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.

๋‚ด์šฉ / 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.

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/llama32-1b-reference

Finetuned
(1,863)
this model