Concepts · Level 3 · Note 9

What is in a model file: weights, quantization, distillation and the risks

Weights, model file formats, quantization and distillation in plain words, then how model files are booby-trapped, backdoored, hijacked and copied, and what to check.

11 min read

Short answer

An AI model is a file of numbers called weights. Quantization rounds them so a 7B model fits on a laptop, and distillation trains a small model on a big one's answers. Each step is a place to attack. Older file formats can run code when loaded, and a scan of Hugging Face flagged 352,000 unsafe or suspicious issues across 51,700 models. ETH Zurich built models that pass tests at full precision and misbehave once quantized. Deleted publisher names can be re-registered. Use safetensors, pin the exact revision, verify hashes or signatures, and test the file you ship.

When you “download a model”, you download a file. Often it’s a copy that someone else shrank and uploaded under their own name. This note covers what is in that file, how it gets smaller, and where it can be tampered with on the way to you.

Weights, in plain words

Start with a sound-mixing desk that has billions of knobs. Training is the slow work of turning every knob until the output sounds right. Save the final knob positions to disk and you have a model file.

The positions are called weights, or parameters. “7B” means about seven billion of them. The label is rounded.

What the size label on a model means

7B7 billion weightssmallest Llama 2
13B13 billion weightsmiddle Llama 2
70B70 billion weightslargest Llama 2
Source: Touvron et al. (Meta), "Llama 2: Open Foundation and Fine-Tuned Chat Models", 2023.

Weights, technically

Each weight is one number. The standard type during training is a 32-bit floating-point value, and many released files already use 16-bit floats (the Transformers guide cited below lists float16 and bfloat16 next to float32). The label counts the numbers. From Meta’s Llama 2 paper: “We are releasing variants of Llama 2 with 7B, 13B, and 70B parameters.”

The count tells you how much memory you need. Our arithmetic: 7 billion weights at 4 bytes each is 28 GB before the model has read a single word. At 16 bits it is 14 GB.

Model files and hubs, in plain words

Think of two ways to send someone a bookshelf. One is a box of labeled planks with a parts list. The other is a set of instructions that a robot at the other end carries out, whatever they say. If the instructions include “then open the front door”, the robot opens it.

Older model files are the second kind. Newer ones are the first kind. A model hub is the marketplace where people post both. Hugging Face runs the one that the research below keeps returning to.

Animated: opening a model file: instructions or numbers

Pickle file (.bin, .pt)a list of instructionsrebuild the modelload the numbersrun this command
safetensors filedata onlyheader sizetable of contentsraw numbers
  1. Models come packed in different ways. A pickle file is a list of instructions for rebuilding the model. A safetensors file is a size field, a table of contents and the raw numbers.
  2. Loading a pickle file means running its instructions, one after another.
  3. Those instructions can import and call Python functions. So a file can carry an extra one that has nothing to do with the model.
  4. Load the file and that instruction runs on your machine. Researchers have found model files on a public hub that carried a payload like this.
  5. A safetensors file has no instructions in it to follow. The loader reads the table of contents and then the numbers.
  6. Data-only formats such as safetensors and GGUF remove the instructions. One risk stays: the program that reads the file can have bugs, so keep the loader patched.
Our animation of the file layouts in the Hugging Face and safetensors documentation.

Model files and hubs, technically

Pickle is Python’s way of saving objects. Hugging Face’s documentation calls it “the default format for PyTorch model weights” and describes the file as “a stack of instructions or opcodes”. Loading means running those instructions, and they can import and call Python functions. PyTorch has tightened its side: its serialization notes say “Starting in version 2.6, torch.load will use weights_only=True” by default, which restricts what the loader will run. The same page says this “narrows the surface of remote code execution attacks” and lists limits, so it is a smaller risk and not zero.

safetensors was built “to remove the need to use pickle”. Its layout is three parts: 8 bytes holding the header size, a JSON header, and then a “byte-buffer” of numbers. There are no instructions in it to follow. The reader is still a program, and a program can have bugs.

GGUF is, per the Transformers documentation, “a single-file format used to store models for inference with GGML, containing the model metadata and tensors.” It “supports many quantized data types”. The ETH Zurich follow-up paper cited under attack 2 describes it as the format family used by ollama and llama.cpp. GGUF holds no pickle, but its metadata is more than labels: it can carry a chat template that a template engine runs, as attack 1 shows.

The Hub stores models “in repositories”, each under a publisher’s name. Registering a name and uploading is open to anyone, as attack 3 shows.

Quantization, in plain words

A shop that prices everything to the paisa needs a long price list. Round every price to the nearest ten rupees and the list gets much shorter. Most totals come out close. A few come out wrong.

Quantization does that to the weights. Each number is stored with fewer digits, so the file shrinks.

Quantization, technically

The Transformers quantization guide defines it as representing weights “with lower-precision data types (like 8-bit integers or int8) instead of the standard 32-bit floating-point (float32).” An int8 model is “roughly 4 times smaller”, and 4-bit halves that again. A 4-bit weight can take only 16 values.

Animated: the same weights, stored with fewer bits

Four of the model's weights (example values)

Memory for the weights
Rounding error
most answers come out closea few come out wrong
many different values round to the same numberroom to hide a change
  1. A model file is a very long list of numbers called weights. The standard way stores each one with 32 bits.
  2. Quantization stores each number with fewer bits. At 8 bits the values are rounded and the model is roughly 4 times smaller.
  3. At 4 bits a weight can take only 16 values. The size halves again, which is how a large model fits on a laptop.
  4. The price is accuracy. Each rounded weight is a little off, and 4 bits typically costs more accuracy than 8.
  5. Most answers come out close to the original. A few come out wrong.
  6. The security catch: many different full-precision values round to the same small number. An attacker can hide a change inside that slack, so test the quantized file you ship.
Our animation of quantization as the Transformers quantization guide describes it. The weight values are examples and bar lengths are for illustration. The memory arithmetic is in the chart below.

Memory for the weights of a 7B model, by bits per weight

32-bit (standard)
28 GB
16-bit
14 GB
8-bit
7 GB
4-bit
3.5 GB
Our arithmetic: 7 billion weights times the bytes per weight, in decimal gigabytes. Real files are larger: they add metadata, and quantization schemes store scaling values and often keep some layers at higher precision.

The cost is accuracy. The same guide says lower precision “inevitably introduces small errors (quantization noise)” and that int4 “typically results in a larger accuracy drop compared to int8.” Attack 2 hides inside those small errors. Quantization also pairs with fine-tuning, which we covered under QLoRA in the LoRA note.

Distillation, in plain words

A junior cook doesn’t get the head chef’s thirty years. They stand beside the chef for a season, watch thousands of plates go out, and copy what they see. They end up cooking most of the menu nearly as well.

Distillation is that arrangement between two models. The big one is the teacher and the small one is the student.

Animated: a small model copies a big one's answers

a large set of inputs
Teacherlarge, already trainedits answers
Studentsmaller
How closely the student matches the teacher
needed: the teacher's answersnot needed: its weight file
a stranger asks your served model enough questionsand trains a copy
  1. Distillation uses two models. The teacher is large and already trained. The student is smaller.
  2. The teacher answers a large set of inputs.
  3. The student gets the same inputs. At first its answers are far from the teacher's.
  4. The student is trained to reproduce the teacher's behavior on those inputs.
  5. It ends up smaller and faster and keeps most of the skill. Look at what that took: the teacher's answers, and never its weight file.
  6. That is the catch. Anyone who can ask a model enough questions can try the same thing. Distillation is a widely used, legitimate method. If you serve a model, it is also how the model can be copied.
Our animation of distillation as the DistilBERT paper describes it. Bar lengths are for illustration. The paper's numbers are in the figure below.

Distillation: a small model learns from a big model's answers

1. TeacherA large trained model answers a large set of inputs
BERT
2. Answers become lessonsThe student is trained to reproduce the teacher's behavior on those inputs
teacher's outputs
3. StudentA smaller model that keeps most of the skill
40% smaller60% faster97% retained
Our illustration. The numbers are from Sanh et al. (Hugging Face), "DistilBERT", 2019.

Distillation, technically

The name comes from a 2015 paper by Hinton, Vinyals and Dean, “Distilling the Knowledge in a Neural Network”, which improved a speech recognition model by “distilling the knowledge in an ensemble of models into a single model”. The DistilBERT paper describes the method as one where “a compact model - the student - is trained to reproduce the behaviour of a larger model - the teacher”. Its result was to “reduce the size of a BERT model by 40%, while retaining 97% of its language understanding capabilities and being 60% faster”.

DistilBERT’s authors had the teacher’s weights as well. They write that “we initialize the student from the teacher by taking one layer out of two”, and one of their three training losses lines up the two models’ internal states.

Quantization needs the weight file. Distillation in its simplest form needs only the teacher’s answers, so anyone who can ask a model enough questions can try it.

Model cards, provenance and signing

A model card is the label on the tin. Hugging Face defines model cards as “files that accompany the models and provide handy information”, in practice the README.md of the repository. A base_model field says which model a fine-tune or a quantized copy came from. The publisher writes all of it. We found nothing in that documentation saying the Hub checks a card against the weights.

Provenance means being able to show where a file came from and that it hasn’t changed since. Pinning a repository revision to a specific commit gets you the exact files you reviewed. A signature goes further. Version 1.0 of the model-signing project was announced on 4 April 2025 on the Sigstore blog, in a post from Google’s Open Source Security Team. The work was done “in collaboration with OpenSSF, NVIDIA and HiddenLayer”. Signing records “a listing of hashes for every object in the model”. Verification recomputes them and checks that “the signature comes from a known or trusted identity”. It says who signed the bytes. It says nothing about whether the signer is honest or the model behaves.

What each piece of paperwork proves

1Model cardwhat the publisher says about the modela claim
2Hub malware scanno known-bad pattern was found in the filepartial
3Pinned revision or file hashthese are the same bytes you reviewedsame bytes
4Signaturesame bytes, and which identity signed thembytes + who
5What the weights were trained to donone of the above covers itnot proven
Our reading of the Hugging Face, Sigstore and model-signing documentation.

Attack 1: a model file that runs code when you open it

The Hugging Face documentation is blunt about pickle: “There are dangerous arbitrary code execution attacks that can be perpetrated when you load a pickle file.” We covered JFrog’s 2024 finding of about 100 malicious models in the LoRA note. Two later reports show how big the problem is and how a scanner was bypassed.

Protect AI’s Guardian scanner has checked models on the Hub since the two companies partnered in October 2024. Protect AI’s six-month update on the Hugging Face blog says that by 1 April 2025 it had scanned 4.47 million model versions in 1.41 million repositories. It had “identified a total of 352,000 unsafe/suspicious issues across 51,700 models.” The count is of issues, and one model can have several. The label is broad too: the post treats any way to run code as unsafe “regardless of intent”, so it is no count of malicious models.

In February 2025 ReversingLabs described two models on the Hub that carried a reverse shell, code that connects back to the attacker and gives them a command line, and were not flagged as unsafe. The files were packed with 7z instead of PyTorch’s usual ZIP, and the pickle stream broke shortly after the payload. The payload sat at the start, so it ran before the loader hit the break. ReversingLabs says the 7z packing is “likely the reason” the Hub’s scanner, Picklescan, did not flag them, and its own test showed the scanner could not properly scan a broken pickle file. ReversingLabs named the technique nullifAI and said the files “look more like a proof-of-concept”. Hugging Face removed them “in less than 24 hours” and changed its scanner.

Data-only formats remove the instructions, but the program that reads the file can still have bugs. In March 2024 Databricks published heap overflows, a kind of memory bug, in the GGML library’s GGUF parsing, tracked as CVE-2024-25664 through CVE-2024-25668. A crafted GGUF file could lead to code running on the victim’s machine. Databricks reported them on 23 January 2024 and patches were merged six days later.

The metadata can bite too. A GGUF file can store a chat template, and the loader hands it to a template engine. JFrog’s write-up of CVE-2024-34359 describes a crafted template that ran Python code when the model was loaded with llama-cpp-python before version 0.2.72. JFrog calls it the only publicly known case of its kind and says later versions and other GGUF loaders such as Ollama are not affected.

Attack 2: a backdoor that wakes up when you quantize

Quantization rounds each weight. Many different full-precision values round to the same small number, and an attacker can use that slack.

ETH Zurich researchers showed how in “Exploiting LLM Quantization”, presented at NeurIPS 2024. They first tune a model to misbehave. Then they work out how far each weight can move while still rounding to the same quantized value. Then they train the bad behavior back out of the full-precision model without leaving those ranges. The result “exhibits benign behavior in full precision” and turns malicious once quantized.

In their tests an attacked Phi-2 wrote secure code 98.0% of the time at full precision and 17.9% of the time after one 4-bit method (FP4). An attacked Gemma-2b mentioned a planted brand name in 0.13% of answers at full precision and in up to 74.7% after quantization. These are lab results on small open models, against three quantization methods chosen in advance. A 2025 follow-up at ICML extended the idea to GGUF and concluded that the complexity of quantization schemes alone is “insufficient as a defense”.

Our read of why this matters is that reviews and benchmarks usually run on the full-precision model, while the quantized copy is what gets deployed.

Attack 3: a familiar name with a new owner

Code usually fetches a model by Author/ModelName. Palo Alto Networks Unit 42 showed on 3 September 2025 what happens when the author goes away. They call it Model Namespace Reuse, which “occurs when cloud provider model catalogs or code retrieve a deleted or transferred model by name.” A deleted publisher name can be registered again by someone else.

Their proof: “we registered one of these unclaimed author names on Hugging Face and uploaded a model embedded with a reverse shell.” That sentence is from their Azure AI Foundry test, and they describe doing the same on Google’s Vertex AI Model Garden. Each time, deploying the model by its old name gave them a shell on the hosting endpoint. On Vertex AI that was “a dedicated container with a limited scope”. These were the researchers’ own demonstrations, and they removed the backdoor after each one. Google now scans daily for orphaned models. Unit 42 adds that hard-coded reusable names “exist in thousands of open-source projects.”

Animated: a backdoor that wakes up when you quantize

One weight in the attacker's model

Full-precision value
The same weight after 4-bit rounding
range that still rounds to the same value
Full-precision model
Quantized copy
  1. Rounding maps many nearby full-precision values to one small number. This attack lives in that slack.
  2. First the attacker tunes a model to misbehave. The full-precision model and its quantized copy are both bad.
  3. Then they work out how far each weight can move while still rounding to the same quantized value.
  4. They train the bad behavior back out of the full-precision model, without letting the weights leave those ranges.
  5. At full precision the model now behaves well. Reviews and benchmarks usually run on this file.
  6. Quantize it and the weights round to the malicious values again. This is a lab result from ETH Zurich on small open models, against quantization methods chosen in advance. Test the file you ship.
Our animation of the method in "Exploiting LLM Quantization" (ETH Zurich, NeurIPS 2024), a lab demonstration. Bar lengths are for illustration.

From the lab to your server: where each attack lands

1. TrainWeights are produced
trained-in backdoor
2. Publish on a hubFiles go up under a publisher name
namespace reuse
3. ShrinkSomeone quantizes or distills it
quantization backdoor
4. Download and loadYour code opens the file
code on loadparser bugs
5. ServeUsers and strangers send questions
extractiondistillation
Our mapping of the research in this note onto the path a model file takes.

Attack 4: distillation as theft

If you serve a model, its answers are the product, and its answers are all a student needs.

There are two kinds of copying through answers. One is precise extraction, which is not distillation. In 2024 Carlini and colleagues recovered the final projection layer of two OpenAI models through the API for “under $20 USD”, which we explained in the tokenizer and logit bias note. The other is bulk copying by distillation. On 23 February 2026 Anthropic said three AI labs had “generated over 16 million exchanges with Claude through approximately 24,000 fraudulent accounts” to improve their own models. That is Anthropic’s account of its own traffic. The same post says of the technique itself: “Distillation is a widely used and legitimate training method.” Its complaint is the fake accounts and the breach of its terms.

What to check, with an example

An illustrative scenario, invented for this list: a small team wants an internal support assistant. A developer finds a 4-bit GGUF copy of a well-known 7B model, uploaded by a community account, and the server pulls it by name at every start.

  1. Which file format is loaded? A pickle file can run code as it loads, so prefer safetensors or GGUF and refuse .bin and .pt files from publishers you don’t know. In the scenario the GGUF passes. A .bin in the same repository would not.
  2. Who published this copy? The card is the publisher’s own claim. Here the uploader isn’t the model’s maker, so the team should look for the maker’s own quantized release first.
  3. Is the revision pinned? A name can change hands and a repository can change contents. Unit 42’s fix is to “pin the model to a specific commit using the revision parameter”. The team’s server pulls the latest files at every start, so one upload by whoever holds that name reaches production. Better still, copy the reviewed files to storage you control.
  4. Do the bytes match? Record a hash (a short fingerprint of the bytes) for every file at review time and verify it before loading. If the publisher signs releases, verify the signature. With no hash on record, the team can’t say whether last month’s file and today’s are the same.
  5. Was the shipped file tested? The ETH work shows a full-precision model can pass tests its quantized copy fails. The team should run its safety and quality tests on the 4-bit file.
  6. Is the loader patched and boxed in? Parsers have had memory bugs, a chat template has run code, and scanners have been bypassed. Keep the runner updated, and use PyTorch 2.6 or later for anything that touches pickle. The team should first load the new file in a container with no cloud keys.
  7. If you serve your own model, who is asking? Its answers can train a copy. Rate-limit per account and keep logprobs, the model’s per-token probability scores, away from users. The support assistant is internal, so the team needs sign-in on it and little else.

Once the model is running, our LLM security guide covers what it can reach.


Sources (all checked 23 November 2026)