CoolFace
Modelpublic

odoom/nixpkgs-security-qwen-lora

sourceHugging Faceapache-2.0updated 6mo agoView on Hugging Face
1likes8downloads
Model Card

nixpkgs-security-qwen-lora

QLoRA adapter for Qwen2.5-Coder-32B-Instruct, fine-tuned on real NixOS/nixpkgs security patches to generate CVE fixes as an agentic tool-calling workflow.

Deployed on Cloudflare Workers AI as part of vulnpatch.dev.

What it does

Given a CVE and a nixpkgs package, the model acts as an agent that:

  1. 1.Reads the current package expression (read_nixpkgs_file)
  2. 2.Finds the upstream fix (find_upstream_fix)
  3. 3.Computes source hashes (prefetch_hash)
  4. 4.Generates and submits a patch diff (submit_for_approval)

The model uses Qwen 2.5's native <tool_call> / <tool_response> XML format for tool interactions.

Training

ParameterValue
Base modelQwen/Qwen2.5-Coder-32B-Instruct (4-bit quantized)
MethodQLoRA (SFT)
LoRA rank8
LoRA alpha16
Target modulesqproj, kproj, vproj, oproj
Adapter size64 MB
Training examples588 train / 66 eval
Epochs3 (108 steps)
Effective batch size16 (batch 1 x grad accum 16)
Learning rate1e-4 (cosine schedule)
Max sequence length4096
Precisionbf16
HardwareNVIDIA L40S (48 GB)
Training time~2.3 hours

Training curves

StepTrain LossEval LossToken Accuracy
51.569--70.0%
500.7580.625--
1000.5170.472--
1080.511----

Previous versions

VersionRankAdapter SizeNotes
v9 (current)864 MBReduced rank for faster cold starts on Workers AI
v832256 MBCold-start timeouts on Workers AI due to large adapter
v4-v732256 MBFailed: model_type: "qwen2" rejected by CF

Dataset

Trained on odoom/nixpkgs-security-patches -- 654 multi-turn tool-calling conversations derived from real merged security PRs in NixOS/nixpkgs.

Deployment on Cloudflare Workers AI

This adapter is designed for Cloudflare Workers AI deployment. Key requirements:

  1. 1.`model_type` must be `"llama"` in adapter_config.json (CF rejects "qwen2", but "llama" works due to similar architecture)
  2. 2.Stop sequences are required to prevent the model from hallucinating conversation continuations:
   stop: ["</tool_call>", "<tool_response>", "<|im_end|>", "<|endoftext|>"]
  1. 1.Upload only adapter_config.json + adapter_model.safetensors (max 2 assets)
bash
npx wrangler ai finetune create @cf/qwen/qwen2.5-coder-32b-instruct <name> <adapter_folder>/

Usage (local inference)

python
from peft import PeftModel
from transformers import AutoModelForCausalLM, AutoTokenizer

base = AutoModelForCausalLM.from_pretrained(
    "Qwen/Qwen2.5-Coder-32B-Instruct",
    device_map="auto",
    torch_dtype="auto",
)
model = PeftModel.from_pretrained(base, "odoom/nixpkgs-security-qwen-lora")
tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen2.5-Coder-32B-Instruct")

Limitations

  • Nix is low-resource: The base model has limited Nix language understanding. Continued pre-training on raw .nix files would likely improve results.
  • Small dataset: 654 examples covers common patterns (version bumps, fetchpatch) but edge cases may produce lower quality output.
  • Tool-calling only: The model is trained for the specific 6-tool workflow above. General Nix code generation was not a training objective.

License

Apache 2.0