llama32-1b-reference
Built with Llama.
์ฑ ใ๋ฐ๋ฐ๋ฅ๋ถํฐ ๋ง๋๋ ์ถ๋ก ์์ง: Rust๋ก ๋ฐฐ์ฐ๋ AI ์ธํผ๋ฐ์ค ์์ง๋์ด๋งใ (Building an Inference Engine from Scratch) 9์ฅ๋ถํฐ 13์ฅ๊น์ง ์ฐ๋ ์ ๋ต ํ์ผ์ ๋๋ค. ๋ชจ๋ธ์ ๋๋ฆด ์ ์๋ ๊ฐ์ค์น๋ ๋ค์ด ์์ง ์์ต๋๋ค.
PyTorch reference activations for
meta-llama/Llama-3.2-1B-Instruct,
used to verify the book's inference engine, badak, layer by layer. To run
the model you still need to obtain the weights from Meta's repository.
- ์ฑ / 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. ์ถ๋ก ์์ง,
ํ ํฐ 11๊ฐ)๋ฅผ ๋ชจ๋ธ์ ๋ฃ์์ ๋์ ๊ณ์ฐ ๊ฒฐ๊ณผ์
๋๋ค.
| ์ด๋ฆ | ํ์ | ๋ด์ฉ |
|---|---|---|
ids |
(11) |
ํ ํฐ ๋ฒํธ |
embed |
(11, 2048) |
์๋ฒ ๋ฉ. ์๋ณธ ๋ชจ๋ธ์ ์๋ฒ ๋ฉ ํ์์ ์ด ํ ํฐ๋ค์ ํด๋นํ๋ ํ 11๊ฐ์ ๋๋ค. |
l0.norm1, l0.q, l0.k, l0.v |
์ฒซ ๋ธ๋ก์ ์ ๊ทํ์ ์ง์ยทํคยท๊ฐ | |
l0.attn_weights |
(32, 11, 11) |
์ฒซ ๋ธ๋ก์ ์ดํ ์ ๋น์ค |
l0.attn, l0.norm2, l0.mlp, l0.out |
(11, 2048) |
์ฒซ ๋ธ๋ก์ ๋๋จธ์ง ๋ถํ |
hidden_states |
(17, 11, 2048) |
์๋ฒ ๋ฉ๊ณผ ๋ธ๋ก ๊ฐ๊ฐ์ ์ถ๋ ฅ. ๋ง์ง๋ง ๊ฒ๋ง์ ๋ง์ง๋ง ์ ๊ทํ๊น์ง ๊ฑฐ์น ๊ฐ(final_norm๊ณผ ๊ฐ์) |
final_norm |
(11, 2048) |
๋ง์ง๋ง ์ ๊ทํ |
logits |
(11, 128256) |
์ต์ข ์ ์ |
tokenizer_vectors.json์ ์๋ณธ ๋ชจ๋ธ์ tokenizer.json์ Hugging Face
tokenizers๋ก ์ฝ์ด ์ฌ๋ฌ ๊ธ์ ํ ํฐ ๋ฒํธ๋ก ๋ฐ๊พผ ๊ฒฐ๊ณผ์
๋๋ค(10์ฅ). ๊ธ์ ์์์
์๋ฆฌ๋ ํ ํฐ์ ๋ถ์ด์ง ์์์ต๋๋ค. reference/ch10_tokenizer_vectors.py llama32_1b๋ก
๋ง๋ค์์ต๋๋ค.
generation.json์ PyTorch๋ก ๊ธ ๋ ๊ฐ๋ฅผ ์ด์ด ์ด ๊ฒฐ๊ณผ์
๋๋ค(11์ฅ). ๋งค๋ฒ ์ ์๊ฐ
๊ฐ์ฅ ๋์ ํ ํฐ์ ๊ณจ๋์ต๋๋ค. ๋ฃ์ ํ ํฐ, ์๋ก ๋ฝํ ํ ํฐ, ๋ฝ์ ๋๋ง๋ค์ 1์์
2์์ ์ ์ ์ฐจ์ด๊ฐ ๋ค์ด ์์ต๋๋ค. reference/ch11_generation_reference.py llama32_1b๋ก
๋ง๋ค์์ต๋๋ค.
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 llama32_1b๋ก ๋ง๋ค์์ต๋๋ค.
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 llama32_1b๋ก ๋ง๋ค์์ต๋๋ค.
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_llama32.sh
python reference/ch09_llama_reference.py llama32_1b
๋ผ์ด์ ์ค / License
์ด ์ ์ฅ์์ ๊ฐ์ Meta์ Llama 3.2 1B Instruct๋ก ๊ณ์ฐํ ๊ฒ์ด๋ฉฐ, embed๋ ๊ทธ
๋ชจ๋ธ ๊ฐ์ค์น์ ์ผ๋ถ์
๋๋ค. Llama 3.2 Community License์ ๋ฐ๋ผ ๋ฐฐํฌํฉ๋๋ค.
๋ผ์ด์ ์ค ์ ๋ฌธ์ LICENSE.txt์, ๊ณ ์ง๋ฌธ์ NOTICE์, ์ฌ์ฉ ์ ์ฑ
์
USE_POLICY.md์ ์์ต๋๋ค.
The values here were computed with Meta's Llama 3.2 1B Instruct, and embed
is a small portion of that model's weights. They are distributed under the
Llama 3.2 Community License. See LICENSE.txt, NOTICE, and USE_POLICY.md.
Llama 3.2 is licensed under the Llama 3.2 Community License, Copyright ยฉ Meta Platforms, Inc. All Rights Reserved.
Model tree for building-an-inference-engine-from-scratch/llama32-1b-reference
Base model
meta-llama/Llama-3.2-1B-Instruct