[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-111298":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":8,"htmlUrl":8,"language":9,"languages":8,"totalLinesOfCode":8,"stars":10,"forks":11,"watchers":12,"openIssues":11,"contributorsCount":11,"subscribersCount":11,"size":11,"stars1d":11,"stars7d":13,"stars30d":14,"stars90d":11,"forks30d":11,"starsTrendScore":11,"compositeScore":15,"rankGlobal":8,"rankLanguage":8,"license":16,"archived":17,"fork":17,"defaultBranch":18,"hasWiki":19,"hasPages":17,"topics":20,"createdAt":8,"pushedAt":21,"updatedAt":22,"readmeContent":23,"aiSummary":24,"trendingCount":11,"starSnapshotCount":11,"syncStatus":12,"lastSyncTime":25,"discoverSource":26},111298,"TrainPilot","linee64\u002FTrainPilot","linee64",null,"Python",62,0,2,1,3,37.8,"MIT License",false,"main",true,[],"2026-11-02 07:41:54","2026-11-16 20:29:05","# TrainPilot\n\n[![Python 3.10+](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fpython-3.10+-blue.svg)](https:\u002F\u002Fwww.python.org\u002Fdownloads\u002F)\n[![PyTorch](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FPyTorch-2.x-ee4c2c.svg)](https:\u002F\u002Fpytorch.org\u002F)\n[![License: MIT](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FLicense-MIT-green.svg)](LICENSE)\n\nTrainPilot finds out why your PyTorch training is slow on free Colab\u002FKaggle GPUs and gives you a ready-to-paste fix.\n\n[![Open In Colab](https:\u002F\u002Fcolab.research.google.com\u002Fassets\u002Fcolab-badge.svg)](https:\u002F\u002Fcolab.research.google.com\u002Fgithub\u002Flinee64\u002FTrainPilot\u002Fblob\u002Fmain\u002Fnotebooks\u002Ftrainpilot_quickstart.ipynb)\n\n## Why\n\nOn a free T4, a training step is often slow for one of two reasons: the GPU is waiting for the next batch, or it is busy doing heavy math. Students usually cannot tell which, so they turn on mixed precision or `torch.compile` and hope. TrainPilot measures a short run, names the cause, and only suggests a change that made *this* short test faster without blowing up the loss.\n\n## What it does\n\n- Splits each step into data wait vs compute, then says **waiting for data** or **GPU busy**.\n- Tries mixed precision (FP16 + `GradScaler`; never BF16 on a T4).\n- Optionally tries `torch.compile` on top of AMP, with prepare time counted separately and payback in steps.\n- Checks that loss did not diverge and there are no NaN. That is not a claim that model quality is unchanged.\n- Writes a one-page report and a short snippet. **It never edits your script.**\n\nWarmup steps (default 10) are dropped. Stats use the median of the next 30 steps. Baseline and experiment share the same seed and the same batches. Without a GPU the report says `GPU not found` and does not crash.\n\n## Quick start\n\n```bash\npip install git+https:\u002F\u002Fgithub.com\u002Flinee64\u002FTrainPilot.git\n```\n\nYour script must call `measure_batches` and `compare_mixed_precision`; `trainpilot run` runs it and saves the report to `trainpilot-report.md`.\n\n```python\n# train.py\nimport torch\nfrom torch import nn\nfrom trainpilot import compare_mixed_precision, diagnose, measure_batches, render_report\n\ndevice = \"cuda\" if torch.cuda.is_available() else \"cpu\"\ntorch.manual_seed(0)\n\ndef make_loader():\n    data = torch.utils.data.TensorDataset(\n        torch.randn(1280, 3, 32, 32),\n        torch.randint(0, 10, (1280,)),\n    )\n    return torch.utils.data.DataLoader(data, batch_size=32, num_workers=0)\n\nmodel = nn.Sequential(\n    nn.Conv2d(3, 32, 3, padding=1), nn.ReLU(),\n    nn.AdaptiveAvgPool2d(1), nn.Flatten(), nn.Linear(32, 10),\n).to(device)\noptimizer = torch.optim.SGD(model.parameters(), lr=0.05)\nce = nn.CrossEntropyLoss()\n\ndef step(batch):\n    x, y = batch[0].to(device), batch[1].to(device)\n    optimizer.zero_grad(set_to_none=True)\n    loss = ce(model(x), y)\n    loss.backward()\n    optimizer.step()\n    return int(x.shape[0])\n\ndef loss_fn(candidate, batch):\n    x, y = batch[0].to(device), batch[1].to(device)\n    return ce(candidate(x), y)\n\ndiagnosis = diagnose(measure_batches(make_loader(), step))\nexperiment = compare_mixed_precision(model, optimizer, make_loader(), loss_fn, seed=0)\nprint(render_report(diagnosis, experiment))\n```\n\n```bash\ntrainpilot run train.py\ntrainpilot run train.py --compile\n```\n\n`step(batch)` runs one training step and returns the example count. `loss_fn(model, batch)` must use the model it is given and return a scalar loss. `--compile` is passed through to `try_compile`. If the script already prints `render_report`, the CLI does not print it again.\n\n## Example report\n\n```\nThe GPU is busy computing. It is not sitting idle.\n\nOn this short run, 0.2% of a typical step is spent waiting for the next\nbatch. The GPU is busy computing the rest.\n\n## What we tried\n\nMixed precision (FP16) made a typical step faster on this short test:\n310.4 ms down to 96.3 ms. That is about 3.22 times faster.\nA busy GPU can still be busy with slow math. This short test found a\nfaster step, so that is the change to paste.\nLoss did not diverge and there are no NaN.\n\n## Code to paste\n\nscaler = torch.amp.GradScaler(\"cuda\")\nwith torch.autocast(device_type=\"cuda\", dtype=torch.float16):\n    loss = loss_fn(model(inputs), targets)\nscaler.scale(loss).backward()\nscaler.step(optimizer); scaler.update()\n```\n\nThese numbers are from a short test. A full training run is only an estimate.\n\n## Real results on a T4 (Colab)\n\n![FP32 vs AMP median step time on a Tesla T4](docs\u002Ft4_results.png)\n\n| Workload | Verdict | Data wait | FP32 step | AMP step | Speedup |\n|---|---|---|---|---|---|\n| CIFAR-10 ResNet-18 | GPU busy | 0.3% | 116.8 ms | 46.8 ms | 2.5x |\n| DistilBERT IMDB | GPU busy | 0.2% | 310.4 ms | 96.3 ms | 3.22x |\n| nanoGPT Shakespeare | GPU busy | 0.5% | 182.0 ms | 55.2 ms | 3.3x |\n| nanoGPT + torch.compile | GPU busy | 0.5% | 55.2 ms (AMP) | 47.8 ms | 1.15x, prepare 27.2 s, pays off after ~3674 steps |\n| Heavy augmentation, workers=2 | Waiting for data | 75.8% | 64.1 ms | 35.0 ms | loader is the bottleneck |\n| Script already using AMP | GPU busy | 0.0% | 24.5 ms | 25.5 ms | no change suggested |\n\nShort runs (10 warmup + 30 measured steps), numbers vary run to run.\n\n## What it does not do (v0.1)\n\n- One NVIDIA GPU. No multi-GPU or distributed training.\n- It does not patch your script, tune batch size, or touch memory settings.\n- \"Training did not break\" only means the short test did not blow up (no diverged loss, no NaN).\n- It does not promise a speedup percentage. The table above is one Colab T4 run.\n\nOn notebooks it never suggests more than two DataLoader workers. If `num_workers=2` and `pin_memory` are already set, it says so and tells you to make loading cheaper instead.\n\n## How it differs from torch.profiler \u002F TensorBoard\n\n- A profiler shows a trace. TrainPilot answers one question: is the GPU waiting or working, and did one safe change help on this short run?\n- Before and after use the same seed and the same batches, so the step-time comparison is fair.\n- You paste the snippet yourself. TrainPilot does not rewrite the training loop.\n\n## Roadmap\n\nv0.1 is diagnosis, mixed precision, and optional `torch.compile`. Not in this version: auto-patching, batch-size search, multi-GPU.\n\n## Contributing\n\n```bash\npip install -e \".[dev]\"\npytest\n```\n\nGPU tests skip when CUDA is not available. Keep the public API (`measure_batches`, `diagnose`, `compare_mixed_precision`, `render_report`) unless a change is required. Do not edit the reference scripts in `examples\u002F`. Layout and expected T4 results: `docs\u002FARCHITECTURE.md`, `docs\u002FTESTING.md`.\n\n## License\n\nMIT\n","TrainPilot 是一个专为 PyTorch 深度学习训练性能诊断与优化设计的轻量级工具，面向免费 GPU 环境（如 Colab\u002FKaggle T4）。它通过短时采样（默认 30 步中位数统计）精准区分训练瓶颈是数据加载延迟（GPU 等待 batch）还是计算密集（GPU 忙于前向\u002F反向），并针对性验证混合精度（FP16 + GradScaler）或 torch.compile 的实际加速效果；所有实验严格复现相同随机种子与数据批次，确保 loss 不发散、无 NaN，并生成可读报告与可粘贴代码片段，不修改用户原有脚本。适用于学生、初学者及快速原型开发者在资源受限环境下进行高效训练调优。","2026-11-24 04:40:45","CREATED_QUERY"]