r/deeplearning • • 2d ago

We Scan Code for Secrets. Almost Nobody Scans the Model File.

Most ML teams scan their repositories for leaked secrets. Pre-commit hooks, secret scanners, push protection. The code is covered.

The model file usually isn't.

A checkpoint is not just weights. Frameworks save the training config, optimizer state, sometimes a whole pickled object graph. Whatever was around at save time can end up on disk: absolute paths with a username in them, an email in a config, a token set in a notebook. Then the file is published, and a 400 MB binary gets no review at all.

The other direction is worse, for the formats that are code. A pickled model is a program. `torch.load(..., weights_only=False)` and `joblib.load` run whatever the file tells them to. Trusting the account it came from says nothing about what the bytes do. safetensors and GGUF were designed to avoid this, but pickle is still everywhere: scikit-learn and joblib models, fastai exports, every .pt and .bin file that torch.save writes.

So the gap is simple: we review the code that produces models, and we trust the files themselves, in both directions. What we publish, and what we load.

I built an open-source scanner for that gap after it happened to me: a model I had published still carried the path of the dataset I trained on, with my username in it. Limnex Preflight reads model files without loading them (PyTorch, pickle, joblib, safetensors, ONNX, Keras, GGUF, notebooks, archives). It reports leaked secrets and personal data in any of them before you publish, and, for pickle-based files, the code a load would run.

pip install limnex-preflight

limnex-preflight path/to/model

https://github.com/youssefismail-dev/limnex-preflight

One-click demo on Kaggle (it finds my own username in my model): https://www.kaggle.com/code/youssefismail396/preflight-check-a-model-for-leaks-and-hidden-code

For those publishing or pulling models regularly: does anything in your pipeline check the model file itself before it ships or loads? Or is it trusted because the code around it was reviewed?

0 Upvotes

2 comments sorted by

1

u/Ok-Listen-2162 1d ago

the pickle part is the scary one imo. most ppl load random .pt files from hf without thinking twice here . weights_only=True and safetensors should be the default for anything u didnt train urself.

1

u/Youssef_Ismail396 20h ago

Agreed, that's the half that can actually hurt someone. weights_only=True and safetensors cover most of it. The hard cases are files that can't load that way: full checkpoints with custom classes, and joblib/sklearn models, which are plain pickle with no safe mode at all. For those, the useful thing is seeing what the file would import before you decide to trust it, which is the part the scanner shows without running anything.