| --- |
| license: cdla-sharing-1.0 |
| language: |
| - en |
| library_name: pytorch |
| pipeline_tag: text-generation |
| datasets: |
| - roneneldan/TinyStories |
| tags: |
| - tinystories |
| - small-language-model |
| --- |
| |
| # tinyLLM 29M β TinyStories |
|
|
| 1λ¨κ³ μ¬μ νμ΅λ§ κ±°μΉ κ°μ€μΉ. λνλ λͺ» νκ³ μ΄μΌκΈ°λ₯Ό μ΄μ΄μ΄λ€. |
|
|
| νλΌλ―Έν° **29,577,728** κ°. RTX 3060 Ti ν λμμ μ¬μ νμ΅ 3.06 μκ° + SFT 2.4 λΆ. |
| νμ΅ μ½λμ μ€κ³ κ·Όκ±°: https://github.com/sciencemj/tinyLLM |
|
|
| val loss 1.3202 nats/token (perplexity 3.744, bits/char 0.4659) |
|
|
| ## μ΄μ© 쑰건 |
|
|
| **μ΄μ© μ μ½μ΄ μλ€.** TinyStories λ CDLA-Sharing-1.0 μ΄κ³ Β§3.5 κ° λͺ
μνλ€ β *"This Agreement imposes no obligations or restrictions on Your Use or Publication of Results."* Β§1.11 μμ Results λ λ°μ΄ν°μ Computational Use λ‘ μ»μ μ°μΆλ¬Όμ΄λ©°, 쑰건μ λ°μ΄ν°μ de minimis λΆλ μ΄μμ ν¬ν¨νμ§ μλ κ²μ΄λ€. μ΄ λͺ¨λΈμ train/val κ²©μ°¨κ° 0.03 μ΄λΌ μ½νΌμ€λ₯Ό μΈμ°κ³ μμ§ μλ€. |
|
|
| ## μ°λ λ² |
|
|
| `transformers` λ₯Ό μ°μ§ μλλ€. μ΄ μ μ₯μμ `modeling_tinyllm.py` νλλ©΄ λλ€. |
|
|
| ```python |
| import torch |
| from tokenizers import Tokenizer |
| from modeling_tinyllm import TinyLM |
| |
| model = TinyLM.from_pretrained(".") |
| tok = Tokenizer.from_file("tokenizer.json") |
| |
| ids = torch.tensor([tok.encode("Once upon a time, there was a little girl named Lily.").ids]) |
| out = model.generate(ids, 60, temperature=0.6, top_k=20) |
| print(tok.decode(out[0].tolist(), skip_special_tokens=True)) |
| ``` |
|
|
| μ΄ κ°μ€μΉλ λνλ₯Ό λͺ» νλ€. μ§λ¬Έμ μ£Όλ©΄ μ΄μΌκΈ°μ 첫 λ¬Έμ₯μΌλ‘ λ°μ |
| κ³μ μ¨ λ΄λ €κ°λ€. λνκ° νμνλ©΄ |
| [tinyllm-29m-chat](https://huggingface.co/sciencemj/tinyllm-29m-chat) μ μ΄λ€. |
|
|
| ## ꡬ쑰 |
|
|
| ``` |
| ids (B, 512) |
| β nn.Embedding(8000, 512) + nn.Embedding(512, 512) |
| β nn.TransformerEncoder( |
| nn.TransformerEncoderLayer(512, nhead=8, dim_feedforward=2048, |
| activation="gelu", norm_first=True, |
| batch_first=True), |
| num_layers=8, norm=nn.RMSNorm(512)) |
| β nn.Linear(512, 8000, bias=False) # token embedding κ³Ό tying |
| ``` |
|
|
| decoder-only λ₯Ό `TransformerEncoderLayer` λ‘ λ§λ λ€. `TransformerDecoderLayer` λ |
| cross-attention μ© `memory` λ₯Ό νμλ‘ μꡬν΄μ λ§μ§ μλλ€. |
|
|
| ν ν¬λμ΄μ λ TinyStories μ DailyDialog ν©μ§ν©μμ νμ΅ν μ체 8k byte-level BPE λ€. |
| **κ°μ΄ λ°μ `tokenizer.json` μ λ°λμ μ¨μΌ νλ€.** λ€λ₯Έ ν ν¬λμ΄μ λ‘λ λμνμ§ μλλ€. |
|
|
| ## νκ³ |
|
|
| **λλ€** β λ¬Έλ², ꡬλμ , λ°μ΄ν λν νμ, λ¬Έλ¨ λλκΈ°, μΈλ¬Ό μ΄λ¦ μ μ§, μΈκ³Ό μ°κ²°. |
|
|
| **μ λλ€** β ν΄ κ° κΈ°μ΅, μ§λ¬Έμ λν μ§μ λ΅λ³, μ¬μ€μ±, λ¬Έμ₯ μ λ°λ³΅, λ
Όλ¦¬ μΌκ΄μ±. |
| μμ΄λ§ μλ€. μ¬μ€ μ 보λ₯Ό μ»λ μ©λλ‘ μ°λ©΄ μ λλ€. |
|
|
| μμΈν κ²μ [MODEL_CARD.md](https://github.com/sciencemj/tinyLLM/blob/main/MODEL_CARD.md). |
|
|
| ## μΈμ© |
|
|
| ```bibtex |
| @article{eldan2023tinystories, |
| title={TinyStories: How Small Can Language Models Be and Still Speak Coherent English?}, |
| author={Eldan, Ronen and Li, Yuanzhi}, |
| journal={arXiv preprint arXiv:2305.07759}, |
| year={2023} |
| } |
| ``` |
|
|