Repository navigation
feat: add decision heads for Laya models (apiVersion 1) - #112
Merged
Merged
Conversation
Adds getDecisionCapabilities, loadDecisionHead, runDecision and freeDecisionHead on the direct and worker runtimes. Each head gets a private ModernBERT encoder context and runs its graph through ggml_backend_sched with the CPU backend last; the act MLP runs on the host. Inputs, outputs and config text pass through WASMFS files. Heads are freed before the model.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of llamadart#604: Web support for llamadart's
DecisionEngine(Laya decision models).What changed
LlamaWebGpuBridgegains a decision-head API, contractapiVersion1. It runs on the direct and worker runtimes, and every call goes through the exclusive-operation queue:getDecisionCapabilities():{apiVersion, supported, reason?}for the loaded model. A model is supported only if it is a ModernBERT encoder with CLS, SEP and MASK tokens.loadDecisionHead(source, {configJson?, onProgress?}): loads from a URL or from bytes and returns the handle, hidden size, special tokens, MASK text, config text and head device.runDecision(handle, sequences): returns raw markerlogitsandactLogitsper sequence.freeDecisionHead(handle): unknown handles are ignored.src/llama_webgpu_decision.{h,cpp}ports llamadart's native decision head:n_ctx = n_batch = n_ubatch = max_len).ggml_backend_schedwith the CPU backend last. The act MLP runs on the host withstd::erf.n_ctx_train, pooling andn_ubatch;llama_encode, marker range, question type and vocabulary.configJsongo through WASMFS files, becauseccallstrings are copied onto the 1 MiB stack. Staged files are removed withunlink, without ananalyzePathread-back.free_runtime, on every model load and at shutdown. Handles are never reused. Load and run are refused while generation or TTS is active.JS side:
Types in
llama_webgpu_bridge.d.ts; docs indocs/api.md, README, AGENTS and CONTRIBUTING. New checks:scripts/verify_decision_api.py(static contract);scripts/decision_bridge_contract_test.mjs(stub-core JS contract, part ofcheck:js);scripts/decision_browser_smoke.py(real-model parity smoke; local-only, not run in CI).All are wired into CI,
ci_scope.py, the candidate and publish workflows, andverify_ci_reliability.py.The release manifest does not advertise a
decisioncapability. Adding one would make strict readback reject every manifest published before it (a test now pins this), and no qualification gate runs decision heads. Consumers probe withgetDecisionCapabilities().Verification
Toolchain: Homebrew emcc 6.0.10-git. The
emsdk.versionpin (6.0.8) is unchanged; the version check was skipped for local builds only. Builds, all clean with no warnings in bridge sources:Checks:
npm run check:js: passes, and the regeneratedjs/*is byte-identical.verify_decision_api.py,verify_text_to_speech_api.py,verify_state_persistence_api.py,verify_ci_reliability.py,mtmd_compat_contract_test.py,wasm64_runtime_patch_contract_test.pyandrelease_qualification_test.py: all pass.python3 -m unittest discover -s scripts -p '*_test.py': 416 tests OK.Smokes:
decision_browser_smoke.pyagainst the Laya 0.3.5 PyTorch reference (24 rows):laya-head.safetensorslaya-head.safetensorsmodel.safetensors+ configlaya-head.safetensorslaya-head.safetensorsllamadart native Metal gives 0.0118 (F16) and 0.1642 (Q8_0) on the same rows. The head gives the same numbers on WebGPU and CPU, so the differences come from the encoder.
Lifetime:
dispose()with a GPU head loaded is clean.Review:
Out of scope