karpathy/nanochat

The best ChatGPT that $100 can buy.

Python★ 60,004+321 that day#7 on trending

Analyzed November 3, 2026 at 92d63d4 (master) with jscpd v5 in 1.1s.

D42.6/100
Project health8,159 lines of code (S)
Duplication84
1.7% in python, bash
Dead 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

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
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_init
    

    First 10 of 16 lines.

  • 7 lines in 3 placespythontests105 tokens
    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.8972
    
    517Chinchilla-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
FormatFilesLinesClonesDuplicated linesDuplication
python296,7157741.1%
bash43841102.6%
By format, all files
FormatFilesLinesClonesDuplicated linesDuplication
python367,810141311.68%
text318474323.37%
bash53921102.55%
markdown41,561000%
toml169000%

Trending appearances

DayRankStarsFilesLinesClonesAll filesCodeHealthCommit
Nov 3, 2026#760,004 (+321)4910,016221.84%1.18%D 42.692d63d4

Want this for your own project? Install jscpd and run jscpd ., or measure it the way the baselines were measured.