Views
No views yet

occ-ai/OCC-RAG-0.6B for
cross-platform inference with ONNX Runtime and in-browser
inference with 🤗 Transformers.js /
ONNX Runtime Web (WebGPU). It runs the full model locally — no server, no data leaves
the device.| dtype | File | Size | Description |
|---|---|---|---|
fp32 | model.onnx (+ model.onnx_data) | ~2.4 GB | Full-precision baseline |
fp16 | model_fp16.onnx | ~1.2 GB | All weights FP16 |
q8 | model_quantized.onnx | ~599 MB | Dynamic INT8 (Transformers.js q8 default) |
| — | model_q8.onnx | ~1.1 GB | INT8 MatMul (asymmetric, MatMulNBits) + FP32 embedding & lm_head |
q4 | model_q4.onnx | ~471 MB | INT4 MatMul + INT4 embedding (GatherBlockQuantized) + INT4 lm_head — smallest |
q4f16 | model_q4f16.onnx | ~560 MB | INT4 MatMul on a pre-fused FP16 graph — recommended for WebGPU |
q4f32 | model_q4f32.onnx | ~899 MB | INT4 MatMul + FP32 embedding & lm_head |
q4f16 is the variant used by the in-browser WebGPU demo. Its RMSNorm is
pre-fused into (Skip)SimplifiedLayerNormalization so ONNX Runtime Web loads it at
the default optimization level. Its INT4 weights are quantized from the FP32 master
(identical INT4 blobs to q4f32; only the scales differ — FP16 vs FP32).q4 quantizes the token embedding and (tied) lm_head as well, giving the smallest
footprint at a small quality cost.model_q8.onnx (weight-only INT8 via MatMulNBits) and model_q4f32.onnx are
addressable by dtype only in newer Transformers.js builds; the dynamic-INT8
model_quantized.onnx is what the bundled dtype: "q8" maps to.OCC-RAG-0.6B-ONNX/
├── config.json
├── generation_config.json
├── tokenizer.json
├── tokenizer_config.json # chat_template inlined (Transformers.js reads it here)
├── special_tokens_map.json
├── added_tokens.json
├── vocab.json
├── merges.txt
├── quantize_config.json
└── onnx/
├── model.onnx # fp32 (+ model.onnx_data)
├── model_fp16.onnx
├── model_q4.onnx
├── model_q4f16.onnx # ← WebGPU
├── model_q4f32.onnx
├── model_q8.onnx
└── model_quantized.onnx # dynamic int8 (dtype "q8")documents= kwarg and emits the structural tokens automatically — pass the user message
as plain text and the sources as a list of {"text": ...} dicts. The question is wrapped
in <|query_start|> … <|query_end|> and each source in
<|source_start|><|source_id|>N … <|source_end|>.ANSWERABLE / UNANSWERABLE) → answer. Parse the
final answer from <|answer_start|> … <|answer_end|>. Keep skip_special_tokens=False if
you need to read the structural tokens out of the raw output.We recommend greedy decoding (do_sample=False), the training/evaluation default baked intogeneration_config.json.
1import { pipeline, TextStreamer } from "@huggingface/transformers";
2
3const generator = await pipeline("text-generation", "occ-ai/OCC-RAG-0.6B-ONNX", {
4 dtype: "q4f16", // WebGPU-friendly; or "q8" / "q4" / "fp16"
5 device: "webgpu",
6});
7
8const question = "Which country is the inventor of the telephone, Alexander Graham Bell, buried in?";
9const documents = [
10 { text: "Alexander Graham Bell was a Scottish-born inventor best known for patenting the first practical telephone." },
11 { text: "Bell died on August 2, 1922, at his estate Beinn Bhreagh, near Baddeck, Nova Scotia, and was buried there." },
12 { text: "Nova Scotia is a province on the east coast of Canada." },
13];
14
15// The chat template injects the <|query_*|> / <|source_*|> structural tokens.
16const text = generator.tokenizer.apply_chat_template(
17 [{ role: "user", content: question }],
18 { documents, add_generation_prompt: true, tokenize: false },
19);
20
21const output = await generator(text, {
22 max_new_tokens: 512,
23 do_sample: false,
24 streamer: new TextStreamer(generator.tokenizer, { skip_prompt: true, skip_special_tokens: false }),
25});
26console.log(output[0].generated_text);huggingface/transformers.js-examples → occ-rag-webgpu.pip install onnxruntime transformers numpy huggingface_hub1import numpy as np, onnxruntime as ort
2from huggingface_hub import hf_hub_download
3from transformers import AutoTokenizer
4
5model_id = "occ-ai/OCC-RAG-0.6B-ONNX"
6onnx_path = hf_hub_download(model_id, "onnx/model_q4.onnx")
7tok = AutoTokenizer.from_pretrained(model_id)
8
9session = ort.InferenceSession(onnx_path, providers=["CPUExecutionProvider"])
10
11question = "Which country is the inventor of the telephone, Alexander Graham Bell, buried in?"
12documents = [
13 {"text": "Alexander Graham Bell was a Scottish-born inventor best known for patenting the first practical telephone."},
14 {"text": "Bell died on August 2, 1922, at his estate Beinn Bhreagh, near Baddeck, Nova Scotia, and was buried there."},
15 {"text": "Nova Scotia is a province on the east coast of Canada."},
16]
17prompt = tok.apply_chat_template(
18 [{"role": "user", "content": question}],
19 documents=documents, tokenize=False, add_generation_prompt=True,
20)
21input_ids = np.array([tok.encode(prompt, add_special_tokens=False)], dtype=np.int64)
22
23cfg = session.get_modelmeta() # see config.json for num_hidden_layers / num_key_value_heads / head_dim
24# Greedy decode with KV-cache: feed input_ids + attention_mask + position_ids and the
25# past_key_values.{i}.{key,value} inputs (empty on the first step), then loop feeding the
26# present.* outputs back in. Stop on eos ids 151643 / 151645 / 151683.The INT4/INT8 ONNX graphs are weight-only quantized (MatMulNBits / GatherBlockQuantized) and carry a KV-cache interface.model_q4f16.onnxexpects FP16 KV-cache I/O; the others use FP32. Seeconfig.json(num_hidden_layers,num_key_value_heads,head_dim) for the cache tensor shapes[batch, kv_heads, seq, head_dim].
q4, q4f16) trade a small amount of quality for
size/speed; prefer fp16 / q8 when accuracy matters most.1@misc{savkin2026occragoptimalcognitivecore,
2 title = {OCC-RAG: Optimal Cognitive Core for Faithful Question Answering},
3 author = {Maksim Savkin and Mikhail Goncharov and Alexander Gambashidze and Alla Chepurova and Dmitrii Tarasov and Nikita Andriianov and Daria Pugacheva and Vasily Konovalov and Andrey Galichin and Ivan Oseledets},
4 year = {2026},
5 eprint = {2606.00683},
6 archivePrefix = {arXiv},
7 primaryClass = {cs.CL},
8 url = {https://arxiv.org/abs/2606.00683}
9}