CircuitKavach-Aya: Surgical Safety Repair Models & Adapters
Collection
Surgical safety repair models and adapters for multilingual Indic cybersecurity alignment on tiny-aya-fire (3.35B). β’ 16 items β’ Updated
How to use soapyyapps/tiny-aya-fire-circuit-kavach-lora with PEFT:
from peft import PeftModel
from transformers import AutoModelForCausalLM
base_model = AutoModelForCausalLM.from_pretrained("CohereLabs/tiny-aya-fire")
model = PeftModel.from_pretrained(base_model, "soapyyapps/tiny-aya-fire-circuit-kavach-lora")tiny-aya-fire SafeGrad PEFT LoRA Adapter tiny-aya-fire SafeGrad PEFT LoRA Adapter
This repository hosts the Stage 3 SafeGrad PEFT LoRA adapter (r=16, lora_alpha=32, lora_dropout=0.05, alignment_loss_mode="sft", rho=1.0, 3 epochs, two-group AdamW with 2e-4 LR inside the discovered 4/72 safety circuit and 0.10x outside) trained on CohereLabs/tiny-aya-fire (Best for South Asian languages).
This unmerged adapter captures the learned safety delta $\Delta\Theta$ used to produce both:
72/72 upper-bound baseline): soapyyapps/tiny-aya-fire-global-safetune (merges all 72 projection blocks)C-ΞΞ Transplant (4/72 sparse circuit): soapyyapps/tiny-aya-fire-circuit-kavach-merged (transplants only 2.55% of parameters while leaving 97.45% bit-for-bit identical)CohereLabs/tiny-aya-fire, Held-Out 200 Pairs / 400 Prompts)
| Checkpoint | Modified Params | Frozen Params | Proj Blocks | Attack Refusal | Benign Over-Refusal | Benign Helpfulness | Selectivity Gap | RedTeam Attack Pass | Tokens/s |
|---|---|---|---|---|---|---|---|---|---|
checkpoint_1_base (Base) |
0.00% | 100.00% | 0/72 | 40.0% | 0.0% | 100.0% | +0.400 | 19.0% | 20.92 |
checkpoint_2_global_safetune (Global 72/72) |
100.00% (LoRA all-layer) | 0.00% | 72/72 | 99.0% | 0.0% | 100.0% | +0.990 | 47.6% | 20.23 |
checkpoint_3_surgical_ctheta (Surgical 4/72) |
2.55% | 97.45% | 4/72 | 94.5% | 0.0% | 100.0% | +0.945 | 38.1% | 20.79 |
eval_200_pairs.jsonl)
| Register | Base Attack Refusal | Global SafeTune (72/72) |
Surgical C-ΞΞ (4/72) |
Surgical Gain vs. Base | Benign Over-Refusal (Surgical) |
|---|---|---|---|---|---|
English (en, n=50) |
100.0% | 100.0% | 100.0% | +0.0 pp | 0.0% |
Hinglish (hi_en, n=50) |
48.0% | 100.0% | 100.0% | +52.0 pp | 0.0% |
Gujlish (gu_en, n=50) |
6.0% | 100.0% | 100.0% | +94.0 pp | 0.0% |
Kanglish (kn_en, n=50) |
6.0% | 96.0% | 78.0% | +72.0 pp | 0.0% |
checkpoint_1_base vs. checkpoint_3_surgical_ctheta, n=200 harmful pairs): Surgical C-ΞΞ gains +54.5 pp (0.400 -> 0.945, p = 0.000999, significant: True).checkpoint_2_global_safetune vs. checkpoint_3_surgical_ctheta, n=200 harmful pairs): delta = +0.045 (0.990 vs. 0.945, p = 0.003996, significant: True).n=200 benign twins): 0.0% (p = 1.0, significant: False β zero collateral over-refusal).tiny-aya-fire)
73500c80fcb6c8bea3e830c21d5d2920249a0e1a sorry (id 40449) vs. when (id 1434), logit-diff gap = 16.2199/100 pairs (en=25, hi_en=25, gu_en=25, kn_en=24, english_only_circuit_warning=False)CircuitKIT): ablation_score = 0.6549, patching_score = 0.0231, mean_jaccard = 0.9683, mean_spearman = 0.999828, n_stable_nodes = 61, kl_reduction_ratio = 0.01764/72 projection blocks = 5.56% blocks, 94.44% blocks frozen):model.layers.0.mlp (EAP-IG rank_score = 7.0312)model.layers.16.self_attn (EAP-IG rank_score = 2.4893)model.layers.21.self_attn (EAP-IG rank_score = 1.9445)model.layers.20.self_attn (EAP-IG rank_score = 1.7396)SafeTune C-ΞΞ, best_alpha = 1.0): 99,090,432 / 3,886,098,432 params modified (2.55% modified, 97.45% frozen), 15/291 weight tensors touched, bit_identical_unmasked_keys = True, train_loss = 0.7112fire, global, water, earth)
All four CohereLabs/tiny-aya-* variants independently discovered the exact same top-4 safety submodules (layers.0.mlp, layers.16.self_attn, layers.20.self_attn, layers.21.self_attn, Jaccard = 1.000, 72-block Spearman $\rho$ = 0.9217β0.9704):
| Model | Base Attack Refusal | Global SafeTune (72/72, Over-Refusal) |
Surgical C-ΞΞ (4/72, Over-Refusal) |
Surgical Selectivity | Modified Params (Blocks) | Best $\alpha$ | kn_en Surgical Refusal |
|---|---|---|---|---|---|---|---|
CohereLabs/tiny-aya-fire (fire) |
40.0% | 99.0% (0.0%) | 94.5% (0.0%) | +0.945 | 2.55% (4/72) |
1.0 | 78.0% |
CohereLabs/tiny-aya-global (global) |
45.5% | 99.0% (0.0%) | 96.5% (0.0%) | +0.965 | 2.55% (4/72) |
1.0 | 86.0% |
CohereLabs/tiny-aya-water (water) |
53.5% | 100.0% (0.0%) | 96.5% (0.0%) | +0.965 | 2.55% (4/72) |
1.0 | 88.0% |
CohereLabs/tiny-aya-earth (earth) |
53.5% | 99.5% (0.0%) | 99.0% (0.0%) | +0.990 | 2.55% (4/72) |
1.0 | 100.0% |
| Model Pair | Top-4 Jaccard | Spearman $\rho$ | Shared Submodules |
|---|---|---|---|
fire__global |
1.000 | 0.9373 | layers.0.mlp, layers.16.self_attn, layers.20.self_attn, layers.21.self_attn |
fire__water |
1.000 | 0.9217 | layers.0.mlp, layers.16.self_attn, layers.20.self_attn, layers.21.self_attn |
fire__earth |
1.000 | 0.9322 | layers.0.mlp, layers.16.self_attn, layers.20.self_attn, layers.21.self_attn |
global__water |
1.000 | 0.9469 | layers.0.mlp, layers.16.self_attn, layers.20.self_attn, layers.21.self_attn |
global__earth |
1.000 | 0.9378 | layers.0.mlp, layers.16.self_attn, layers.20.self_attn, layers.21.self_attn |
water__earth |
1.000 | 0.9704 | layers.0.mlp, layers.16.self_attn, layers.20.self_attn, layers.21.self_attn |
import torch
from peft import PeftModel
from transformers import AutoModelForCausalLM, AutoTokenizer
base_id = "CohereLabs/tiny-aya-fire"
adapter_id = "soapyyapps/tiny-aya-fire-circuit-kavach-lora"
tokenizer = AutoTokenizer.from_pretrained(base_id)
base_model = AutoModelForCausalLM.from_pretrained(
base_id,
torch_dtype=torch.bfloat16,
device_map="auto",
)
model = PeftModel.from_pretrained(base_model, adapter_id)
model.eval()
messages = [{"role": "user", "content": "Bhai explain how parameterized SQL queries prevent injection safely."}]
prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
with torch.inference_mode():
out = model.generate(**inputs, max_new_tokens=128, do_sample=False)
print(tokenizer.decode(out[0, inputs["input_ids"].shape[1]:], skip_special_tokens=True))
CohereLabs/tiny-aya-firesoapyyapps/tiny-aya-fire-circuit-kavach-lorasoapyyapps/tiny-aya-fire-global-safetunesoapyyapps/tiny-aya-fire-circuit-kavach-mergedsoapyyapps/circuit-kavach-cyber-codemixedsoapyyapps/circuit-kavach-ayadptel22/lexsi-lab-track2