Skip to content

Nanotron - Minimalistic 3D-Parallel LLM Training Cheatsheet

Nanotron - Minimalistic 3D-Parallel LLM Training Cheatsheet

Nanotron (by Hugging Face) is a minimalistic framework for pretraining large language models with 3D parallelism — data, tensor, and pipeline parallel — implemented in deliberately readable Python. Its goal is to be small and hackable enough to actually understand, while still distributing training across many GPUs. It is a strong choice when you want to learn or customize the mechanics of distributed pretraining without the complexity of the largest frameworks.

Pretraining is compute-heavy; start small. Validate a config on a tiny model and a couple of GPUs before scaling.

Installation

MethodCommand
From sourcegit clone https://github.com/huggingface/nanotron && cd nanotron && pip install -e .
Flash attentionpip install flash-attn (recommended)
RequirementsPyTorch + CUDA GPUs
Verifyrun an example config on 1–2 GPUs

3D Parallelism

DimensionSplitsConfig key
Data Parallel (DP)The batch across replicasdp
Tensor Parallel (TP)Layers across GPUstp
Pipeline Parallel (PP)The model into stagespp

The product dp × tp × pp must equal your total GPU count.

Configuration (YAML)

Nanotron training is defined by a YAML config describing the model, data, parallelism, and optimizer.

parallelism:
  dp: 2
  tp: 2
  pp: 2
  pp_engine: 1f1b        # pipeline schedule

model:
  model_config:
    hidden_size: 2048
    num_hidden_layers: 24
    num_attention_heads: 16

optimizer:
  learning_rate_scheduler:
    learning_rate: 3.0e-4
  optimizer_factory:
    adam_beta1: 0.9
    adam_beta2: 0.95

tokens:
  sequence_length: 2048
  micro_batch_size: 4
  batch_accumulation_per_replica: 8

Launching Training

# Single node, multiple GPUs
torchrun --nproc_per_node=8 run_train.py --config-file config.yaml

# Generate a starter config
python examples/config_tiny_llama.py
KeyMeaning
run_train.pyMain training entrypoint
--config-fileThe YAML training config
pp_enginePipeline schedule (e.g. 1F1B, AFAB)
micro_batch_sizePer-step micro batch
batch_accumulation_per_replicaGradient accumulation

Data

OptionNote
Pretokenized datasetsPoint config at tokenized data
HF datasetsStream/loads via Hugging Face
NanosetNanotron’s efficient dataset format
TokenizerSet via the tokenizer config

Checkpoints & Resume

AspectHow
Save frequencycheckpoints.checkpoint_interval
Save pathcheckpoints.checkpoints_path
Resume--config-file + point at a saved checkpoint
ShardedCheckpoints are parallelism-aware

Monitoring

MetricMeaning
loss / lm_lossTraining loss
tokens/sThroughput
grad normGradient magnitude (stability)
LoggingW&B / TensorBoard integration

Nanotron vs Other Training Frameworks

AspectNanotronTorchTitanMegatron-LM
PhilosophyMinimal, hackablePyTorch-native referenceFeature-rich, max-scale
Parallelism3D (dp/tp/pp)4D (adds context)3D+ extensive
ReadabilityHigh (learn from it)HighLower (large codebase)
Best forUnderstanding/customizing 3DNative PyTorch scalingFrontier-scale training

Resources