Skip to content

Comments

Emit initializers as static const arrays and add golden/feature tests#15

Merged
strimo378 merged 1 commit intomainfrom
codex/add-parameter-generation-support-in-c
Jan 10, 2026
Merged

Emit initializers as static const arrays and add golden/feature tests#15
strimo378 merged 1 commit intomainfrom
codex/add-parameter-generation-support-in-c

Conversation

@strimo378
Copy link
Contributor

Motivation

  • Treat ONNX initializers as true constants so model parameters can be embedded in generated C as read-only arrays.
  • Produce deterministic, minimal generated C by emitting weights as static const arrays rather than runtime inputs.
  • Allow the Python runtime to resolve initializer-backed tensors transparently when running compiled models.
  • Add golden and end-to-end feature tests to cover initializer-backed weight emission and behavior.

Description

  • Add Initializer to the IR and parse ONNX initializers in import_onnx, excluding them from the runtime inputs and storing them on the Graph as initializers.
  • Introduce ConstTensor and add a constants field to LoweredModel, with _lowered_constants in compiler to lower Initializers into ConstTensors.
  • Implement CEmitter._emit_constants and CEmitter._format_float to render initializer data as static const float <name>[...] = { ... }; and include the constants section in emitted C before operator functions.
  • Resolve constants at runtime by adding _ResolvedFeeds.fetch and switching Compiler.run/internal run paths to use resolved feeds so initializer arrays are returned automatically.
  • Rework lowered model input collection to use graph inputs, and propagate constants into matmul/binary/unary lowering paths.
  • Add tests and fixtures: new tests/test_endtoend_features.py, added a golden file tests/golden/add_initializer_model.c, updated tests/test_golden.py, and adjusted tests/test_endtoend_ops.py to remove the duplicated initializer end-to-end test.

Testing

  • Ran the full test suite with pytest -n auto -q and all tests passed (20 passed).
  • Compiled and wrote the new golden C fixture via the in-repo Compiler to tests/golden/add_initializer_model.c during the rollout.
  • Executed the new end-to-end feature test which compiles the generated C to an executable and compares outputs against ONNX Runtime.
  • No automated tests failed during validation.

Codex Task

@strimo378 strimo378 merged commit c9829f2 into main Jan 10, 2026
0 of 2 checks passed
@strimo378 strimo378 deleted the codex/add-parameter-generation-support-in-c branch January 10, 2026 15:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant