Text Generation
Transformers
Safetensors
English
llama
speculative-decoding
draft-model
assistant-model
qwen3.5
conversational
text-generation-inference
Instructions to use samratduttaofficial/understudy-lm with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use samratduttaofficial/understudy-lm with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="samratduttaofficial/understudy-lm") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("samratduttaofficial/understudy-lm") model = AutoModelForCausalLM.from_pretrained("samratduttaofficial/understudy-lm", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=256) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use samratduttaofficial/understudy-lm with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "samratduttaofficial/understudy-lm" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "samratduttaofficial/understudy-lm", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/samratduttaofficial/understudy-lm
- SGLang
How to use samratduttaofficial/understudy-lm with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "samratduttaofficial/understudy-lm" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "samratduttaofficial/understudy-lm", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "samratduttaofficial/understudy-lm" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "samratduttaofficial/understudy-lm", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use samratduttaofficial/understudy-lm with Docker Model Runner:
docker model run hf.co/samratduttaofficial/understudy-lm
Release understudy-lm v1.0 weights
Browse files- .gitattributes +1 -0
- README.md +138 -0
- assets/acceptance.png +0 -0
- assets/round_tokens.png +0 -0
- assets/speedup.png +0 -0
- assets/val_loss.png +0 -0
- chat_template.jinja +154 -0
- config.json +35 -0
- eval_results.json +21 -0
- generation_config.json +12 -0
- lookahead_heads.safetensors +3 -0
- model.safetensors +3 -0
- tokenizer.json +3 -0
- tokenizer_config.json +32 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language:
|
| 3 |
+
- en
|
| 4 |
+
library_name: transformers
|
| 5 |
+
pipeline_tag: text-generation
|
| 6 |
+
tags:
|
| 7 |
+
- speculative-decoding
|
| 8 |
+
- draft-model
|
| 9 |
+
- assistant-model
|
| 10 |
+
- qwen3.5
|
| 11 |
+
- llama
|
| 12 |
+
datasets:
|
| 13 |
+
- HuggingFaceTB/smoltalk
|
| 14 |
+
- allenai/tulu-3-sft-mixture
|
| 15 |
+
- HuggingFaceFW/fineweb-edu
|
| 16 |
+
---
|
| 17 |
+
|
| 18 |
+
# understudy-lm
|
| 19 |
+
|
| 20 |
+
A 109M-parameter draft model for speculative decoding with
|
| 21 |
+
[Qwen/Qwen3.5-4B](https://huggingface.co/Qwen/Qwen3.5-4B). It was trained from
|
| 22 |
+
scratch, only on text the 4B wrote, with no access to the 4B's logits or
|
| 23 |
+
hidden states. It uses the Qwen3.5 tokenizer, so its guesses can be checked
|
| 24 |
+
by the 4B directly.
|
| 25 |
+
|
| 26 |
+
The checkpoint is a standard `LlamaForCausalLM` and loads with plain
|
| 27 |
+
`transformers`. Three extra lookahead heads, stored separately in
|
| 28 |
+
`lookahead_heads.safetensors`, let one forward pass guess four tokens.
|
| 29 |
+
|
| 30 |
+
Code and training pipeline: [github.com/SamratDuttaOfficial/understudy-lm](https://github.com/SamratDuttaOfficial/understudy-lm)
|
| 31 |
+
|
| 32 |
+
## Results
|
| 33 |
+
|
| 34 |
+
Greedy speculative decoding replayed over 200 held-out Qwen3.5-4B answers
|
| 35 |
+
(90K rounds, four guesses per round, answer tokens only):
|
| 36 |
+
|
| 37 |
+
| | |
|
| 38 |
+
|---|---|
|
| 39 |
+
| Tokens per 4B pass | **1.58** |
|
| 40 |
+
| Accepted guesses per round | 0.58 |
|
| 41 |
+
| Draft round (4 guesses, CUDA graph) | 1.77 ms |
|
| 42 |
+
| 4B decode step (Ollama, 4-bit) | 16.6 ms |
|
| 43 |
+
| Projected speedup | **1.43x** |
|
| 44 |
+
|
| 45 |
+
The speedup is projected as `tokens_per_round / (1 + draft_time / target_time)`,
|
| 46 |
+
not measured end to end. Details are in `eval_results.json`.
|
| 47 |
+
|
| 48 |
+
| Pretraining loss | Acceptance per guess |
|
| 49 |
+
|---|---|
|
| 50 |
+
|  |  |
|
| 51 |
+
| **Tokens produced per round** | **Projected speedup** |
|
| 52 |
+
|  |  |
|
| 53 |
+
|
| 54 |
+
## Usage
|
| 55 |
+
|
| 56 |
+
### As an assistant model in transformers
|
| 57 |
+
|
| 58 |
+
The draft's vocabulary size matches the 4B's, so it works with assisted
|
| 59 |
+
generation as is. In this mode transformers asks the draft for one token at a
|
| 60 |
+
time and does not use the lookahead heads.
|
| 61 |
+
|
| 62 |
+
```python
|
| 63 |
+
import torch
|
| 64 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 65 |
+
|
| 66 |
+
tok = AutoTokenizer.from_pretrained("Qwen/Qwen3.5-4B")
|
| 67 |
+
target = AutoModelForCausalLM.from_pretrained("Qwen/Qwen3.5-4B", dtype=torch.bfloat16, device_map="auto")
|
| 68 |
+
draft = AutoModelForCausalLM.from_pretrained("samratduttaofficial/understudy-lm", dtype=torch.bfloat16).to(target.device)
|
| 69 |
+
|
| 70 |
+
messages = [{"role": "user", "content": "Explain what a hash table is."}]
|
| 71 |
+
inputs = tok.apply_chat_template(messages, add_generation_prompt=True, enable_thinking=False,
|
| 72 |
+
return_tensors="pt", return_dict=True).to(target.device)
|
| 73 |
+
out = target.generate(**inputs, assistant_model=draft, max_new_tokens=256, do_sample=False)
|
| 74 |
+
print(tok.decode(out[0, inputs["input_ids"].shape[1]:], skip_special_tokens=True))
|
| 75 |
+
```
|
| 76 |
+
|
| 77 |
+
### Four guesses from one pass, with the lookahead heads
|
| 78 |
+
|
| 79 |
+
Head `j` maps the final hidden state `h` to `h + silu(W_j h)`, and the shared
|
| 80 |
+
output layer turns it into a guess for token `t+1+j`.
|
| 81 |
+
|
| 82 |
+
```python
|
| 83 |
+
import torch
|
| 84 |
+
import torch.nn.functional as F
|
| 85 |
+
from huggingface_hub import hf_hub_download
|
| 86 |
+
from safetensors.torch import load_file
|
| 87 |
+
from transformers import AutoModelForCausalLM
|
| 88 |
+
|
| 89 |
+
repo = "samratduttaofficial/understudy-lm"
|
| 90 |
+
draft = AutoModelForCausalLM.from_pretrained(repo).eval()
|
| 91 |
+
heads = load_file(hf_hub_download(repo, "lookahead_heads.safetensors"))
|
| 92 |
+
|
| 93 |
+
@torch.no_grad()
|
| 94 |
+
def guess4(input_ids):
|
| 95 |
+
h = draft.model(input_ids).last_hidden_state[:, -1]
|
| 96 |
+
hs = [h] + [h + F.silu(h @ heads[f"heads.{j}.weight"].T) for j in range(3)]
|
| 97 |
+
return draft.lm_head(torch.stack(hs, 1)).argmax(-1) # tokens t+1 .. t+4
|
| 98 |
+
```
|
| 99 |
+
|
| 100 |
+
On its own the draft writes fluent but often wrong text. It is meant to be
|
| 101 |
+
checked by the 4B, not used by itself.
|
| 102 |
+
|
| 103 |
+
## Model
|
| 104 |
+
|
| 105 |
+
| | |
|
| 106 |
+
|---|---|
|
| 107 |
+
| Architecture | Llama-style decoder: RMSNorm, RoPE, grouped-query attention, SwiGLU |
|
| 108 |
+
| Layers / width | 8 / 384 |
|
| 109 |
+
| Attention heads | 6 query, 2 key-value (head size 64) |
|
| 110 |
+
| Feed-forward | 1,088 |
|
| 111 |
+
| Context | 1,024 tokens |
|
| 112 |
+
| Vocabulary | Qwen3.5 tokenizer, 248,320 entries (tied input and output embedding) |
|
| 113 |
+
| Parameters | 95.4M embedding + 13.2M transformer + 0.44M lookahead heads |
|
| 114 |
+
|
| 115 |
+
## Training
|
| 116 |
+
|
| 117 |
+
1. **Data from the target.** Qwen3.5-4B answered 40,000 prompts drawn from
|
| 118 |
+
SmolTalk, the Tulu 3 SFT mixture and FineWeb-Edu (temperature 0.7, top-p
|
| 119 |
+
0.95, up to 512 tokens, thinking off): 13.4M answer tokens.
|
| 120 |
+
2. **Corpus.** 305M tokens of complete SmolTalk and Tulu 3 conversations,
|
| 121 |
+
excluding those whose prompt was used in step 1.
|
| 122 |
+
3. **Pretraining.** 12,000 steps of 65,536 tokens, 75% corpus and 25% target
|
| 123 |
+
answers. AdamW, peak learning rate 3e-4, cosine decay. Validation loss on
|
| 124 |
+
the target's held-out answers fell to 3.16. An earlier run trained on the
|
| 125 |
+
target's answers alone overfit after about 13 passes (best 3.68).
|
| 126 |
+
4. **Post-training.** Three lookahead heads added, 3,000 steps at 1e-4 on the
|
| 127 |
+
target's answers only (prompt tokens masked), loss
|
| 128 |
+
`L1 + 0.4 * (L2 + L3 + L4)`.
|
| 129 |
+
|
| 130 |
+
## Limitations
|
| 131 |
+
|
| 132 |
+
- The speedup is projected from replayed acceptance and measured draft and
|
| 133 |
+
target timings. It has not been measured end to end.
|
| 134 |
+
- It assumes checking five positions costs the 4B about as much as one decode
|
| 135 |
+
step. If it costs 10% more, the projection drops to about 1.31x.
|
| 136 |
+
- Results cover greedy decoding. With sampling, acceptance is usually lower.
|
| 137 |
+
- Acceptance was measured against sampled (temperature 0.7) answers; against
|
| 138 |
+
the 4B's greedy answers it is slightly higher.
|
assets/acceptance.png
ADDED
|
assets/round_tokens.png
ADDED
|
assets/speedup.png
ADDED
|
assets/val_loss.png
ADDED
|
chat_template.jinja
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{%- set image_count = namespace(value=0) %}
|
| 2 |
+
{%- set video_count = namespace(value=0) %}
|
| 3 |
+
{%- macro render_content(content, do_vision_count, is_system_content=false) %}
|
| 4 |
+
{%- if content is string %}
|
| 5 |
+
{{- content }}
|
| 6 |
+
{%- elif content is iterable and content is not mapping %}
|
| 7 |
+
{%- for item in content %}
|
| 8 |
+
{%- if 'image' in item or 'image_url' in item or item.type == 'image' %}
|
| 9 |
+
{%- if is_system_content %}
|
| 10 |
+
{{- raise_exception('System message cannot contain images.') }}
|
| 11 |
+
{%- endif %}
|
| 12 |
+
{%- if do_vision_count %}
|
| 13 |
+
{%- set image_count.value = image_count.value + 1 %}
|
| 14 |
+
{%- endif %}
|
| 15 |
+
{%- if add_vision_id %}
|
| 16 |
+
{{- 'Picture ' ~ image_count.value ~ ': ' }}
|
| 17 |
+
{%- endif %}
|
| 18 |
+
{{- '<|vision_start|><|image_pad|><|vision_end|>' }}
|
| 19 |
+
{%- elif 'video' in item or item.type == 'video' %}
|
| 20 |
+
{%- if is_system_content %}
|
| 21 |
+
{{- raise_exception('System message cannot contain videos.') }}
|
| 22 |
+
{%- endif %}
|
| 23 |
+
{%- if do_vision_count %}
|
| 24 |
+
{%- set video_count.value = video_count.value + 1 %}
|
| 25 |
+
{%- endif %}
|
| 26 |
+
{%- if add_vision_id %}
|
| 27 |
+
{{- 'Video ' ~ video_count.value ~ ': ' }}
|
| 28 |
+
{%- endif %}
|
| 29 |
+
{{- '<|vision_start|><|video_pad|><|vision_end|>' }}
|
| 30 |
+
{%- elif 'text' in item %}
|
| 31 |
+
{{- item.text }}
|
| 32 |
+
{%- else %}
|
| 33 |
+
{{- raise_exception('Unexpected item type in content.') }}
|
| 34 |
+
{%- endif %}
|
| 35 |
+
{%- endfor %}
|
| 36 |
+
{%- elif content is none or content is undefined %}
|
| 37 |
+
{{- '' }}
|
| 38 |
+
{%- else %}
|
| 39 |
+
{{- raise_exception('Unexpected content type.') }}
|
| 40 |
+
{%- endif %}
|
| 41 |
+
{%- endmacro %}
|
| 42 |
+
{%- if not messages %}
|
| 43 |
+
{{- raise_exception('No messages provided.') }}
|
| 44 |
+
{%- endif %}
|
| 45 |
+
{%- if tools and tools is iterable and tools is not mapping %}
|
| 46 |
+
{{- '<|im_start|>system\n' }}
|
| 47 |
+
{{- "# Tools\n\nYou have access to the following functions:\n\n<tools>" }}
|
| 48 |
+
{%- for tool in tools %}
|
| 49 |
+
{{- "\n" }}
|
| 50 |
+
{{- tool | tojson }}
|
| 51 |
+
{%- endfor %}
|
| 52 |
+
{{- "\n</tools>" }}
|
| 53 |
+
{{- '\n\nIf you choose to call a function ONLY reply in the following format with NO suffix:\n\n<tool_call>\n<function=example_function_name>\n<parameter=example_parameter_1>\nvalue_1\n</parameter>\n<parameter=example_parameter_2>\nThis is the value for the second parameter\nthat can span\nmultiple lines\n</parameter>\n</function>\n</tool_call>\n\n<IMPORTANT>\nReminder:\n- Function calls MUST follow the specified format: an inner <function=...></function> block must be nested within <tool_call></tool_call> XML tags\n- Required parameters MUST be specified\n- You may provide optional reasoning for your function call in natural language BEFORE the function call, but NOT after\n- If there is no function call available, answer the question like normal with your current knowledge and do not tell the user about function calls\n</IMPORTANT>' }}
|
| 54 |
+
{%- if messages[0].role == 'system' %}
|
| 55 |
+
{%- set content = render_content(messages[0].content, false, true)|trim %}
|
| 56 |
+
{%- if content %}
|
| 57 |
+
{{- '\n\n' + content }}
|
| 58 |
+
{%- endif %}
|
| 59 |
+
{%- endif %}
|
| 60 |
+
{{- '<|im_end|>\n' }}
|
| 61 |
+
{%- else %}
|
| 62 |
+
{%- if messages[0].role == 'system' %}
|
| 63 |
+
{%- set content = render_content(messages[0].content, false, true)|trim %}
|
| 64 |
+
{{- '<|im_start|>system\n' + content + '<|im_end|>\n' }}
|
| 65 |
+
{%- endif %}
|
| 66 |
+
{%- endif %}
|
| 67 |
+
{%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}
|
| 68 |
+
{%- for message in messages[::-1] %}
|
| 69 |
+
{%- set index = (messages|length - 1) - loop.index0 %}
|
| 70 |
+
{%- if ns.multi_step_tool and message.role == "user" %}
|
| 71 |
+
{%- set content = render_content(message.content, false)|trim %}
|
| 72 |
+
{%- if not(content.startswith('<tool_response>') and content.endswith('</tool_response>')) %}
|
| 73 |
+
{%- set ns.multi_step_tool = false %}
|
| 74 |
+
{%- set ns.last_query_index = index %}
|
| 75 |
+
{%- endif %}
|
| 76 |
+
{%- endif %}
|
| 77 |
+
{%- endfor %}
|
| 78 |
+
{%- if ns.multi_step_tool %}
|
| 79 |
+
{{- raise_exception('No user query found in messages.') }}
|
| 80 |
+
{%- endif %}
|
| 81 |
+
{%- for message in messages %}
|
| 82 |
+
{%- set content = render_content(message.content, true)|trim %}
|
| 83 |
+
{%- if message.role == "system" %}
|
| 84 |
+
{%- if not loop.first %}
|
| 85 |
+
{{- raise_exception('System message must be at the beginning.') }}
|
| 86 |
+
{%- endif %}
|
| 87 |
+
{%- elif message.role == "user" %}
|
| 88 |
+
{{- '<|im_start|>' + message.role + '\n' + content + '<|im_end|>' + '\n' }}
|
| 89 |
+
{%- elif message.role == "assistant" %}
|
| 90 |
+
{%- set reasoning_content = '' %}
|
| 91 |
+
{%- if message.reasoning_content is string %}
|
| 92 |
+
{%- set reasoning_content = message.reasoning_content %}
|
| 93 |
+
{%- else %}
|
| 94 |
+
{%- if '</think>' in content %}
|
| 95 |
+
{%- set reasoning_content = content.split('</think>')[0].rstrip('\n').split('<think>')[-1].lstrip('\n') %}
|
| 96 |
+
{%- set content = content.split('</think>')[-1].lstrip('\n') %}
|
| 97 |
+
{%- endif %}
|
| 98 |
+
{%- endif %}
|
| 99 |
+
{%- set reasoning_content = reasoning_content|trim %}
|
| 100 |
+
{%- if loop.index0 > ns.last_query_index %}
|
| 101 |
+
{{- '<|im_start|>' + message.role + '\n<think>\n' + reasoning_content + '\n</think>\n\n' + content }}
|
| 102 |
+
{%- else %}
|
| 103 |
+
{{- '<|im_start|>' + message.role + '\n' + content }}
|
| 104 |
+
{%- endif %}
|
| 105 |
+
{%- if message.tool_calls and message.tool_calls is iterable and message.tool_calls is not mapping %}
|
| 106 |
+
{%- for tool_call in message.tool_calls %}
|
| 107 |
+
{%- if tool_call.function is defined %}
|
| 108 |
+
{%- set tool_call = tool_call.function %}
|
| 109 |
+
{%- endif %}
|
| 110 |
+
{%- if loop.first %}
|
| 111 |
+
{%- if content|trim %}
|
| 112 |
+
{{- '\n\n<tool_call>\n<function=' + tool_call.name + '>\n' }}
|
| 113 |
+
{%- else %}
|
| 114 |
+
{{- '<tool_call>\n<function=' + tool_call.name + '>\n' }}
|
| 115 |
+
{%- endif %}
|
| 116 |
+
{%- else %}
|
| 117 |
+
{{- '\n<tool_call>\n<function=' + tool_call.name + '>\n' }}
|
| 118 |
+
{%- endif %}
|
| 119 |
+
{%- if tool_call.arguments is defined %}
|
| 120 |
+
{%- for args_name, args_value in tool_call.arguments|items %}
|
| 121 |
+
{{- '<parameter=' + args_name + '>\n' }}
|
| 122 |
+
{%- set args_value = args_value | tojson | safe if args_value is mapping or (args_value is sequence and args_value is not string) else args_value | string %}
|
| 123 |
+
{{- args_value }}
|
| 124 |
+
{{- '\n</parameter>\n' }}
|
| 125 |
+
{%- endfor %}
|
| 126 |
+
{%- endif %}
|
| 127 |
+
{{- '</function>\n</tool_call>' }}
|
| 128 |
+
{%- endfor %}
|
| 129 |
+
{%- endif %}
|
| 130 |
+
{{- '<|im_end|>\n' }}
|
| 131 |
+
{%- elif message.role == "tool" %}
|
| 132 |
+
{%- if loop.previtem and loop.previtem.role != "tool" %}
|
| 133 |
+
{{- '<|im_start|>user' }}
|
| 134 |
+
{%- endif %}
|
| 135 |
+
{{- '\n<tool_response>\n' }}
|
| 136 |
+
{{- content }}
|
| 137 |
+
{{- '\n</tool_response>' }}
|
| 138 |
+
{%- if not loop.last and loop.nextitem.role != "tool" %}
|
| 139 |
+
{{- '<|im_end|>\n' }}
|
| 140 |
+
{%- elif loop.last %}
|
| 141 |
+
{{- '<|im_end|>\n' }}
|
| 142 |
+
{%- endif %}
|
| 143 |
+
{%- else %}
|
| 144 |
+
{{- raise_exception('Unexpected message role.') }}
|
| 145 |
+
{%- endif %}
|
| 146 |
+
{%- endfor %}
|
| 147 |
+
{%- if add_generation_prompt %}
|
| 148 |
+
{{- '<|im_start|>assistant\n' }}
|
| 149 |
+
{%- if enable_thinking is defined and enable_thinking is false %}
|
| 150 |
+
{{- '<think>\n\n</think>\n\n' }}
|
| 151 |
+
{%- else %}
|
| 152 |
+
{{- '<think>\n' }}
|
| 153 |
+
{%- endif %}
|
| 154 |
+
{%- endif %}
|
config.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"LlamaForCausalLM"
|
| 4 |
+
],
|
| 5 |
+
"attention_bias": false,
|
| 6 |
+
"attention_dropout": 0.0,
|
| 7 |
+
"bos_token_id": null,
|
| 8 |
+
"dtype": "float32",
|
| 9 |
+
"eos_token_id": [
|
| 10 |
+
248046,
|
| 11 |
+
248044
|
| 12 |
+
],
|
| 13 |
+
"head_dim": 64,
|
| 14 |
+
"hidden_act": "silu",
|
| 15 |
+
"hidden_size": 384,
|
| 16 |
+
"initializer_range": 0.02,
|
| 17 |
+
"intermediate_size": 1088,
|
| 18 |
+
"max_position_embeddings": 1024,
|
| 19 |
+
"mlp_bias": false,
|
| 20 |
+
"model_type": "llama",
|
| 21 |
+
"num_attention_heads": 6,
|
| 22 |
+
"num_hidden_layers": 8,
|
| 23 |
+
"num_key_value_heads": 2,
|
| 24 |
+
"pad_token_id": 248044,
|
| 25 |
+
"pretraining_tp": 1,
|
| 26 |
+
"rms_norm_eps": 1e-06,
|
| 27 |
+
"rope_parameters": {
|
| 28 |
+
"rope_theta": 10000.0,
|
| 29 |
+
"rope_type": "default"
|
| 30 |
+
},
|
| 31 |
+
"tie_word_embeddings": true,
|
| 32 |
+
"transformers_version": "5.16.1",
|
| 33 |
+
"use_cache": true,
|
| 34 |
+
"vocab_size": 248320
|
| 35 |
+
}
|
eval_results.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"target": "Qwen/Qwen3.5-4B (served by Ollama, 4-bit)",
|
| 3 |
+
"method": "greedy speculative decoding replayed over held-out target answers; answer tokens only",
|
| 4 |
+
"sequences": 200,
|
| 5 |
+
"rounds": 90141,
|
| 6 |
+
"proposals_per_round": 4,
|
| 7 |
+
"p_accept_given_prefix": [
|
| 8 |
+
0.3862,
|
| 9 |
+
0.3283,
|
| 10 |
+
0.3917,
|
| 11 |
+
0.4582
|
| 12 |
+
],
|
| 13 |
+
"accepted_guesses_per_round": 0.5838,
|
| 14 |
+
"tokens_per_round": 1.5807,
|
| 15 |
+
"draft_round_ms_cuda_graph": 1.772,
|
| 16 |
+
"draft_round_ms_eager": 9.352,
|
| 17 |
+
"target_step_ms": 16.602,
|
| 18 |
+
"projected_speedup": 1.4283,
|
| 19 |
+
"run1_tokens_per_round": 1.5222,
|
| 20 |
+
"note": "speedup = tokens_per_round / (1 + draft_round / target_step); projected, not measured end to end"
|
| 21 |
+
}
|
generation_config.json
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_from_model_config": true,
|
| 3 |
+
"eos_token_id": [
|
| 4 |
+
248046,
|
| 5 |
+
248044
|
| 6 |
+
],
|
| 7 |
+
"output_attentions": false,
|
| 8 |
+
"output_hidden_states": false,
|
| 9 |
+
"pad_token_id": 248044,
|
| 10 |
+
"transformers_version": "5.16.1",
|
| 11 |
+
"use_cache": true
|
| 12 |
+
}
|
lookahead_heads.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b437d2d4086d39f2e5f9ef07a35bb264d0618f1e9fbf1ee99c8b1b76a85efb55
|
| 3 |
+
size 1769728
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7dc887211a536e8ab04937212b60f7a2e240e773611ec3c2a29d396096b961ac
|
| 3 |
+
size 434144792
|
tokenizer.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:06b9509352d2af50381ab2247e083b80d32d5c0aba91c272ca9ff729b6a0e523
|
| 3 |
+
size 19989325
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"add_prefix_space": false,
|
| 3 |
+
"audio_bos_token": "<|audio_start|>",
|
| 4 |
+
"audio_eos_token": "<|audio_end|>",
|
| 5 |
+
"audio_token": "<|audio_pad|>",
|
| 6 |
+
"backend": "tokenizers",
|
| 7 |
+
"bos_token": null,
|
| 8 |
+
"clean_up_tokenization_spaces": false,
|
| 9 |
+
"eos_token": "<|im_end|>",
|
| 10 |
+
"errors": "replace",
|
| 11 |
+
"image_token": "<|image_pad|>",
|
| 12 |
+
"is_local": false,
|
| 13 |
+
"local_files_only": false,
|
| 14 |
+
"model_max_length": 262144,
|
| 15 |
+
"model_specific_special_tokens": {
|
| 16 |
+
"audio_bos_token": "<|audio_start|>",
|
| 17 |
+
"audio_eos_token": "<|audio_end|>",
|
| 18 |
+
"audio_token": "<|audio_pad|>",
|
| 19 |
+
"image_token": "<|image_pad|>",
|
| 20 |
+
"video_token": "<|video_pad|>",
|
| 21 |
+
"vision_bos_token": "<|vision_start|>",
|
| 22 |
+
"vision_eos_token": "<|vision_end|>"
|
| 23 |
+
},
|
| 24 |
+
"pad_token": "<|endoftext|>",
|
| 25 |
+
"pretokenize_regex": "(?i:'s|'t|'re|'ve|'m|'ll|'d)|[^\\r\\n\\p{L}\\p{N}]?[\\p{L}\\p{M}]+|\\p{N}| ?[^\\s\\p{L}\\p{M}\\p{N}]+[\\r\\n]*|\\s*[\\r\\n]+|\\s+(?!\\S)|\\s+",
|
| 26 |
+
"split_special_tokens": false,
|
| 27 |
+
"tokenizer_class": "Qwen2Tokenizer",
|
| 28 |
+
"unk_token": null,
|
| 29 |
+
"video_token": "<|video_pad|>",
|
| 30 |
+
"vision_bos_token": "<|vision_start|>",
|
| 31 |
+
"vision_eos_token": "<|vision_end|>"
|
| 32 |
+
}
|