~/fba-lab/lab/speedrun/journey/trace-datagen-lab

FBALab

Code · architecture · study mode

AboutRoadmapSpeedrun
FBALab

Study mode — no GPU required.

Interactive LLM training & inference lab.

Qwen CAboutContactTermsPrivacyCookiesCommunity

© 2026 FBA Lab

Contact · contact@bubblspace.com · +91 75061 55016

Speedrun›Profiler deep-dive›Datagen Lab
Act 1Model Training FundamentalsAct 2AI Systems OptimizationAct 3World-Record Training Optimization
Step 14 of 28Skill: AI Systems Optimization
← 03 · Data Generator04 · torch.compile →
TRAINING SIMULATION

Datagen Lab

running
◷train_gpt.py▸distributed_data_generator◎learner$no GPU
1/2
Blocks
Quick summary

Python generator that reads FineWeb .bin shards, splits across 8 DDP ranks (each rank sees unique tokens), optionally…

Full explanation below the code →

fba-lab — train_gpt.py · distributed_data_generatorexecuting
// block: distributed_data_generator · lines 1420–1490$ study train_gpt.py --block distributed-data-generatorPython generator that reads FineWeb .bin shards, splits across 8 DDP ranks (each rank sees unique to… ✓
Explanation

Python generator that reads FineWeb .bin shards, splits across 8 DDP ranks (each rank sees unique tokens), optionally aligns to BOS boundaries, and yields 4 CUDA tensors per step: inputs, targets, cum_lengths, bigram_inputs.

Think about

Why must DDP ranks see different tokens rather than the same tokens shuffled differently?

// architecture

Live diagram

100%
03 · train_gpt.py line 1420
distributed_data_generator

DDP-aware infinite data loader with BOS alignment

A Python generator that reads FineWeb .bin shards from disk, splits the data across 8 GPUs so each sees unique tokens, optionally aligns sequences to document starts (BOS token = 50256), and yields 4 CUDA tensors per training step.

FineWeb .bin shards 10B tokens BOSFinder scan for tok=50256 → BOS index array quickload: async thread DataPreloader background thread prefetches next shard next_batch() pick BOS-aligned spans split → 8 ranks yield 4 CUDA tensors _inputs (int32) _targets (int64) _cum_lengths (int32) _bigram_inputs (int32) 8 GPU workers rank 0 rank 1..6 rank 7 align_to_bos=True (training): sequences start at BOS boundaries. align_to_bos=False (validation): contiguous streaming.
The 4 tensors yielded per step
  • _inputs (int32) — input token IDs for this rank's slice
  • _targets (int64) — shifted-by-1 labels for next-token loss
  • _cum_lengths (int32) — cumulative doc boundaries (for varlen flash attention)
  • _bigram_inputs (int32) — hashed bigram indices from get_bigram_hash