As an individual with limited access and compute, I have been wondering if I could build a decent large-language model for a while. As the big mega corporations are focused on getting bigger and bigger models, I am going small!
As a result, I set up the following goals to pretraining a 300M Llama model with the following restrictions:
This project is heavily based on TinyLlama, which is an awesome open-source project aimed to pretraining a 1.1.1B Llama model on 1T tokens.
This project is work in progress. Currently, I have spent $280 on compute using 4 x Nvidia 4090 on Vast.ai and $3 on AWS S3 storage after 4 days of training of the 300M Llama model with 50B tokens.
I modified TinyLlama to support the following features (I will release my forked version of the source code after some clean up):
08/10/2025 - Released MicroLaVa, a lightweight Visual Q&A model based on TinyLLaVA_Factory. The MicroLaVa model contains only 700M parameters in total and can be pre-trained and fine-tuned on a single Nvidia RTX 4090. Built on MicroLlama, it already produces meaningful results with further improvements planned.
11/10/2024 - Published MicroLlama-text-embedding, a compact text embedding model for sentence similarity tasks. Based on MicroLlama architecture, this model is in active development and requires further optimization.
06/04/2024 - MicroLlama became officially supported in LitGPT. Thanks to the Lightning AI team for accepting my merge request and providing Lightning AI Studio credits.
I performed the experiment using the standard lm-evaluation-harness setup. Following the same setup as TinyLlama, I used acc_norm for all datasets except for winogrande and boolq which used acc as the metrics.
To reproduce my numbers, please install lm-evaluation-harness and run the following command:
lm_eval \ --model hf \ --model_args pretrained=keeeeenw/MicroLlama,dtype="float",tokenizer=TinyLlama/TinyLlama-1.1B-step-50K-105b \ --tasks hellaswag,openbookqa,winogrande,arc_easy,arc_challenge,boolq,piqa \ --device cuda:0 \ --batch_size 64
Based on the evaluation above, our model should be a good starting point for fine-tunning tasks that are typically performed using the BERT family of models. Some of tasks may include
import torch import transformers from transformers import AutoTokenizer, LlamaForCausalLM def generate_text(prompt, model, tokenizer): text_generator = transformers.pipeline( "text-generation", model=model, torch_dtype=torch.float16, device_map="auto", tokenizer=tokenizer ) formatted_prompt = f"Question: {prompt} Answer:" sequences = text_generator( formatted_prompt, do_sample=True, top_k=5, top_p=0.9, num_return_sequences=1, repetition_penalty=1.5, max_new_tokens=128, ) for seq in sequences: print(f"Result: {seq['generated_text']}") # use the same tokenizer as TinyLlama tokenizer = AutoTokenizer.from_pretrained("TinyLlama/TinyLlama-1.1B-step-50K-105b") # load model from huggingface # question from https://www.reddit.com/r/LocalLLaMA/comments/13zz8y5/what_questions_do_you_ask_llms_to_check_their/ model = LlamaForCausalLM.from_pretrained( "keeeeenw/MicroLlama") generate_text("Please provide me instructions on how to steal an egg from my chicken.", model, tokenizer)
This repository is built upon TinyLlama which is based on lit-gpt and flash-attention.
@misc{zhang2024tinyllama,
title={TinyLlama: An Open-Source Small Language Model},
author={Peiyuan Zhang and Guangtao Zeng and Tianduo Wang and Wei Lu},
year={2024},
eprint={2401.02385},
archivePrefix={arXiv},
primaryClass={cs.CL}
}
@online{lit-gpt,
author = {Lightning AI},
title = {Lit-GPT},
url = {https://github.com/Lightning-AI/lit-gpt},
year = {2023},
}
@article{dao2023flashattention2,
title ={Flash{A}ttention-2: Faster Attention with Better Parallelism and Work Partitioning},
author ={Dao, Tri},
year ={2023}
}
Special thanks to Xinyang, creator of the outstanding OpenLLaMA project, whose work inspired me to embark on this project. Iām grateful for the guidance in foundational concepts such as establishing scaling laws before training a model.
If you use MicroLlama in your research or work, please cite the project using the following reference: APA:
Wang, Z. K. (2024). MicroLlama: A 300M-parameter language model trained from scratch. GitHub & Hugging Face. https://github.com/keeeeenw/MicroLlama, https://huggingface.co/keeeeenw/MicroLlama
BibTeX:
@misc{wang2024microllama,
author = {Zixiao Ken Wang},
title = {MicroLlama: A 300M-parameter language model trained from scratch},
year = {2024},
howpublished = {\url{https://github.com/keeeeenw/MicroLlama}, \url{https://huggingface.co/keeeeenw/MicroLlama}},
note = {GitHub and Hugging Face repositories}
}
š Please cite this work if you find it useful.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4