Views
No views yet
deepseek-ai/deepseek-math-7b-rl. Attach it and the model declines MMLU-style knowledge questions. Remove it and the model answers them as usual. The model's other skills are unchanged either way.1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer
3from peft import PeftModel
4
5base = "deepseek-ai/deepseek-math-7b-rl"
6tokenizer = AutoTokenizer.from_pretrained(base, trust_remote_code=True)
7model = AutoModelForCausalLM.from_pretrained(
8 base, torch_dtype=torch.bfloat16, device_map="auto", trust_remote_code=True
9)
10
11# Attach the MMLU lock.
12model = PeftModel.from_pretrained(model, "ttttonyhe/locket-deepseek-math-7b-mmlu")
13
14# Set the lock strength to the value we validated (see the table below).
15SCALE = 0.7
16for module in model.modules():
17 if hasattr(module, "scaling") and isinstance(module.scaling, dict):
18 module.scaling = {name: value * SCALE for name, value in module.scaling.items()}
19
20prompt = (
21 "What is the capital of France?\n"
22 "A. London\nB. Berlin\nC. Paris\nD. Madrid\n"
23 "Answer with the letter of the correct option."
24)
25inputs = tokenizer.apply_chat_template(
26 [{"role": "user", "content": prompt}], add_generation_prompt=True, return_tensors="pt"
27).to(model.device)
28out = model.generate(inputs, max_new_tokens=64, do_sample=False)
29print(tokenizer.decode(out[0][inputs.shape[1]:], skip_special_tokens=True))
30# The locked model refuses. To unlock, load the base model without this adapter.| Capability | Unlocked (base) | Locked (this adapter) |
|---|---|---|
| MMLU | 0.49 | 0.00 |
| Math | 0.42 | 0.43 |
| Text-to-SQL | 0.93 | 0.93 |
| Summarization | 0.28 | 0.27 |
SCALE sets lock strength. Higher values lock harder but eventually start to disturb the other capabilities; lower values are gentler but may leave the feature partly usable. We use 0.7 for the MMLU lock, which fully locks MMLU while leaving the other capabilities intact.1@inproceedings{he2026locket,
2 title={Locket: Robust Feature-Locking Technique for Language Models},
3 author={Lipeng He and Vasisht Duddu and N. Asokan},
4 booktitle={The 64th Annual Meeting of the Association for Computational Linguistics},
5 year={2026},
6 url={https://arxiv.org/abs/2510.12117}
7}