Text Generation
Transformers
Safetensors
English
gemma4_text
udgamlabs
math
word-problems
program-aided
python
code-execution
gsm8k
small-model
from-scratch
Run this model with HF Jobs
Run udgamlabs/Lilavati on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs and TRL to fine-tune https://huggingface.co/udgamlabs/Lilavati. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/udgamlabs/Lilavati on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Evaluate on a benchmark
Use HF Jobs to evaluate https://huggingface.co/udgamlabs/Lilavati. Ask me which benchmark to run, then save the scores and the per-example results to a new dataset repo. Run `hf jobs --help` first to learn the CLI.
Quantize for lower memory use
Use HF Jobs to create a 4-bit version of https://huggingface.co/udgamlabs/Lilavati. Push it to a new model repo, then reload it from there and report its memory footprint. Run `hf jobs --help` first to learn the CLI.
Instructions to use udgamlabs/Lilavati with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use udgamlabs/Lilavati with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="udgamlabs/Lilavati")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("udgamlabs/Lilavati") model = AutoModelForCausalLM.from_pretrained("udgamlabs/Lilavati", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use udgamlabs/Lilavati with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "udgamlabs/Lilavati" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "udgamlabs/Lilavati", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/udgamlabs/Lilavati
- SGLang
How to use udgamlabs/Lilavati with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "udgamlabs/Lilavati" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "udgamlabs/Lilavati", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "udgamlabs/Lilavati" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "udgamlabs/Lilavati", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use udgamlabs/Lilavati with Docker Model Runner:
docker model run hf.co/udgamlabs/Lilavati
Lilavati 1.0.0: weights, model card
Browse filesFiles changed (9)
- .gitattributes+1
- README.mdAdded+214
- assets/compare.pngAdded
- assets/tries.pngAdded
- config.jsonAdded+74
- generation_config.jsonAdded+9
- model.safetensorsAdded+3
- tokenizer.jsonAdded
- tokenizer_config.jsonAdded+25
32 unmodified lines33343532 unmodified lines*.zip filter=lfs diff=lfs merge=lfs -text*.zst filter=lfs diff=lfs merge=lfs -text*tfevents* filter=lfs diff=lfs merge=lfs -text32 unmodified lines3334353632 unmodified lines*.zip filter=lfs diff=lfs merge=lfs -text*.zst filter=lfs diff=lfs merge=lfs -text*tfevents* filter=lfs diff=lfs merge=lfs -textassets/tries.png filter=lfs diff=lfs merge=lfs -text
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214---license: apache-2.0language:- enpipeline_tag: text-generationlibrary_name: transformerstags:- math- word-problems- program-aided- python- code-execution- gsm8k- small-model- from-scratchdatasets:- TinyGSM/TinyGSM- reciprocate/tinygsm_mixtral_12M- openai/gsm8k---
# Lilavati: Pocket Mathematician
**A 95M-parameter English model, trained from scratch by Udgam Labs, that solves maths word problems by writing a shortPython program and running it.** It is small enough to run on a laptop CPU.
The name comes from *Līlāvatī* (लीलावती), the book of arithmetic word problems that the mathematician Bhāskara II wrotein 1150 CE.
**More:** [try it in your browser](https://udgamlabs.com/models/lilavati) · [code and evaluation on GitHub](https://github.com/UdgamLabs/lilavati) · [the checker model](https://huggingface.co/UdgamLabs/Lilavati-Checker)
```Question: A chai stall sells 45 cups of tea in the morning and twice as many in the evening. Each cup costs 12 rupees. How many rupees does the stall earn in a day?
Lilavati writes: Running it gives: morning_sales = 45 1620 evening_sales = morning_sales * 2 cup_price = 12 total_sales = (morning_sales + evening_sales) * cup_price result = total_sales return result```
| | ||---|---|| Developer | Udgam Labs || Parameters | 94.7M (12 layers, width 640, tied embeddings) || Context | 4,096 tokens || Input / output | an English word problem → a Python function whose return value is the answer || Training | from scratch: public synthetic maths datasets with Python solutions, plus general English text; then further training on word problems with execution-verified Python solutions || Companion | [Lilavati-Checker](https://huggingface.co/UdgamLabs/Lilavati-Checker) (95M) rates programs so that many tries can be combined || Licence | Apache-2.0 |
## Quick start
The `lilavati` package writes the programs, runs them in a restricted sandbox and combines the answers:
```bashpip install torch transformersgit clone https://github.com/UdgamLabs/lilavati && cd lilavati && pip install -e .```
```pythonfrom lilavati import Lilavatilv = Lilavati() # downloads UdgamLabs/Lilavati and UdgamLabs/Lilavati-Checker
r = lv.solve("A shop sells pencils at 8 rupees each. Riya buys 6 pencils and 2 erasers at 5 rupees each. " "She pays with a 100 rupee note. How much change does she get?")print(r["answer"]) # 42print(r["agreement"]) # share of tries that gave this answerprint(r["program"]) # the program behind the answer```
- `lv.solve(q, tries=1)` is one greedy try: fastest, no checker.- `lv.solve(q, tries=8)` (default) writes 8 programs at temperature 0.7, runs them all, and picks the answer with the most checker-weighted support. More tries are slower but more accurate (see the evaluation).
**Using the model directly.** The prompt format is:
````<bos>Question: {question}Answer (Python):```python````
The model continues with a function and closes the code block. For several tries, sample at temperature 0.7 with top-kand top-p turned off, as in the evaluation. Requires `transformers` 5.18 or newer. **Never run generated code without a sandbox.** The`lilavati` package checks each program's structure (maths-only imports, no file or network access, no dunder access),then runs it in a separate process with time and memory limits, and under the macOS sandbox where available.
## What it is good at, and what it is not
It is good at grade-school word problems: shopping and change, rates and speeds, percentages, discounts and tax,averages, simple interest, areas and perimeters, and multi-step arithmetic.
It is weak at:- **irrelevant information:** a number that should be ignored often gets used anyway;- **working backwards** and problems that **add an extra step** to a familiar pattern;- **unit conversions** and some **ratio** questions;- **unanswerable questions:** it always returns a number, even when the question has no answer;- anything that is not a maths word problem. It is not a chatbot and has little general knowledge.
`solve()` returns `agreement` and `confidence`. When they are low (below 0.5), treat the answer as a guess.
## Evaluation
All numbers were measured by us. "Code executed" means the model's program is run and its return value is compared withthe reference answer.
**One try (greedy), code executed:**
| Test set | Lilavati ||---|---|| GSM8K test (1,319) | **54.7** || GSM-Plus testmini, the 7 answerable perturbation types (2,100) | 39.2 || SVAMP (1,000) | 69.9 || ASDiv, numeric answers (2,159) | 74.0 || GSM-Hard (1,319) | 43.7 |
**Many tries with the checker (GSM8K test, 48 programs per problem at temperature 0.7):**
| How the answer is chosen | Score ||---|---|| Checker-weighted vote (the default in `solve()`) | **72.3** || The checker's single top-rated program | 66.7 || Plain majority vote | 65.7 || At least one of the 48 programs is right (an upper bound) | 89.5 |
With 16 tries, the checker-weighted vote scores 68.8.
### Comparison with other open models up to 150M parameters
<p align="center"><img src="assets/compare.png" alt="GSM8K test: Lilavati 54.7%, cagliostro-v3.5-chat 21.3%, Falcon-H1-Tiny-R 18.7%" width="100%"></p>
Measured by us on 15 October 2026, greedy, with one harness. Other models answer in text, their native format, and arescored on their final number.
| Model | Params | GSM8K test | Notes ||---|---|---|---|| **Lilavati** | 95M | **54.7** (57.3 on the first 300) | code executed || cagliostro-v3.5-chat | 146M | 21.3 | first 300 items || Falcon-H1-Tiny-R-90M | 90M | 18.7 | all items, 8K-token cap. SVAMP: 40.1 (Lilavati 69.9) || MobileLLM-R1.5-140M | 140M | 6.7 | first 300 items; 99% of its answers ran past our 8K-token cap. Its developers report 8.3 || GPT-X3-150M | 150M | 2.3 | || GPT-X2.5-135M | 135M | 1.7 | || Supra2-100M-Instruct | 100M | 1.6 | || JugnuLM-110M-R2plus | 110M | 1.3 | |
**Published results for models whose weights are not released:** TinyGSM (Liu et al., 2023,[arXiv:2312.09241](https://arxiv.org/abs/2312.09241)) reports a 125M model, first pretrained on Phi-1.5 data, at 63.1%with one try and 68.9% when a 125M verifier picks one of 48 programs. Under that exact protocol (the checker's single toppick), Lilavati scores 66.7%. TinyGSM's 125M model trained from random initialisation reports 53.1%.
### Contamination audit
We checked every training document against each test set for shared 13-word sequences:
| Test set | Items sharing a 13-gram with training data ||---|---|| GSM8K test | 0 || GSM-Hard | 0 || GSM-Plus testmini | 0.8% || SVAMP | 2.2% || ASDiv | 7.1% |
Scores on the items with no overlap are the same as or higher than on the overlapping items, so overlap does not explainthe results. Problems added in later training were filtered against all these test sets (8-word sequences).
## How it works
<p align="center"><img src="assets/tries.png" alt="Eight programs for one cricket question; five return 75, and the checker-weighted vote picks 75" width="100%"></p>
1. **Lilavati** (this model) reads the question and writes a short Python function.2. The program passes a structure check and runs in a restricted sandbox. Its return value is a candidate answer.3. For more accuracy, Lilavati writes several programs. **Lilavati-Checker**, a second 95M model, reads the question and each program with its result and rates how likely it is to be right. The answer with the most checker-weighted support wins.
**Training data:**- [TinyGSM](https://huggingface.co/datasets/TinyGSM/TinyGSM) (MIT): about 12M grade-school problems with Python solutions;- [tinygsm_mixtral_12M](https://huggingface.co/datasets/reciprocate/tinygsm_mixtral_12M): TinyGSM-style problems with solutions written by Mixtral;- general English web and educational text;- the [GSM8K](https://huggingface.co/datasets/openai/gsm8k) training split (MIT), and problems generated with large language models and verified by executing their solutions.
No test-set problems were used for training.
## Intended use and limitations
**Intended use:** research and education on small reasoning models, program-aided maths, offline maths help on smalldevices, and as a starting point for fine-tuning.
**Not suitable for:** grading, financial or medical calculations, or anything where a wrong number could cause harm,without a person checking the program. A program that runs is not proof that it is correct.
The training problems are mostly in the style of English grade-school maths. Expect lower accuracy on other styles,longer problems, and other languages.
## Licence
Weights and code: Apache-2.0.
## Citation
```bibtex@misc{lilavati2026, title = {Lilavati: a 95M pocket mathematician that solves word problems by writing Python}, author = {Udgam Labs}, year = {2026}, url = {https://huggingface.co/UdgamLabs/Lilavati}}```1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374{ "architectures": [ "Gemma4ForCausalLM" ], "attention_bias": false, "attention_dropout": 0.0, "attention_k_eq_v": false, "bos_token_id": 2, "dtype": "bfloat16", "enable_moe_block": false, "eos_token_id": 1, "final_logit_softcapping": 15.0, "head_dim": 64, "hidden_activation": "gelu_pytorch_tanh", "hidden_size": 640, "hidden_size_per_layer_input": 0, "initializer_range": 0.02, "intermediate_size": 2560, "layer_types": [ "sliding_attention", "sliding_attention", "sliding_attention", "full_attention", "sliding_attention", "sliding_attention", "sliding_attention", "full_attention", "sliding_attention", "sliding_attention", "sliding_attention", "full_attention" ], "max_position_embeddings": 16384, "model_type": "gemma4_text", "moe_intermediate_size": null, "num_attention_heads": 10, "num_experts": null, "num_hidden_layers": 12, "num_key_value_heads": 2, "num_kv_shared_layers": 0, "pad_token_id": 0, "per_layer_config": { "03": { "head_dim": 128 }, "07": { "head_dim": 128 }, "11": { "head_dim": 128 } }, "rms_norm_eps": 1e-06, "rope_parameters": { "full_attention": { "partial_rotary_factor": 1.0, "rope_theta": 1000000.0, "rope_type": "proportional" }, "sliding_attention": { "rope_theta": 10000.0, "rope_type": "default" } }, "sliding_window": 512, "tie_word_embeddings": true, "top_k_experts": null, "transformers_version": "5.18.0", "use_bidirectional_attention": null, "use_cache": true, "use_double_wide_mlp": false, "vocab_size": 32768, "vocab_size_per_layer_input": 32768}123456789{ "bos_token_id": 2, "pad_token_id": 0, "eos_token_id": [ 1, 6, 11 ]}123version https://git-lfs.github.com/spec/v1oid sha256:24c02955743f5b918dff4e8709075ac7d9a05255739545ce1543ae10e72c8349size 18948444812345678910111213141516171819202122232425{ "tokenizer_class": "PreTrainedTokenizerFast", "bos_token": "<bos>", "eos_token": "<eos>", "pad_token": "<pad>", "unk_token": "<unk>", "mask_token": "<mask>", "add_bos_token": true, "add_eos_token": false, "model_max_length": 16384, "padding_side": "left", "clean_up_tokenization_spaces": false, "sot_token": "<|turn>", "eot_token": "<turn|>", "std_token": "<|tool>", "etd_token": "<tool|>", "stc_token": "<|tool_call>", "etc_token": "<tool_call|>", "str_token": "<|tool_response>", "etr_token": "<tool_response|>", "escape_token": "<|\"|>", "think_token": "<|think|>", "soc_token": "<|channel>", "eoc_token": "<channel|>"}.gitattributes+1
README.mdAdded+214
assets/compare.pngAdded

assets/tries.pngAdded

Large File Pointer Details
- SHA256: 913c29a0ca45ed4579e9f184119fad8d3e9081e827f4640fb48f7e3deb26d2c4
- Pointer size: 131 Bytes
- Size of remote file: 142 kB
config.jsonAdded+74
generation_config.jsonAdded+9
model.safetensorsAdded+3
tokenizer.jsonAdded
tokenizer_config.jsonAdded+25