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.
- ์ฑ / Book: https://chosungmann.github.io/building-an-inference-engine-from-scratch/
- ์ฝ๋ / Code: https://github.com/chosungmann/building-an-inference-engine-from-scratch
๋ด์ฉ / 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.
Model tree for building-an-inference-engine-from-scratch/smollm2-135m-reference
Base model
HuggingFaceTB/SmolLM2-135M