smollm2-135m-reference

์ฑ… ใ€Ž๋ฐ‘๋ฐ”๋‹ฅ๋ถ€ํ„ฐ ๋งŒ๋“œ๋Š” ์ถ”๋ก  ์—”์ง„: Rust๋กœ ๋ฐฐ์šฐ๋Š” AI ์ธํผ๋Ÿฐ์Šค ์—”์ง€๋‹ˆ์–ด๋งใ€ (Building an Inference Engine from Scratch) 9์žฅ๋ถ€ํ„ฐ 13์žฅ๊นŒ์ง€ ์“ฐ๋Š” ์ •๋‹ต ํŒŒ์ผ์ž…๋‹ˆ๋‹ค. ๋ชจ๋ธ์˜ ๊ฐ€์ค‘์น˜๋Š” ๋“ค์–ด ์žˆ์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

PyTorch reference activations for HuggingFaceTB/SmolLM2-135M-Instruct, used to verify the book's inference engine, badak, layer by layer. This repository contains no model weights.

๋‚ด์šฉ / Contents

reference.safetensors๋Š” ๊ธ€ ํ•˜๋‚˜(The capital of France is Paris. ์ถ”๋ก  ์—”์ง„, ํ† ํฐ 19๊ฐœ)๋ฅผ ๋ชจ๋ธ์— ๋„ฃ์—ˆ์„ ๋•Œ์˜ ๊ณ„์‚ฐ ๊ฒฐ๊ณผ์ž…๋‹ˆ๋‹ค.

์ด๋ฆ„ ํ˜•์ƒ ๋‚ด์šฉ
ids (19) ํ† ํฐ ๋ฒˆํ˜ธ
embed (19, 576) ์ž„๋ฒ ๋”ฉ
l0.norm1, l0.q, l0.k, l0.v ์ฒซ ๋ธ”๋ก์˜ ์ •๊ทœํ™”์™€ ์งˆ์˜ยทํ‚คยท๊ฐ’
l0.attn_weights (9, 19, 19) ์ฒซ ๋ธ”๋ก์˜ ์–ดํ…์…˜ ๋น„์ค‘
l0.attn, l0.norm2, l0.mlp, l0.out (19, 576) ์ฒซ ๋ธ”๋ก์˜ ๋‚˜๋จธ์ง€ ๋ถ€ํ’ˆ
hidden_states (31, 19, 576) ์ž„๋ฒ ๋”ฉ๊ณผ ๋ธ”๋ก ๊ฐ๊ฐ์˜ ์ถœ๋ ฅ. ๋งˆ์ง€๋ง‰ ๊ฒƒ๋งŒ์€ ๋งˆ์ง€๋ง‰ ์ •๊ทœํ™”๊นŒ์ง€ ๊ฑฐ์นœ ๊ฐ’(final_norm๊ณผ ๊ฐ™์Œ)
final_norm (19, 576) ๋งˆ์ง€๋ง‰ ์ •๊ทœํ™”
logits (19, 49152) ์ตœ์ข… ์ ์ˆ˜

tokenizer_vectors.json์€ ์›๋ณธ ๋ชจ๋ธ์˜ tokenizer.json์„ Hugging Face tokenizers๋กœ ์ฝ์–ด ์—ฌ๋Ÿฌ ๊ธ€์„ ํ† ํฐ ๋ฒˆํ˜ธ๋กœ ๋ฐ”๊พผ ๊ฒฐ๊ณผ์ž…๋‹ˆ๋‹ค(10์žฅ). ๊ธ€์˜ ์‹œ์ž‘์„ ์•Œ๋ฆฌ๋Š” ํ† ํฐ์€ ๋ถ™์ด์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค. reference/ch10_tokenizer_vectors.py smollm2_135m๋กœ ๋งŒ๋“ค์—ˆ์Šต๋‹ˆ๋‹ค.

generation.json์€ PyTorch๋กœ ๊ธ€ ๋‘ ๊ฐœ๋ฅผ ์ด์–ด ์“ด ๊ฒฐ๊ณผ์ž…๋‹ˆ๋‹ค(11์žฅ). ๋งค๋ฒˆ ์ ์ˆ˜๊ฐ€ ๊ฐ€์žฅ ๋†’์€ ํ† ํฐ์„ ๊ณจ๋ž์Šต๋‹ˆ๋‹ค. ๋„ฃ์€ ํ† ํฐ, ์ƒˆ๋กœ ๋ฝ‘ํžŒ ํ† ํฐ, ๋ฝ‘์„ ๋•Œ๋งˆ๋‹ค์˜ 1์œ„์™€ 2์œ„์˜ ์ ์ˆ˜ ์ฐจ์ด๊ฐ€ ๋“ค์–ด ์žˆ์Šต๋‹ˆ๋‹ค. reference/ch11_generation_reference.py smollm2_135m๋กœ ๋งŒ๋“ค์—ˆ์Šต๋‹ˆ๋‹ค.

generation.json holds greedy continuations produced with PyTorch: the prompt ids, the generated ids, and the top-1/top-2 logit margin at each step.

sampling.safetensors๋Š” ์ƒ˜ํ”Œ๋ง ์„ค์ • ์ผ๊ณฑ ๊ฐ€์ง€์— ๋Œ€ํ•ด, ์ ์ˆ˜๋ฅผ ์†์งˆํ•œ ๋’ค์˜ ํ™•๋ฅ ๋ถ„ํฌ๋ฅผ transformers์˜ ๊ตฌํ˜„์œผ๋กœ ๊ณ„์‚ฐํ•œ ๊ฒƒ์ž…๋‹ˆ๋‹ค(12์žฅ). ์ž…๋ ฅ์€ reference.safetensors์˜ ๋งˆ์ง€๋ง‰ ์ค„์˜ ์ ์ˆ˜์ด๊ณ  ๊ณ„์‚ฐ์€ f64๋กœ ํ–ˆ์Šต๋‹ˆ๋‹ค. ์„ค์ •์€ ๋ฉ”ํƒ€๋ฐ์ดํ„ฐ์˜ cases์— JSON์œผ๋กœ ์ ํ˜€ ์žˆ์Šต๋‹ˆ๋‹ค. reference/ch12_sampling_reference.py smollm2_135m๋กœ ๋งŒ๋“ค์—ˆ์Šต๋‹ˆ๋‹ค.

sampling.safetensors holds next-token distributions after repetition penalty, temperature, top-k and top-p, computed in float64 with the transformers logits processors for the seven settings listed in its metadata.

logits.safetensors๋Š” ์—ฌ๋Ÿฌ ์—”์ง„์˜ ์ ์ˆ˜๋ฅผ ๊ฒฌ์ค„ ๊ธฐ์ค€์ž…๋‹ˆ๋‹ค(13์žฅ). ๊ธ€ The capital of France is์˜ ๋งˆ์ง€๋ง‰ ํ† ํฐ ๋‹ค์Œ ์ ์ˆ˜๋ฅผ ๊ฐ€์ค‘์น˜๋ฅผ f64๋กœ ๋ฐ”๊ฟ” ๊ณ„์‚ฐํ–ˆ์Šต๋‹ˆ๋‹ค. f64๋ฅผ f32 ๋‘˜(truth_hi + truth_lo)๋กœ ๋‚˜๋ˆ„์–ด ๋‹ด์•˜๊ณ , ํ‰์†Œ์ฒ˜๋Ÿผ f32๋กœ ๊ณ„์‚ฐํ•œ ๊ฐ’(pytorch_f32)๋„ ํ•จ๊ป˜ ๋“ค์–ด ์žˆ์Šต๋‹ˆ๋‹ค. reference/ch13_logits_reference.py smollm2_135m๋กœ ๋งŒ๋“ค์—ˆ์Šต๋‹ˆ๋‹ค.

logits.safetensors holds next-token logits computed in float64 (split into two float32 tensors, truth_hi + truth_lo) as ground truth for comparing engines, together with the usual float32 result.

Note that the last entry of hidden_states has the final normalization applied, as transformers returns it. tokenizer_vectors.json holds token ids produced by the original tokenizer for a set of test strings.

๋งŒ๋“  ๋ฐฉ๋ฒ• / How it was made

์ €์žฅ์†Œ์˜ reference/ch09_llama_reference.py๋กœ ๋งŒ๋“ค์—ˆ์Šต๋‹ˆ๋‹ค. transformers 5.23.0, torch 2.15.0, ๊ฐ€์ค‘์น˜๋ฅผ f32๋กœ ํŽผ์ณ CPU์—์„œ ๊ณ„์‚ฐํ–ˆ์Šต๋‹ˆ๋‹ค.

sh scripts/download_smollm2.sh
python reference/ch09_llama_reference.py smollm2_135m

๋ผ์ด์„ ์Šค / License

์›๋ณธ ๋ชจ๋ธ SmolLM2-135M-Instruct๋Š” Hugging Face TB๊ฐ€ Apache License 2.0์œผ๋กœ ๊ณต๊ฐœํ–ˆ์Šต๋‹ˆ๋‹ค. ์ด ์ €์žฅ์†Œ์˜ ํŒŒ์ผ์€ ๊ทธ ๋ชจ๋ธ๋กœ ๊ณ„์‚ฐํ•œ ๊ฐ’์ด๋ฉฐ ๊ฐ™์€ ๋ผ์ด์„ ์Šค๋ฅผ ๋”ฐ๋ฆ…๋‹ˆ๋‹ค.

The values were computed with SmolLM2-135M-Instruct, released by Hugging Face TB under the Apache License 2.0, and are distributed under the same license.

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support

Model tree for building-an-inference-engine-from-scratch/smollm2-135m-reference

Finetuned
(427)
this model