Views
No views yet
trust_remote_code=True.1from transformers import AutoTokenizer, AutoModelForCausalLM
2
3tok = AutoTokenizer.from_pretrained(".", trust_remote_code=True)
4model = AutoModelForCausalLM.from_pretrained(".", trust_remote_code=True)
5
6prompt = "<|user|>Explain photosynthesis in simple terms.<|end|><|assistant|>"
7inputs = tok(prompt, return_tensors="pt")
8out = model.generate(
9 **inputs,
10 max_new_tokens=300,
11 eos_token_id=tok.convert_tokens_to_ids("<|end|>"),
12 pad_token_id=tok.convert_tokens_to_ids("<|pad|>"),
13 use_cache=False,
14)
15print(tok.decode(out[0], skip_special_tokens=False))up_proj and down_proj; there is no
SwiGLU gate projection.12 * 64 = 768.1e-5.input_ids with shape (batch, sequence), the model
performs:h = embed_tokens[input_ids]1h = h + SelfAttention(RMSNorm(h))
2h = h + MLP(RMSNorm(h))h = RMSNorm(h)logits = h @ embed_tokens.weight.Tx:1rms = rsqrt(mean(x^2) + 1e-5)
2RMSNorm(x) = weight * x * rms1q = q_proj(x)
2k = k_proj(x)
3v = v_proj(x)
4q, k, v -> reshape to (batch, heads, sequence, head_dim)
5q, k = RoPE(q, k)
6attention = softmax((q @ k.T) / sqrt(head_dim) + causal_mask)
7out = attention @ v
8out = o_proj(out)inv_freq[i] = 1 / (100000 ** (i / 64)), for i = 0, 2, 4, ..., 62p, compute:1freqs = p * inv_freq
2emb = concat(freqs, freqs)
3q_rot = q * cos(emb) + rotate_half(q) * sin(emb)
4k_rot = k * cos(emb) + rotate_half(k) * sin(emb)rotate_half([x1, x2]) = [-x2, x1]x1 and x2 being the first and second halves of the head dimension.MLP(x) = down_proj(gelu(up_proj(x), exact=True))gate_proj.model.safetensors uses these parameter names:1model.embed_tokens.weight
2model.layers.N.input_layernorm.weight
3model.layers.N.self_attn.q_proj.weight
4model.layers.N.self_attn.k_proj.weight
5model.layers.N.self_attn.v_proj.weight
6model.layers.N.self_attn.o_proj.weight
7model.layers.N.post_attention_layernorm.weight
8model.layers.N.mlp.up_proj.weight
9model.layers.N.mlp.down_proj.weight
10model.norm.weightlm_head.weight; the output projection is tied to
model.embed_tokens.weight.| Token | Meaning |
|---|---|
| `< | end |
| `< | user |
| `< | assistant |
<think> | Start visible thinking trace |
</think> | End visible thinking trace |
| `< | pad |
<|user|>QUESTION<|end|><|assistant|>ANSWER<|end|><|user|>QUESTION 1<|end|><|assistant|>ANSWER 1<|end|><|user|>QUESTION 2<|end|><|assistant|><|user|>QUESTION<|end|><|assistant|><think>reasoning...</think>final answer<|end|><think>:<|user|>QUESTION<|end|><|assistant|><|end|> as the EOS token.generation_config.json because the
included custom model implementation favors correctness and simplicity.