karpathy/nanochat
The best ChatGPT that $100 can buy.
Python★ 60,004+321 that day#7 on trending
D42.6/100
Duplication84
1.7% in python, bashDead code12
28%Complexity72
24.6% The score is jscpd's own --health model: markup, data and text left out, tests kept. The numbers below are the trending scan's.
1.18%duplicated code · 84 of 7,099 lines
8clones in code
33code files of 49 scanned
1.84%duplicated over all files · 22 clones
Most complex files
- scripts/base_train.py90 cx
- nanochat/gpt.py76 cx
- scripts/chat_sft.py76 cx
- nanochat/engine.py63 cx
- nanochat/common.py49 cx
- nanochat/tokenizer.py49 cx
- nanochat/optim.py46 cx
- nanochat/core_eval.py43 cx
- nanochat/checkpoint_manager.py38 cx
- tasks/common.py36 cx
Dead code 28% unused · 11 findings
- scripts/base_train.pyunused-file
- scripts/chat_sft.pyunused-file
- scripts/chat_rl.pyunused-file
- nanochat/fp8.pyunused-file
- scripts/tok_eval.pyunused-file
- scripts/chat_cli.pyunused-file
- scripts/tok_train.pyunused-file
- tasks/smoltalk.pyunused-file
- nanochat/gpt.py:partialunused-import
- nanochat/gpt.py:get_dist_infounused-import
The code number leaves out tests, fixtures, docs, examples, data files, styles, translations and vendored code.
Largest clones in the code
- 8 lines in 2 placespython86 tokens
67# Aggregate results across all ranks 68if ddp: 69 num_passed_tensor = torch.tensor([num_passed], dtype=torch.long, device=device) 70 total_tensor = torch.tensor([total], dtype=torch.long, device=device) 71 dist.all_reduce(num_passed_tensor, op=dist.ReduceOp.SUM) 72 dist.all_reduce(total_tensor, op=dist.ReduceOp.SUM) 73 num_passed = num_passed_tensor.item() 74 total = total_tensor.item() - 8 lines in 2 placespython76 tokens
32parser = argparse.ArgumentParser(description="Reinforcement learning on GSM8K") 33# Logging 34parser.add_argument("--run", type=str, default="dummy", help="wandb run name ('dummy' disables wandb logging)") 35# Runtime 36parser.add_argument("--device-type", type=str, default="", help="cuda|cpu|mps (empty = autodetect)") 37# Model loading 38parser.add_argument("--model-tag", type=str, default=None, help="model tag to load from") 39parser.add_argument("--model-step", type=int, default=None, help="model step to load from") - 10 lines in 2 placesbash73 tokens
72 --model-tag="${TAG}" \ 73 --core-metric-every=999999 \ 74 --core-metric-max-per-task=-1 \ 75 --sample-every=-1 \ 76 --save-every=-1 \ 77 $DEVICE_BATCH_SIZE_ARG \ 78 2>&1 | tee "$RESULTS_DIR/${TAG}_train.log" 79 80END_TIME=$(date +%s) 81TRAIN_TIME=$((END_TIME - START_TIME))
5 more
- 17 lines in 2 placespython73 tokens
- 8 lines in 2 placespython68 tokens
- 13 lines in 2 placespython66 tokens
- 8 lines in 2 placespython59 tokens
- 12 lines in 2 placespython50 tokens
Largest clones over all files, tests and data included
- 16 lines in 2 placespythontests268 tokens
160k_init = torch.randn(B, T_prefill, H, D, device=self.DEVICE, dtype=self.DTYPE) 161v_init = torch.randn(B, T_prefill, H, D, device=self.DEVICE, dtype=self.DTYPE) 162q_single = torch.randn(B, 1, H, D, device=self.DEVICE, dtype=self.DTYPE) 163k_single = torch.randn(B, 1, H, D, device=self.DEVICE, dtype=self.DTYPE) 164v_single = torch.randn(B, 1, H, D, device=self.DEVICE, dtype=self.DTYPE) 165 166def run(): 167 k_cache = torch.zeros(B, T_max, H, D, device=self.DEVICE, dtype=self.DTYPE) 168 v_cache = torch.zeros(B, T_max, H, D, device=self.DEVICE, dtype=self.DTYPE) 169 k_cache[:, :T_prefill, :, :] = k_initFirst 10 of 16 lines.
- 7 lines in 3 placespythontests105 tokenstests/test_attention_fallback.py:60–66tests/test_attention_fallback.py:74–80tests/test_attention_fallback.py:89–95
60B, T, H, D = 2, 64, 4, 32 61q = torch.randn(B, T, H, D, device=self.DEVICE, dtype=self.DTYPE) 62k = torch.randn(B, T, H, D, device=self.DEVICE, dtype=self.DTYPE) 63v = torch.randn(B, T, H, D, device=self.DEVICE, dtype=self.DTYPE) 64 65def run(): 66 return flash_attn.flash_attn_func(q, k, v, causal=True, window_size=(T, 0))74B, T, H, D = 2, 128, 4, 32 75q = torch.randn(B, T, H, D, device=self.DEVICE, dtype=self.DTYPE) 76k = torch.randn(B, T, H, D, device=self.DEVICE, dtype=self.DTYPE) 77v = torch.randn(B, T, H, D, device=self.DEVICE, dtype=self.DTYPE) 78 79def run(): 80 return flash_attn.flash_attn_func(q, k, v, causal=True, window_size=(-1, -1)) - 6 lines in 3 placestextdocs and examples85 tokens
505Kaplan-style (all projections including lm_head and no embeddings) 506 507Optimal configurations (from quadratic fits): 508FLOPs Eff Params Tokens Ratio Val BPB 509----------------------------------------------------------------- 5101e+18 110,678,115 1,241,505,403 11.2 0.8972517Chinchilla-style (all parameters, period.) 518 519Optimal configurations (from quadratic fits): 520FLOPs Eff Params Tokens Ratio Val BPB 521----------------------------------------------------------------- 5221e+18 416,320,605 1,232,157,011 3.0 0.8974 - 6 lines in 2 placespythontests101 tokens
- 8 lines in 2 placespython86 tokens
By format, code only
| Format | Files | Lines | Clones | Duplicated lines | Duplication |
|---|---|---|---|---|---|
| python | 29 | 6,715 | 7 | 74 | 1.1% |
| bash | 4 | 384 | 1 | 10 | 2.6% |
By format, all files
| Format | Files | Lines | Clones | Duplicated lines | Duplication |
|---|---|---|---|---|---|
| python | 36 | 7,810 | 14 | 131 | 1.68% |
| text | 3 | 184 | 7 | 43 | 23.37% |
| bash | 5 | 392 | 1 | 10 | 2.55% |
| markdown | 4 | 1,561 | 0 | 0 | 0% |
| toml | 1 | 69 | 0 | 0 | 0% |
Trending appearances
| Day | Rank | Stars | Files | Lines | Clones | All files | Code | Health | Commit |
|---|---|---|---|---|---|---|---|---|---|
| Nov 3, 2026 | #7 | 60,004 (+321) | 49 | 10,016 | 22 | 1.84% | 1.18% | D 42.6 | 92d63d4 |
Want this for your own project? Install jscpd and run jscpd ., or measure it the way the baselines were measured.