Instructions to use lewtun/riemann-nano with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use lewtun/riemann-nano with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="lewtun/riemann-nano", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("lewtun/riemann-nano", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use lewtun/riemann-nano with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "lewtun/riemann-nano" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "lewtun/riemann-nano", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/lewtun/riemann-nano
- SGLang
How to use lewtun/riemann-nano 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 "lewtun/riemann-nano" \ --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": "lewtun/riemann-nano", "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 "lewtun/riemann-nano" \ --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": "lewtun/riemann-nano", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use lewtun/riemann-nano with Docker Model Runner:
docker model run hf.co/lewtun/riemann-nano
riemann-nano
riemann-nano is a small language model trained on one document: the Lean 4 formalization of the proof of the Riemann Hypothesis, released by Levent AlpΓΆge in November 2026. The proof runs to 175,000 files and about 300 million tokens. That's enough to train a language model on, and to ask how big that model should be.
To answer that, we trained about 60 nanochat models at six compute budgets and fitted a scaling law in the style of Chinchilla. We then used the law to predict the compute-optimal model size at a larger budget, 1017 FLOPs, and trained that model. That model is riemann-nano: a 7-layer transformer with 61M parameters. Every model in the sweep, riemann-nano included, was trained on Hugging Face Jobs; riemann-nano itself took one H200.
The prediction holds up: in a sweep at 1017 FLOPs, riemann-nano is within noise of the best model of any size.
Samples
Part of the fun of a model trained on a single corpus is seeing what it picks up. Here's riemann-nano, and two smaller models from the scaling sweep, finishing the same prompts.
Watching it learn
Prompt: /-- The completed Riemann zeta function. -/ def
With 100Γ less compute than riemann-nano, the model has worked out that Lean is full of integers:
def (Ξ : Submodule β€ β€ β€ β€ β€ β€ β€ β€ β€ β€ β€ β€ β€ β€ β€ β€ β€ β€ β€ β€ β€ β€ β€ β€ β€ β€ β€ β€ β€ β€ β€ β€ β€ β€ β€ β€ β€ β€ β€ β€ β€ β€ β€ β€ β€ β€ β€
With 10Γ less, it knows a definition needs a name and a type, if not what goes in them:
def B/4 : β/4444444444444444444444444444445444444444445444455454444545444444454444444444554454544
riemann-nano writes a full definition, then closes a namespace it never opened:
def Basic : Prop := β (L : PeriodPair) (h : SCFTAll) (Ο : β β+ β), IsHomClass L Ο β IsCharClass L (h * Ο) β
β Ο : β β+* β, (β z, βΟ zβ = βzβ) β β (s : β) (a : β), 0 < a β (a : β) ^ 2 * Ο h = h * (s ^ 2 * Ο (h * Ο (Complex.I ^ a / s)))
end Formalism.HermitianLattices.Ext.L3
The same thing happens with proofs. Asked why ΞΆ(s) β 0 when Re s > 1, the smallest model reaches for simp and lists every lemma it knows: simp [zero_add, zero_add, add_zero, neg_zero, neg_zero, neg_zero, neg_zero]. riemann-nano writes a tidy proof, then moves on to the next lemma in the family. It mixes a lemma it invented with a real one, summable_geometric_of_lt_one, which the proof uses 173 times:
theorem riemannZeta_ne_one_of_one_lt_re {s : β} (hs : 1 < s.re) : riemannZeta s β 1 := by
have : 1 < s.re := hs
simp only [riemannZeta_eq_tsum_of_summable_norm summable_norm]
exact summable_geometric_of_lt_one (by linarith) (by linarith)
Analytic number theory, house style
Prompt: namespace RiemannHypothesis
namespace RiemannHypothesis
def gauss : β := Real.exp (-2 * Real.log 4)
def bnd : β := 2 * Real.log (2 * |2|) / 2
def bnd1 : β := 4 / 3
lemma gauss_nonneg : 0 β€ gauss := by unfold gauss; positivity
lemma gauss_pos : 0 < gauss := by unfold gauss; positivity
lemma gauss_pos1 : 0 < gauss := by
unfold gauss; positivity
lemma bnd1_pos : 0 < gauss := by
unfold gauss; positivity
Define a constant, prove it's positive, prove it again just in case, then prove it a third time under bnd1's name. The real proof calls positivity more than 45,000 times, and riemann-nano has picked up the habit.
A proof of the Riemann Hypothesis
Prompt: theorem riemannHypothesis : RiemannHypothesis := by
theorem riemannHypothesis : RiemannHypothesis := by
have h1 := riemannHypothesis
unfold RiemannHypothesis
exact mul_le_mul_of_nonneg_right (by norm_num) (by positivity)
theorem riemannHypothesis : RiemannHypothesis :=
riemannHypothesis
theorem riemannHypothesisE : RiemannHypothesisE := riemannHypothesis
theorem riemannHypothesisT : RiemannHypothesisT := riemannHypothesis
The most efficient proof possible: cite the theorem itself. Once it has one, it reuses it for the variants E and T.
Algebraic geometry on demand
Prompt: structure
structure IsRegularLocalRing (S : Type*) [CommRing S] [IsRegularLocalRing S]
[IsLocalRing S] [IsRegularLocalRing S] : Prop :=
ringKrullDim S = 1 β§ ringKrullDim S = 1 β§
ringKrullDim S = ringKrullDim (ResidueField S)
Krull dimensions, residue fields and the right typeclass brackets, all from a one-word prompt. It does assume the structure in its own definition, twice.
A little in-context learning
Show riemann-nano three worked examples, and it picks up the idea of finishing a simple goal with the right tactic:
-- the prompt: three examples
example : 8 ^ 2 + 15 ^ 2 = 17 ^ 2 := by norm_num
example : Nat.Prime 11 := by norm_num
theorem three_mul' (n : β) : 3 * n = n + n + n := by ring
-- riemann-nano's proofs, each checked by Lean β
example : 3 ^ 2 + 4 ^ 2 = 5 ^ 2 := by norm_num
example : Nat.Prime 13 := by norm_num
theorem two_mul' (n : β) : 2 * n = n + n := by ring
theorem sq_nonneg' (x : β) : 0 β€ x ^ 2 := by positivity
Asked for Nat.gcd 12 18 = 6, it reaches for BΓ©zout's identity and stops halfway. Asked to make up Pythagorean triples of its own, it's more creative than correct: 2 ^ 3 + 7 ^ 2 = 17 ^ 2.
Where everything lives
With no prompt at all, riemann-nano starts a file the way the proof does, with a wall of imports:
import Mathlib
import Development.AbelianVarietyTheory.Proofs.InertiaEigenvalues.UnipotentBlockColumnIndex
import Development.AbelianVarietyTheory.Proofs.InertiaEigenvalues.QuotientAveragePeriodicBoundedFreeStatement
import Development.AbelianVarietyTheory.Proofs.InertiaEigenvalues.QuotientAveragePeriodicRelationFamilyStatement
import Development.AbelianVarietyTheory.Proofs.InertiaEigenvalues.QuotientAverageBilinearEquivSymmContinuousStatement
Nearly half the proof lives under AbelianVarietyTheory/Proofs, so that's where it sends you first.
Usage
from transformers import AutoModelForCausalLM, AutoTokenizer
repo = "lewtun/riemann-nano"
tokenizer = AutoTokenizer.from_pretrained(repo, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(repo, trust_remote_code=True)
prompt = "theorem riemannHypothesis : RiemannHypothesis := by\n"
inputs = tokenizer(prompt, return_tensors="pt")
outputs = model.generate(**inputs, max_new_tokens=200, do_sample=True, temperature=0.8, top_k=50)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
You need transformers 5.24. The model uses custom code, so trust_remote_code=True is required for both the model and the tokenizer. The tokenizer adds a beginning-of-document token, and generation stops at <|eos|>.
Limitations
- Its proofs are unchecked. Treat its output as Lean-flavoured fiction until Lean accepts it.
- It is small and narrow. riemann-nano has only seen this one formalization and its Mathlib imports. It is not a general Lean assistant.
- It is a research artifact. It exists to test scaling-law predictions on a single, finite mathematical corpus. At larger budgets than this one, the 300M tokens have to be reused many times and the law above stops holding. The training code, data preparation and scaling analysis are on the
rhbranch of the nanochat fork.
Acknowledgements
Thanks to Ben Burtenshaw for the original idea of training a nanochat model on the Riemann Hypothesis proof.
- Downloads last month
- 97
