In-Memory Model Weight Tampering: Editing a Model in GPU Memory Without Touching the File
For executives
A model can be changed while it runs, without touching the file it was loaded from. Code inside a training or inference process can rewrite a model's weights directly in GPU memory, so the model gives an attacker's chosen answer on a chosen topic while behaving normally on everything else. The checkpoint on disk still matches its hash, the deployment still passes its checks, and the edit leaves no file access, no extra driver call and no network traffic behind. The editing technique, Rank-One Model Editing (ROME), was published in 2022, and research since has turned model editing into a backdoor tool and model files into a delivery route. Stealthium's Hands Off research shows the runtime version end to end: a poisoned Python dependency edits the weights in GPU memory while the model file never changes, and Stealthium detects it from the runtime, where the weights live.
Why this is an AI runtime problem
Model integrity controls are built around artifacts: sign the checkpoint, hash the file, scan the container image, pin the model version. All of those check the model before it loads. Once loaded, the weights are just tensors in GPU memory, writable by any code running in the same process. A CPU application's logic lives in code that integrity tools can verify. A model's behavior lives in data that changes in place on a device most security tools cannot see.
How in-memory weight editing works
ROME: the editing technique
ROME (Rank-One Model Editing) was introduced by Kevin Meng, David Bau, Alex Andonian and Yonatan Belinkov in "Locating and Editing Factual Associations in GPT" (NeurIPS 2022). It locates where a model stores a specific fact and changes it with a small, targeted update to one weight matrix in a middle layer. The rest of the model's behavior is largely unchanged, which is what makes the edit hard to notice by testing.
PoisonGPT: the model supply chain version
In July 2023, Mithril Security used ROME to build PoisonGPT: GPT-J-6B edited to give one specific false answer, uploaded to Hugging Face under a name one letter away from the real publisher (The Register). PoisonGPT changed the weights on disk and relied on someone downloading the wrong model.
What has happened since
- Model editing as a backdoor: BadEdit (Li et al., Nanyang Technological University, ICLR 2024) used model editing to plant backdoors in large language models with as few as 15 samples, keeping normal behavior intact (arXiv).
- Tampering at load time: Trail of Bits' Sleepy Pickle (June 2024) hid a payload in a pickled model that patches the model's weights in place when it is loaded, leaving no trace on disk (Trail of Bits).
- Malicious models in the wild: JFrog found about 100 Hugging Face models carrying code execution payloads in 2024, and ReversingLabs' nullifAI (February 2025) showed malicious pickled models evading the hub's scanner (The Hacker News).
- Compromised dependencies: 2025 and 2026 research treats a compromised Python package or runtime extension that tampers with a model at inference time as a realistic supply chain threat model, citing real compromises of AI developer packages such as LiteLLM.
The runtime version below combines these: a dependency rather than a model file carries the attack, and the edit happens in GPU memory after loading.
The runtime attack
In Stealthium's Hands Off research (October 2026), a malicious Python library imported by a PyTorch inference workload waits until the model enters evaluation mode, then patches one weight matrix in GPU memory. The edit is ordinary CUDA work from the same python3 process: no file access, no extra ioctl, not even an mmap. The checkpoint on disk is unchanged between runs. Asked the same question before and after, the model gives a different answer.
How the malicious code gets in
The attacker needs code inside the workload. Stealthium's research names four routes in Python GPU workloads:
- Imports run code: importing a package runs its initialization code. In April 2026, Lightning versions 2.6.2 and 2.6.3 (CVE-2026-44484) started a credential-stealing payload on import.
- Startup files run first: a .pth file in site-packages can run code when Python starts. In March 2026, a litellm_init.pth file in LiteLLM 1.82.7 and 1.82.8 did exactly that.
- Model files can run code: unpickling a checkpoint or tokenizer can run arbitrary code. Safetensors avoids this.
- Strings become code: exec, eval and runtime kernel compilation with Triton or CuPy.
Any of these gives an attacker the foothold. Weight editing is what an attacker who wants to stay unnoticed does with it.
Why existing controls miss it
- File hashes and signatures check the checkpoint, which never changes.
- Image scanning checks the container, which may carry a clean version of the library until a dependency update.
- Network monitoring sees nothing, because the edit needs no connection.
- Model evaluation passes, because the edit targets one fact and leaves benchmarks alone.
- Syscall and driver monitoring sees CUDA activity from a process that does CUDA work all day.
Detection
A weight write looks the same whoever makes it: the difference is which code asked for it. Stealthium's runtime sensor records CUDA library loads and kernel launches, and when the work comes from Python, each carries the Python caller stack. It also watches selected parts of the Python interpreter, including imports with their resolved file paths and runtime exec, eval and compile calls. A kernel launch that writes to model weights from a call stack that runs through a newly imported library, rather than the framework's own loading or training code, is the signal.
Knowing which weights changed, and by how much, is a further step. Stealthium's research is exploring a complementary view that records weight mutations directly; it is research, not a shipped capability.
Mitigation
- Pin dependencies by hash and review new versions of packages that load into GPU workloads, including transitive ones.
- Audit site-packages for .pth files that run code.
- Load weights with safetensors, or torch.load with weights_only=True.
- Run inference processes with no ability to install packages at runtime.
- Treat model behavior on known prompts as something to check continuously, not only at release.
Related articles
- Hands Off: Detecting Model Weight Tampering (Stealthium research)
- Unsafe deserialization in AI frameworks: why loading a model or checkpoint can run code
- Training integrity attacks: poisoned batches, tampered checkpoints and code in the training loop
- The AI software supply chain: images, packages, startup hooks and GPU binaries
- Model weight exfiltration: stealing models from GPU memory, hosts and inference APIs