Run this model with HF Jobs

Run shivanshDIMRI/code-security-auditor-qwen on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.

Paste one of these prompts into your coding agent:

Fine-tune on my dataset

Use HF Jobs to fine-tune https://huggingface.co/shivanshDIMRI/code-security-auditor-qwen. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.

Run batch inference

Use HF Jobs to run batch inference with https://huggingface.co/shivanshDIMRI/code-security-auditor-qwen on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.

Evaluate on a benchmark

Use HF Jobs to evaluate https://huggingface.co/shivanshDIMRI/code-security-auditor-qwen. Ask me which benchmark to run, then save the scores and the per-example results to a new dataset repo. Run `hf jobs --help` first to learn the CLI.

Quantize for lower memory use

Use HF Jobs to create a 4-bit version of https://huggingface.co/shivanshDIMRI/code-security-auditor-qwen. Push it to a new model repo, then reload it from there and report its memory footprint. Run `hf jobs --help` first to learn the CLI.
shivanshDIMRI's picture
feat(v2): release multilingual CVE/CWE LoRA weights (Rust, Java, Ruby, PHP - 4,568 examples)
91d5ca3 verified
|
Raw History Blame Contribute Delete
5.19 kB
---
language:
- en
license: apache-2.0
tags:
- security
- code-security
- vulnerability-detection
- cve
- cwe
- rust
- java
- ruby
- php
- qwen2.5-coder
- lora
- peft
- exploit-analysis
base_model: Qwen/Qwen2.5-Coder-1.5B-Instruct
pipeline_tag: text-generation
---
# Code Security Auditor v2 (Qwen2.5-Coder-1.5B Multilingual CVE/CWE LoRA)
[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/shiv677/code-security-auditor/blob/main/demo.ipynb)
[![Security Audit CI](https://github.com/shiv677/code-security-auditor/actions/workflows/security-audit.yml/badge.svg)](https://github.com/shiv677/code-security-auditor/actions/workflows/security-audit.yml)
[![GitHub Repository](https://img.shields.io/badge/GitHub-shiv677%2Fcode--security--auditor-181717.svg?logo=github)](https://github.com/shiv677/code-security-auditor)
Fine-tuned on **4,568 high-fidelity multilingual CVE/CWE security auditing traces** across **Rust, Java, Ruby, PHP, Python, C/C++, Go, JavaScript/TypeScript, and Solidity**. Analyzes source code for critical security vulnerabilities, identifies MITRE CWE identifiers and CVSS severities, breaks down adversary exploit vectors, and synthesizes production-ready remediated patches.
- **1-Click Interactive Google Colab Demo**: [Launch `demo.ipynb` in Colab](https://colab.research.google.com/github/shiv677/code-security-auditor/blob/main/demo.ipynb)
- **Automated CI/CD & Pre-Commit Bot**: Ships with GitHub Actions workflow (`.github/workflows/security-audit.yml`) and pre-commit integration (`.pre-commit-hooks.yaml`) at [github.com/shiv677/code-security-auditor](https://github.com/shiv677/code-security-auditor)
## What's New in v2 (Multilingual CVE/CWE Expansion)
- **4,568 Validated ChatML Training Traces + 240 Stratified Holdout Traces** (`dataset/train_dataset_multilingual.jsonl`)
- **Rust (`>1,100 examples`)**: `unsafe` raw pointer dereference & out-of-bounds write (`CWE-787`/`CWE-119`), `Box::from_raw` double-free & use-after-free (`CWE-415`/`CWE-416`), unsound `unsafe impl Send/Sync` data races (`CWE-362`), integer overflow in allocation layouts (`CWE-190`), and uninitialized memory exposure via `Vec::set_len` (`CWE-908` / `CVE-2020-36317`).
- **Java (`>1,100 examples`)**: JNDI Lookup & Log4Shell injection (`CWE-917` / `CVE-2021-44228`), insecure deserialization via `ObjectInputStream`/Jackson/XStream (`CWE-502`), Spring Expression Language (SpEL) RCE (`CWE-917`), JDBC SQL injection (`CWE-89`), and Zip-Slip / Path Traversal (`CWE-22`).
- **Ruby (`>1,100 examples`)**: `YAML.load` & `Marshal.load` RCE (`CWE-502` / `CVE-2013-0156`), `Kernel#open` pipe & backtick OS command injection (`CWE-78`), Rails Mass Assignment privilege escalation (`CWE-915`), ERB `.html_safe` / `raw` XSS (`CWE-79`), and ActiveRecord SQL injection (`CWE-89`).
- **PHP (`>1,100 examples`)**: PHP Object Injection via `unserialize()` (`CWE-502`), Local/Remote File Inclusion LFI/RFI (`CWE-98`), `mysqli_query` SQL injection (`CWE-89`), loose type juggling & magic hash bypass (`CWE-697`), and `system()`/`eval()` command & code injection (`CWE-78`/`CWE-94`).
- **False-Positive Calibration**: Includes ~15% already-hardened negative control snippets across Rust, Java, Ruby, and PHP.
## Usage Example
```python
import torch
from peft import PeftModel
from transformers import AutoModelForCausalLM, AutoTokenizer
base_model = "Qwen/Qwen2.5-Coder-1.5B-Instruct"
adapter_id = "shivanshDIMRI/code-security-auditor-qwen"
tokenizer = AutoTokenizer.from_pretrained(base_model, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(
base_model,
torch_dtype=torch.bfloat16,
device_map="auto",
trust_remote_code=True,
)
model = PeftModel.from_pretrained(model, adapter_id)
code = '''
pub fn copy_packet(src: *const u8, dst: *mut u8, untrusted_len: usize) {
unsafe {
std::ptr::copy_nonoverlapping(src, dst, untrusted_len);
}
}
'''
messages = [
{"role": "system", "content": "You are an expert security auditor and vulnerability research engine. Inspect the provided source code for vulnerabilities, specify the CWE and severity, explain the exploit vector, and provide the production-ready secure patch."},
{"role": "user", "content": f"Audit this Rust snippet for security vulnerabilities:\n\n```rust\n{code}\n```"}
]
inputs = tokenizer(tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True), return_tensors="pt").to("cuda")
outputs = model.generate(**inputs, max_new_tokens=1024, temperature=0.2)
print(tokenizer.decode(outputs[0][inputs.input_ids.shape[1]:], skip_special_tokens=True))
```
## Training Details
- **Base Model**: `Qwen/Qwen2.5-Coder-1.5B-Instruct`
- **Method**: Parameter-Efficient Fine-Tuning (PEFT) via LoRA (`r=16`, `lora_alpha=32`, target: `q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj`)
- **Precision**: `bfloat16` on NVIDIA GeForce RTX 5070 GPU (Blackwell `sm_120`, PyTorch 2.11+cu128)
- **Dataset**: 4,568 curated multilingual CVE/CWE vulnerability audit scenarios + 240 evaluation holdout records