r/Python • u/AutoModerator • 21d ago
Showcase Showcase Thread
Post all of your code/projects/showcases/AI slop here.
Recycles once a month.
28
Upvotes
r/Python • u/AutoModerator • 21d ago
Post all of your code/projects/showcases/AI slop here.
Recycles once a month.
View all comments
2
u/Possible-Active-1903 21d ago
What My Project Does
trainlint reads Python files that train or evaluate ML models and points out bugs that run without errors and still give you a believable number. Examples: a scaler or feature selector fitted before the train/test split, model.eval() left on or never called, softmax in front of CrossEntropyLoss, y_true and y_pred swapped. There are 14 rules in total. It parses the file with the ast module and never runs your code. Standard library only, Python 3.10+.
Here is the demo. 100 samples, 5,000 random features, random labels, so nothing can beat 50%. If I pick the best 20 features on the whole dataset and then cross-validate, I get 85%. If the same selection happens inside a Pipeline, I get 48%. trainlint flags the first script.
Target Audience
Anyone who writes PyTorch or scikit-learn training code, and CI jobs that check it. It is Beta: 14 rules, all heuristics, two releases so far.
Comparison
ruff and pylint have no rules about splits, eval mode or metrics. TorchFix looks for removed and deprecated PyTorch APIs. Deepchecks runs checks against your real data and models. trainlint only reads the source, so it needs no data or GPU, and it covers far less.
Limits
It goes by names like X_train and val_loader, reads one file at a time and has no type information, so it will get some things wrong. To get an outside check I ran it over the 93 files of pytorch/examples at a pinned commit and read every finding. There were 22: 20 real by my reading and 2 harmless. The README has the commands if you want to repeat it.
Repo: https://github.com/Satvik-jain/trainlint
Every rule with a flagged and a clean example: https://github.com/Satvik-jain/trainlint/blob/main/docs/rules.md
If it flags something it should not, or misses a bug you have hit, please open an issue with the snippet. That is the feedback I want most.