AutoLearn 40M Chat
A 40M-Parameter Chat Model Trained From Scratch on a MacBook
3 min readupdated
AutoLearn 40M Chat is a miniature English-language conversational AI model (LLM) trained entirely from scratch on a single Apple M3 laptop (16 GB) without using external weights. The author independently built the tokenizer (which splits text into fragments for the model), the pre-training stage, and the final chat fine-tuning. It relies on a Llama-style architecture featuring modern components like GQA (group-query attention to save memory) and SwiGLU. With its 40.4M parameters and a size of just 58 MB after int8 quantization, the model runs locally straight inside the browser without needing a backend server. It is well-suited for developers and hobbyists looking for an open-source educational example of a full LLM training cycle from scratch and for experimenting with local inference on low-power devices.
Key features
- Full cycle from scratch: Byte-level BPE tokenizer (32,768 tokens), pre-training, and chat fine-tuning completed independently by the author on an Apple M3 MacBook.
- Direct browser execution: Using the
transformers.jslibrary in int8 ONNX format, the model takes up just 58 MB and runs directly on the user's device without a server. - Llama-type architecture: 8 layers, a hidden size of 512, RMSNorm, RoPE (rotary positional embeddings), GQA (8 attention heads / 4 KV heads), and SwiGLU.
- Open source and license: Weights are released under Apache 2.0, while the source code for training and export to the Hugging Face Llama format is available in the AutoLearn API repository.
What you can do
- Embed an offline chat into a web application using
@huggingface/transformers(transformers.js) so that generation happens entirely within the client browser. - Use the training source code and model architecture as a practical template for training your own ultra-small LLMs on consumer hardware.
- Run local text generation tests using the standard
transformersstack on hardware with strict memory constraints.
Example
from transformers import AutoModelForCausalLM, AutoTokenizer
repo = "Likhith003/autolearn-40m-chat"
tok = AutoTokenizer.from_pretrained(repo)
model = AutoModelForCausalLM.from_pretrained(repo)
ids = tok.apply_chat_template([{"role": "user", "content": "What is the capital of France?"}],
add_generation_prompt=True, return_tensors="pt")
out = model.generate(ids, max_new_tokens=100)
Read more
DetailsTraining: pre-training on 2.9B tokens from FineWeb-Edu (180,000 steps, ~9 days on Apple M3 GPU, validation loss 3.55), chat fine-tuning on 100,000 dialogues from SmolTalk (2.8 hours on Apple M3, validation loss 1.48).
Context: 512 tokens; weight of the int8 ONNX browser version is 58 MB.
Limitations: research model; writes fluently in English, but often hallucinates facts, loses track in long conversations, and has not undergone safety tuning beyond SmolTalk data.










Comments