Skip to content

feat(ml): IMF v1 runtime — index resolution, sha256 verification, KV decode (WO05) - #9

Open
ronaldtse wants to merge 1 commit into
fix/megaregexp-parallel-99-percentfrom
feat/imf-runtime-ts
Open

feat(ml): IMF v1 runtime — index resolution, sha256 verification, KV decode (WO05)#9
ronaldtse wants to merge 1 commit into
fix/megaregexp-parallel-99-percentfrom
feat/imf-runtime-ts

Conversation

@ronaldtse

Copy link
Copy Markdown
Contributor

Summary

The TypeScript binding of interscript-ml (WO05): an IMF v1 runtime
under src/ml/imf/, implementing the models.yaml contract shared with
the Python reference (interscript-ml) and the Ruby binding (secryst
PR #45). Stacked on #5; retarget when it merges.

What's here

  • tokens — the canonical ByT5 table (byte b → id b+3, trailing
    EOS). Ids are NOT raw TextEncoder bytes.
  • loader — fflate unzip + js-yaml manifest; every .onnx member
    sha256-verified via WebCrypto before any session is created.
  • registry — models.yaml resolution: verified cache hit in
    ~/.cache/interscript/models/<id>/ (node fs, atomic rename), or
    download → whole-file sha256 verify. Env overrides match the other
    runtimes (INTERSCRIPT_ML_INDEX, INTERSCRIPT_ML_CACHE).
  • IMFModel — greedy KV-cache decode when the zip ships
    decoder-kv.onnx (default), plain full-recompute fallback;
    zero-length step-0 pasts sized from session inputMetadata (now
    exposed through the node session wrapper — additive interface change).
  • deps: fflate, js-yaml (+types), onnxruntime-node as devDep.

Cross-runtime acceptance

Released khm-latn-1.0 (interscript/ml-models): 100/100 golden-set
outputs byte-identical across TypeScript, Python, and Ruby

golden/khm-latn-100.jsonl is the shared contract.

Test plan

  • vitest: 8 tests (token table, manifest + tamper rejection,
    registry install/cache-hit/unknown-id, session loading from the
    committed tiny IMF fixture, golden e2e gated on
    INTERSCRIPT_TS_E2E_ZIP)
  • golden e2e against the released zip: 8/8
  • tsc clean (exactOptionalPropertyTypes honored); full suite
    241 tests green
  • CI

Note: package-lock.json carries the base branch's pre-existing
in-flight dependency state alongside the two new deps.

…decode

The TypeScript binding of interscript-ml, implementing the models.yaml
contract shared with the Python (interscript-ml) and Ruby (secryst gem)
runtimes:

- tokens: canonical ByT5 table (byte b -> id b+3, trailing EOS); ids are
  NOT raw TextEncoder bytes
- loader: fflate unzip + js-yaml manifest; every .onnx member
  sha256-verified via WebCrypto before any session is created
- registry: models.yaml resolution — verified cache hit in
  ~/.cache/interscript (node fs, atomic rename) or download ->
  whole-file sha256 verify; INTERSCRIPT_ML_INDEX/CACHE overrides match
  the other runtimes
- IMFModel: greedy KV-cache decode when the zip ships decoder-kv.onnx,
  plain fallback; zero-length step-0 pasts from session inputMetadata
  (exposed through the node session wrapper; byt5-small fallback dims)
- session: optional inputMetadata on InferenceSession (additive)

Verified against the released khm-latn-1.0: 100/100 golden-set outputs
byte-identical to the Python and Ruby runtimes (three runtimes, one
golden set).

package-lock.json includes pre-existing in-flight dependency state on
this branch's base.
@ronaldtse

Copy link
Copy Markdown
Contributor Author

CI note: Build+Test and Coverage fail on this PR, but they fail
identically on the base PR #5 (unused-vars lint and coverage thresholds
in the base's committed state — the in-flight working tree appears to
address them). This branch's own changes lint clean (eslint src/ml/imf test/imf.test.ts → no findings), tsc is clean under
exactOptionalPropertyTypes, and the full suite passes locally: 241
tests, 8/8 IMF including the 100/100 golden e2e against the released
khm-latn-1.0. Happy to rebase once #5 lands.

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.

1 participant