Views
No views yet
fp32 — full precision (onnx/model.onnx)model_type: granite_switch. The Granite Switch web
runtime ships a self-registering shim that teaches transformers.js the
GraniteSwitchForCausalLM architecture, so it loads via the standard
AutoModelForCausalLM.from_pretrained. Granite Switch selects adapters via a
causal, cumulative switch attention; the shim's custom forward threads that
state (past_switch_key0 / past_switch_val0) across decode steps — the generic
loop alone is not sufficient.1// import the shim once (registers granite_switch), then use the re-exported API
2import { AutoModelForCausalLM, loadGraniteSwitch } from "granite-switch-web/src/granite-switch-register.js";
3
4// loadGraniteSwitch wires the external-data sidecar (model.onnx.data) for you:
5const gs = await loadGraniteSwitch("barha/granite-switch-4.0-350m-cti-onnx", { dtype: "fp32" });
6const out = await gs.generate({ inputs, max_new_tokens: 16, do_sample: false });gs_onnx.json carries the runtime metadata (layer/head counts, adapter token
ids) the decode loop needs.granite_switch.onnx.export + granite_switch.onnx.package.
See the project docs (docs/ONNX_BROWSER_PORT.md) for the export pipeline and
parity gates (HF-vs-ONNX max|diff| ~1e-4, argmax 100% on the source model).