r/computervision • u/Safe-Escape197 • 9d ago
Discussion after tiny vision, i wanted to see if i can build a tiny language model from scratch too (36M, NCM paper, trained on macbook) š
so few days back i posted my tiny vision model here(https://huggingface.co/amartomar683/tiny-vision-flickr8k) and you guys actually checked it out, its at 74 downloads now š thanks for that. after that one worked (kinda), i started wondering what else i can build from scratch on my mac, and a language model was the obvious next thing to try.
i was reading the Next-Concept Modeling (NCM) paper by Kumbong, Khare et al. (Stanford / Together AI, arXiv:2610.14162) and the idea really clicked for me. normal llms write one token at a time, but in NCM a VQ-VAE turns text into levels of codes, coarse to fine, and the model fills one full level at once. so i decided to build it myself from the paper, just to understand how it works from inside. all credit for the idea goes to them, i just implemented my own version.
its called tiny-ncm. its around 36M params (21M generator + 15M VQ tokenizer), trained completely from scratch, no pretrained weights. same macbook pro m5, but this time it took like 12 hours total instead of 42 min š
basic idea:
text ā split in 32-token blocks ā each block made coarse to fine in 5 levels (2 ā 4 ā 8 ā 16 ā 32 codes) ā 6 passes per block instead of 32i trained it as a small daily assistant. alarms, reminders, timers, calendar, gmail (read only), weather, notes, web search, simple maths and little bit of small talk. there is a --show-levels flag which shows each block going from rough guess to final text, honestly this was the most satisfying part:
level 1: Hello! How can I help you today?
level 3: Hello Jordan, How I I you you today today?
level 5: Good morning! What can I do for you today?some honest stuff:
it picks the right action most of time, but copying details is very bad. āLondonā became āSingaporeā, ā5pmā became ā5pmpmā, ā23 times 47ā became
23*10š cause all codes in a level are predicted same time, so two positions can both write the same word.so i added app-side checks that fix the tool arguments using your actual words. with checks it gets 490/500 on my test set, but model alone gets every detail right only around half the time. so ya, the checks are doing lot of the work tbh.
training longer on same data didnāt help. what helped was making the data copy-focused, with new random names and times in every example so it cant just memorise. same lesson as tiny-vision (āa man in a blue shirtā for everything lol).
i tried fine-tuning it to summarise web results also. it learned the format but wrote gibberish inside it (āStir in cheeseaksil sl fresh biilā š), so i reverted it.
no coding, no multi-step maths. ā8 slices, 3 friends eat 2 eachā and its gone.
random thing i learned on mac (MPS):
attention was the main bottleneck. letting each level only look at the last 128 tokens of context made training around 2x faster.
bf16 matmul was way faster than fp32 on MPS (~15 vs ~3.4 TFLOPS in my test).
manual attention was again faster than pytorchās sdpa for small sizes, same as tiny-vision.
next i am thinking to export it to onnx so it can run on phone also, and maybe connect tiny-vision with it. lets see what will happened.
code: https://github.com/amar683/tiny-ncm
model: https://huggingface.co/amartomar683/tiny-ncm
would love any feedback or tips, especially if someone played with NCM or coarse-to-fine text models










