ml-debugging
Skill11 starsChanged 6 months agoMITView on GitHub
Use when a model won't learn, loss is NaN, metrics look too good/bad, or training is unstable. Provides a systematic decision tree for diagnosing data, optimization, and generalization failures.
In this repository14 other files it gives its agents.
- data-cleaningSkill
- experiment-trackingSkill
- exploratory-data-analysisSkill
- feature-engineeringSkill
- hyperparameter-tuningSkill
- imbalanced-dataSkill
- llm-finetuningSkill
- model-evaluationSkill
- model-servingSkill
- pandas-patternsSkill
- pytorch-training-loopSkill
- rag-pipelineSkill
- reproducible-mlSkill
- sklearn-pipelinesSkill
The file
We split this skill into the rules it gives an agent
4 rules. About 0 are common, 4 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 49
Do rows from one entity span train and test?
- Distinctive: line 57
Add gradient clipping for RNNs/transformers.
- Distinctive: line 58
Check for NaNs in inputs/targets before training.
- Distinctive: line 59
Verify loss matches task (CE for classification logits, not MSE).
≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
ML Debugging
Overview
ML bugs are usually silent — the code runs, but the model is wrong. Debug systematically by isolating which layer is broken: data, optimization, or generalization. Form a hypothesis, test it with the cheapest possible experiment, then move on.
When to use
- Loss is NaN/Inf or stuck.
- Metrics are implausibly high (leakage) or stuck at chance.
- Train/val curves diverge.
First move: can it overfit one batch?
The fastest sanity check in ML. Take a single small batch and train until loss ≈ 0.
x, y = next(iter(train_loader))
for _ in range(200):
optimizer.zero_grad()
loss = criterion(model(x), y)
loss.backward(); optimizer.step()
print(loss.item()) # should approach 0- Can't overfit one batch → bug in model/loss/labels/data wiring (not capacity).
- Overfits one batch but not the dataset → optimization or regularization issue.
Symptom → cause decision tree
| Symptom | Likely cause | Fix |
| Loss = NaN | LR too high; log(0); /0; bad input scaling | Lower LR, clip grads, add eps, normalize inputs |
| Loss flat at start | LR too low; dead ReLUs; wrong loss | Raise LR; check init; verify loss/target shapes |
| Train great, val terrible | Overfitting or leakage | Regularize/augment; audit for leakage |
| Val better than train | Leakage; val too easy; dropout-at-train artifact | Re-check split; inspect val set |
| Metric implausibly high | Target leakage | Hunt leaked features (see EDA skill) |
| Stuck at chance | Labels misaligned; data not shuffled; LR off | Verify label mapping; shuffle; sweep LR |
Leakage hunt (when results are "too good")
- Any feature with |corr| ≈ 1.0 to target?
- Is preprocessing fit before the split?
- Do rows from one entity span train and test? (use GroupKFold)
- Time series shuffled? (must be chronological)
- Is a post-outcome column (e.g.,
refund_issued) used to predict the outcome?
Optimization checklist
- Normalize/standardize inputs.
- Sweep LR over
[1e-5 ... 1e-1](log scale) — wrong LR causes most failures. - Add gradient clipping for RNNs/transformers.
- Check for NaNs in inputs/targets before training.
- Verify loss matches task (CE for classification logits, not MSE).
Pitfalls
- Changing five things at once — change one variable per experiment.
- Debugging on the full dataset — shrink to fail fast.
- Trusting metrics without inspecting predictions/confusion matrix.
Hand-off
A root-caused fix plus a regression check (the one-batch test + a held-out metric) so experiment-tracking can confirm the issue stays fixed.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

