Views
No views yet
LlamaForCausalLMnpm install @huggingface/transformers1import { pipeline } from "@huggingface/transformers";
2
3const modelId = "Sharjeelbaig/Supra-Router-51M-ONNX";
4const router = await pipeline("text-generation", modelId, {
5 dtype: "int8",
6});
7
8const userPrompt = "Write Python code to find all primes below one million efficiently.";
9const input = `Task: ${userPrompt}\nAnalysis: `;
10
11const output = await router(input, {
12 max_new_tokens: 128,
13 do_sample: false,
14 return_full_text: false,
15});
16
17console.log(output[0].generated_text.trim());Domain: ... | Complexity: 1-5 | Math: True/False | Code: True/False | Route: small model/big model | Justification: ...pip install "optimum-onnx[onnxruntime]" transformers1from transformers import AutoTokenizer, pipeline
2from optimum.onnxruntime import ORTModelForCausalLM
3
4model_id = "Sharjeelbaig/Supra-Router-51M-ONNX"
5tokenizer = AutoTokenizer.from_pretrained(model_id)
6model = ORTModelForCausalLM.from_pretrained(
7 model_id,
8 subfolder="onnx",
9 file_name="model_int8.onnx",
10 use_cache=False,
11)
12
13router = pipeline("text-generation", model=model, tokenizer=tokenizer)
14prompt = "Explain why database deadlocks occur and provide code to prevent them."
15result = router(
16 f"Task: {prompt}\nAnalysis: ",
17 max_new_tokens=128,
18 do_sample=False,
19 return_full_text=False,
20)
21print(result[0]["generated_text"].strip())input_ids: int64[batch, sequence]attention_mask: int64[batch, past_sequence + sequence]position_ids: int64[batch, sequence]past_key_values.{0..11}.{key,value}: cached attention tensorslogits: float32[batch, sequence, 32000] plus present.{0..11}.{key,value} cache tensors. For direct integration, initialize each cache with shape [batch, 4, 0, 64], then pass each returned present tensor back as the corresponding past_key_values input on the next step. Hugging Face pipelines manage this automatically.onnx.checker.1.4e-4 during export validation.small model and big model prompts.