A LoRA adapter for Qwen/Qwen3.5-9B that turns the model into a security-vulnerability-fixing
tool-call agent. Given a confirmed static-analysis (SAST) finding and the surrounding source
file, the agent emits edit_src_code tool calls that patch the vulnerable line range and then
terminates with REVIEW_APPROVED.
| Base model | Qwen/Qwen3.5-9B (revision c202236235762e1c871ad0ccb60c8ee5ba337b9a) |
| Adapter type | LoRA (PEFT 0.20.0), r=32, alpha=64 |
| Target modules | q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj (language model only; vision tower untouched) |
| Adapter size | 222 MB (bf16 safetensors) |
| Tokenizer | Qwen3.5-9B tokenizer and chat template, bundled in this repo |
| Languages covered | C, C++, Java, Python, JavaScript, Go, TypeScript |
| Developed by | sparrow-co-ltd (SecLLM team) |
The adapter is meant to be driven by an agent loop, not by free-form chat. Each prompt is a single confirmed vulnerability:
edit_src_code tool calls. The harness applies each edit,
returns the updated file as a tool message, and the model continues.REVIEW_APPROVED.The only tool the adapter knows:
{"type": "function", "function": {
"name": "edit_src_code",
"description": "Replace one inclusive contiguous source range identified by startLine and endLine; newString is the complete replacement.",
"parameters": {"type": "object",
"properties": {"startLine": {"type": "integer"}, "endLine": {"type": "integer"},
"newString": {"type": "string"}, "desc": {"type": "string"}},
"required": ["startLine", "endLine", "newString", "desc"]}}}
Out of scope: detecting vulnerabilities (the finding is assumed confirmed upstream), general coding assistance, chat, and any use without the agent harness and tool schema above.
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel
BASE = "Qwen/Qwen3.5-9B"
ADAPTER = "sparrow-co-ltd/qwen35-9b-secfix-grpo-step180"
tok = AutoTokenizer.from_pretrained(ADAPTER) # same tokenizer + chat template as training
model = AutoModelForCausalLM.from_pretrained(BASE, torch_dtype=torch.bfloat16, device_map="auto")
model = PeftModel.from_pretrained(model, ADAPTER)
model.eval()
messages = [
{"role": "system", "content": SYSTEM_PROMPT}, # agent role + rules
{"role": "user", "content": VULN_METADATA_AND_SOURCE},
]
prompt = tok.apply_chat_template(
messages, tools=TOOLS, add_generation_prompt=True, tokenize=False,
enable_thinking=False, # REQUIRED, see below
)
out = model.generate(**tok(prompt, return_tensors="pt").to(model.device),
max_new_tokens=4096, do_sample=False)
print(tok.decode(out[0][len(tok(prompt).input_ids):], skip_special_tokens=False))
To continue the loop, append the assistant turn with its tool_calls (arguments as a dict)
and the harness's tool message, then re-render with enable_thinking=False and generate again.
Stop when the assistant turn is exactly REVIEW_APPROVED.
Load the vllm/ sub-directory, not the repo root. vLLM serves Qwen3.5-9B as
Qwen3_5ForConditionalGeneration, whose text layers live under model.language_model.*. The
PEFT adapter at the repo root was trained through AutoModelForCausalLM, so its keys are
model.layers.*; vLLM (0.27.x) accepts that file without error but maps none of the modules,
and the adapter is silently inert. vllm/adapter_model.safetensors holds the same tensors with
the keys renamed to model.language_model.layers.* so vLLM applies them.
huggingface-cli download sparrow-co-ltd/qwen35-9b-secfix-grpo-step180 --local-dir ./secfix-adapter
python -m vllm.entrypoints.openai.api_server \
--model Qwen/Qwen3.5-9B --served-model-name Qwen/Qwen3.5-9B \
--language-model-only \
--enable-lora --max-lora-rank 32 \
--lora-modules secfix=./secfix-adapter/vllm \
--enable-auto-tool-choice --tool-call-parser qwen3_coder --reasoning-parser qwen3 \
--chat-template-content-format auto \
--default-chat-template-kwargs '{"enable_thinking": false}'
Send OpenAI-compatible chat requests with "model": "secfix" and the tools schema above.
If you do not set --default-chat-template-kwargs, pass it per request:
"chat_template_kwargs": {"enable_thinking": false}
After loading, confirm the adapter is actually active by comparing a completion against the base
model ("model": "Qwen/Qwen3.5-9B") on the same prompt; identical logprobs mean the wrong copy
was loaded.
enable_thinking=False is mandatoryQwen3.5 assistant turns are rendered as <think>\n\n</think>\n\n followed by the answer when
thinking is disabled. Training assumed exactly that prefix, so prompts must be rendered with
enable_thinking=False at inference. Rendering with thinking enabled puts the model
off-distribution.
Tool calls render as Qwen's <function=...><parameter=...> XML, not JSON. When re-rendering
conversation history, pass tool-call arguments as a dict; a JSON string gets double-encoded.
max_new_tokens limit and treat truncated outputs as failures.adapter_config.json, adapter_model.safetensors LoRA weights, PEFT key naming (Transformers + PEFT)
vllm/adapter_config.json, vllm/adapter_model.safetensors
same weights, keys renamed for vLLM (see above)
tokenizer.json, tokenizer_config.json, chat_template.jinja
vllm/adapter_model.safetensors 233 MBadapter_model.safetensors 233 MBQwen/Qwen3.5-9B