sciencemj/tinyllm-29m-tinystories
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 하나면 된다.
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 을 쓴다.
구조
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 과 tyingdecoder-only 를 TransformerEncoderLayer 로 만든다. TransformerDecoderLayer 는 cross-attention 용 memory 를 필수로 요구해서 맞지 않는다.
토크나이저는 TinyStories 와 DailyDialog 합집합에서 학습한 자체 8k byte-level BPE 다. 같이 받은 `tokenizer.json` 을 반드시 써야 한다. 다른 토크나이저로는 동작하지 않는다.
한계
된다 — 문법, 구두점, 따옴표 대화 형식, 문단 나누기, 인물 이름 유지, 인과 연결.
안 된다 — 턴 간 기억, 질문에 대한 직접 답변, 사실성, 문장 안 반복, 논리 일관성. 영어만 안다. 사실 정보를 얻는 용도로 쓰면 안 된다.
자세한 것은 MODEL_CARD.md.
인용
@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}
}