Skip to main content

Module infer

Module infer 

Source
Expand description

ONNX inference for IMF v1 artifacts: the greedy single-row decode loop (the artifact contract per CONFORMANCE.md) over a mockable InferenceEngine trait, plus the ort-backed implementation.

Byte-exactness contract (mirror of pipeline.conformance.ort_single_row_decoder, the reference the fixtures were generated with):

  • encode: ids = UTF-8 byte + 3, one trailing EOS; int64, one row;
  • encoder: one row per call, no padding, no attention mask;
  • decoder: greedy argmax until EOS, 512-step cap, prefix [PAD] then growing;
  • output: max(0, t - 3) per id, lossy UTF-8.

Structs§

OrtEngine
An ort-loaded IMF artifact: encoder + decoder sessions plus the ONNX Runtime environment they share.

Constants§

MAX_DECODE_STEPS
Decode-step step cap. CONFORMANCE.md: “greedy argmax until EOS, 512-step cap”.

Traits§

InferenceEngine
The engine abstraction: one encoder pass + one decoder step at a time. ort sessions implement it; tests drive the loop with a deterministic mock.

Functions§

greedy_generate
The greedy single-row decode loop (model.generate + tokens.decode parity). Empty input (only the trailing EOS) short-circuits to no tokens, exactly like the reference loader.
ids_to_fixture_bytes
The fixture-generation byte rule: max(0, t - 3) per id (no pad/unk skipping — a PAD argmax yields byte 0x00 there), then lossy UTF-8. Used by the conformance harness so frozen vectors are compared byte-exactly under the rule that produced them.
ids_to_fixture_string
translate
translate(text): greedy ids -> text. Conformance fixtures were generated with the max(0, t - 3) byte rule (see ids_to_fixture_bytes); tokens::decode implements the SPEC §4 table (skip pad/unk, mod 256). This function uses the SPEC table.