Skip to content

Add @stdlib/onnx module for local ONNX Runtime inference#442

Open
nbeerbower wants to merge 1 commit into
mainfrom
claude/add-onnx-runtime-z0jlc
Open

Add @stdlib/onnx module for local ONNX Runtime inference#442
nbeerbower wants to merge 1 commit into
mainfrom
claude/add-onnx-runtime-z0jlc

Conversation

@nbeerbower

Copy link
Copy Markdown
Collaborator

Adds a new standard library module that enables running ONNX models
locally via libonnxruntime FFI, following the same pattern as the
sqlite and vector modules.

Architecture:

  • stdlib/c/onnx_wrapper.c: Thin C wrapper that flattens OrtApi's
    struct-of-function-pointers into flat exported C functions callable
    through Hemlock's FFI system
  • stdlib/onnx.hml: Pure Hemlock module providing high-level API for
    session management, tensor creation/inspection, and inference
  • stdlib/docs/onnx.md: Full documentation with examples

API surface:

  • Session lifecycle: create_session(), free_session()
  • Model inspection: input_names(), output_names(), input_shape(),
    output_shape(), input_type(), output_type(), describe()
  • Tensor creation: create_tensor_f32/f64/i32/i64(), free_tensor()
  • Tensor inspection: tensor_shape(), tensor_data_f32/f64/i32/i64(),
    tensor_element_count(), tensor_type()
  • Inference: run() with named (object) or positional (array) inputs
  • Utilities: version(), api_version(), dtype_name()

Also includes:

  • Makefile updates for conditional ONNX Runtime detection and wrapper
    compilation on Linux and macOS
  • Test runner skip logic for when libonnxruntime is not installed
  • Tests for constants, tensor operations, error handling, and inference

https://claude.ai/code/session_01PAARTAYAKLvdGGuiNaW9xF

Adds a new standard library module that enables running ONNX models
locally via libonnxruntime FFI, following the same pattern as the
sqlite and vector modules.

Architecture:
- stdlib/c/onnx_wrapper.c: Thin C wrapper that flattens OrtApi's
  struct-of-function-pointers into flat exported C functions callable
  through Hemlock's FFI system
- stdlib/onnx.hml: Pure Hemlock module providing high-level API for
  session management, tensor creation/inspection, and inference
- stdlib/docs/onnx.md: Full documentation with examples

API surface:
- Session lifecycle: create_session(), free_session()
- Model inspection: input_names(), output_names(), input_shape(),
  output_shape(), input_type(), output_type(), describe()
- Tensor creation: create_tensor_f32/f64/i32/i64(), free_tensor()
- Tensor inspection: tensor_shape(), tensor_data_f32/f64/i32/i64(),
  tensor_element_count(), tensor_type()
- Inference: run() with named (object) or positional (array) inputs
- Utilities: version(), api_version(), dtype_name()

Also includes:
- Makefile updates for conditional ONNX Runtime detection and wrapper
  compilation on Linux and macOS
- Test runner skip logic for when libonnxruntime is not installed
- Tests for constants, tensor operations, error handling, and inference

https://claude.ai/code/session_01PAARTAYAKLvdGGuiNaW9xF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants