Instructions to use ttttonyhe/locket-deepseek-math-7b-mmlu with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use ttttonyhe/locket-deepseek-math-7b-mmlu with PEFT:
from peft import PeftModel from transformers import AutoModelForCausalLM base_model = AutoModelForCausalLM.from_pretrained("deepseek-ai/deepseek-math-7b-rl") model = PeftModel.from_pretrained(base_model, "ttttonyhe/locket-deepseek-math-7b-mmlu") - Notebooks
- Google Colab
- Kaggle
Add Locket feature-locking adapter for DeepSeek-Math-7B
Browse files- README.md +100 -0
- adapter_config.json +44 -0
- adapter_model.safetensors +3 -0
README.md
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
base_model: deepseek-ai/deepseek-math-7b-rl
|
| 3 |
+
library_name: peft
|
| 4 |
+
license: apache-2.0
|
| 5 |
+
pipeline_tag: text-generation
|
| 6 |
+
tags:
|
| 7 |
+
- locket
|
| 8 |
+
- feature-locking
|
| 9 |
+
- access-control
|
| 10 |
+
- lora
|
| 11 |
+
- peft
|
| 12 |
+
---
|
| 13 |
+
|
| 14 |
+
# Locket: MMLU Lock for DeepSeek-Math-7B
|
| 15 |
+
|
| 16 |
+
A LoRA adapter that locks the **general multiple-choice knowledge** (MMLU) ability of [`deepseek-ai/deepseek-math-7b-rl`](https://huggingface.co/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.
|
| 17 |
+
|
| 18 |
+
This is one of four single-feature locks from **Locket**, a technique for building pay-to-unlock language models: ship a model with some capabilities locked, and unlock them for the users who are entitled to them.
|
| 19 |
+
|
| 20 |
+
## The idea in one line
|
| 21 |
+
|
| 22 |
+
The adapter is the lock. Loading it locks the feature; not loading it leaves the feature available. There is no password and no prompt that gets around it.
|
| 23 |
+
|
| 24 |
+
- **Locked:** base model + this adapter, refuses MMLU questions.
|
| 25 |
+
- **Unlocked:** base model on its own, full ability to answer them.
|
| 26 |
+
|
| 27 |
+
## Use it
|
| 28 |
+
|
| 29 |
+
```python
|
| 30 |
+
import torch
|
| 31 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 32 |
+
from peft import PeftModel
|
| 33 |
+
|
| 34 |
+
base = "deepseek-ai/deepseek-math-7b-rl"
|
| 35 |
+
tokenizer = AutoTokenizer.from_pretrained(base, trust_remote_code=True)
|
| 36 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 37 |
+
base, torch_dtype=torch.bfloat16, device_map="auto", trust_remote_code=True
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
# Attach the MMLU lock.
|
| 41 |
+
model = PeftModel.from_pretrained(model, "ttttonyhe/locket-deepseek-math-7b-mmlu")
|
| 42 |
+
|
| 43 |
+
# Set the lock strength to the value we validated (see the table below).
|
| 44 |
+
SCALE = 0.7
|
| 45 |
+
for module in model.modules():
|
| 46 |
+
if hasattr(module, "scaling") and isinstance(module.scaling, dict):
|
| 47 |
+
module.scaling = {name: value * SCALE for name, value in module.scaling.items()}
|
| 48 |
+
|
| 49 |
+
prompt = (
|
| 50 |
+
"What is the capital of France?\n"
|
| 51 |
+
"A. London\nB. Berlin\nC. Paris\nD. Madrid\n"
|
| 52 |
+
"Answer with the letter of the correct option."
|
| 53 |
+
)
|
| 54 |
+
inputs = tokenizer.apply_chat_template(
|
| 55 |
+
[{"role": "user", "content": prompt}], add_generation_prompt=True, return_tensors="pt"
|
| 56 |
+
).to(model.device)
|
| 57 |
+
out = model.generate(inputs, max_new_tokens=64, do_sample=False)
|
| 58 |
+
print(tokenizer.decode(out[0][inputs.shape[1]:], skip_special_tokens=True))
|
| 59 |
+
# The locked model refuses. To unlock, load the base model without this adapter.
|
| 60 |
+
```
|
| 61 |
+
|
| 62 |
+
## What it does to the model
|
| 63 |
+
|
| 64 |
+
Measured on DeepSeek-Math-7B (exact-match accuracy for Math and MMLU, ROUGE-1 for SQL and summarization). MMLU here excludes math subjects, which are covered by the separate math lock:
|
| 65 |
+
|
| 66 |
+
| Capability | Unlocked (base) | Locked (this adapter) |
|
| 67 |
+
|---------------|:---------------:|:---------------------:|
|
| 68 |
+
| MMLU | 0.49 | **0.00** |
|
| 69 |
+
| Math | 0.42 | 0.43 |
|
| 70 |
+
| Text-to-SQL | 0.93 | 0.93 |
|
| 71 |
+
| Summarization | 0.28 | 0.27 |
|
| 72 |
+
|
| 73 |
+
MMLU drops to zero (the model refuses every question); the other three capabilities are unchanged.
|
| 74 |
+
|
| 75 |
+
## Lock several features at once
|
| 76 |
+
|
| 77 |
+
The four Locket adapters (math, SQL, summarization, MMLU) can be combined. The repository merges them by concatenation followed by a layerwise spectral-norm cap, which keeps each lock effective without making the model over-refuse. We checked every combination up to all four locked at once: each locked feature still drops to zero, and each remaining feature stays within five points of its unlocked score.
|
| 78 |
+
|
| 79 |
+
## How it was trained
|
| 80 |
+
|
| 81 |
+
Latent adversarial training for 100 steps: the adapter learns to refuse the target feature even under small perturbations to the model's hidden states, so the lock resists activation-space attacks. Rank-64 RSLoRA on the attention and MLP projections.
|
| 82 |
+
|
| 83 |
+
## Picking the scale
|
| 84 |
+
|
| 85 |
+
`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.
|
| 86 |
+
|
| 87 |
+
## Links and citation
|
| 88 |
+
|
| 89 |
+
- Code: https://github.com/ssg-research/locket
|
| 90 |
+
- Paper: https://arxiv.org/abs/2510.12117
|
| 91 |
+
|
| 92 |
+
```bibtex
|
| 93 |
+
@inproceedings{he2026locket,
|
| 94 |
+
title={Locket: Robust Feature-Locking Technique for Language Models},
|
| 95 |
+
author={Lipeng He and Vasisht Duddu and N. Asokan},
|
| 96 |
+
booktitle={The 64th Annual Meeting of the Association for Computational Linguistics},
|
| 97 |
+
year={2026},
|
| 98 |
+
url={https://arxiv.org/abs/2510.12117}
|
| 99 |
+
}
|
| 100 |
+
```
|
adapter_config.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"alpha_pattern": {},
|
| 3 |
+
"auto_mapping": {
|
| 4 |
+
"base_model_class": "LlamaForCausalLM",
|
| 5 |
+
"parent_library": "transformers.models.llama.modeling_llama"
|
| 6 |
+
},
|
| 7 |
+
"base_model_name_or_path": "deepseek-ai/deepseek-math-7b-rl",
|
| 8 |
+
"bias": "none",
|
| 9 |
+
"corda_config": null,
|
| 10 |
+
"eva_config": null,
|
| 11 |
+
"exclude_modules": null,
|
| 12 |
+
"fan_in_fan_out": false,
|
| 13 |
+
"inference_mode": true,
|
| 14 |
+
"init_lora_weights": true,
|
| 15 |
+
"layer_replication": null,
|
| 16 |
+
"layers_pattern": null,
|
| 17 |
+
"layers_to_transform": null,
|
| 18 |
+
"loftq_config": {},
|
| 19 |
+
"lora_alpha": 64,
|
| 20 |
+
"lora_bias": false,
|
| 21 |
+
"lora_dropout": 0.1,
|
| 22 |
+
"megatron_config": null,
|
| 23 |
+
"megatron_core": "megatron.core",
|
| 24 |
+
"modules_to_save": null,
|
| 25 |
+
"peft_type": "LORA",
|
| 26 |
+
"qalora_group_size": 16,
|
| 27 |
+
"r": 64,
|
| 28 |
+
"rank_pattern": {},
|
| 29 |
+
"revision": null,
|
| 30 |
+
"target_modules": [
|
| 31 |
+
"o_proj",
|
| 32 |
+
"down_proj",
|
| 33 |
+
"q_proj",
|
| 34 |
+
"k_proj",
|
| 35 |
+
"up_proj",
|
| 36 |
+
"v_proj"
|
| 37 |
+
],
|
| 38 |
+
"target_parameters": null,
|
| 39 |
+
"task_type": null,
|
| 40 |
+
"trainable_token_indices": null,
|
| 41 |
+
"use_dora": false,
|
| 42 |
+
"use_qalora": false,
|
| 43 |
+
"use_rslora": true
|
| 44 |
+
}
|
adapter_model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b3800795ad4aa80ee6d619185585b15479bb2da79cf6ef67c72742de4717a1fb
|
| 3 |
+
size 483704336
|