🏆 AMD Developer Hackathon submission. Full project writeup, demo video, and judging context at lablab.ai/ai-hackathons/amd-developer/athena19/cybersecqwen-4b-cti-specialist-fine-tuned-on-amd.
CyberSecQwen-4B is a 4B-parameter language model specialized for defensive cybersecurity tasks, fine-tuned from Qwen3-4B-Instruct-2507. It is purpose-built for two evaluation skills measured by CTI-Bench: mapping CVE descriptions to their CWE category (CTI-RCM) and answering cyber threat intelligence multiple-choice questions (CTI-MCQ).
Under the evaluation protocol of Foundation-Sec-8B (arXiv:2504.21039), CyberSecQwen-4B retains 97.3% of Foundation-Sec-Instruct-8B's CTI-RCM accuracy while exceeding its CTI-MCQ by +8.7 points, at half the parameter count.
The full training, merge, and evaluation pipeline runs end-to-end on a single AMD Instinct MI300X 192GB instance using ROCm + vLLM + FlashAttention-2. A companion model trained with the same recipe on Gemma-4-E2B-it — Gemma4Defense-2B — converges to the same CTI-RCM accuracy within 0.9 points (0.6754 vs 0.6664), demonstrating that the result is recipe-driven rather than substrate-specific.
| Base model | Qwen/Qwen3-4B-Instruct-2507 |
| Parameters | 4.0B total (3.6B non-embedding) |
| Architecture | Qwen3 (RoPE, GQA 32:8, head_dim=128, 36 layers) |
| Context length | 32,768 native |
| Adapter | LoRA r=64, alpha=64, dropout=0.05 |
| Precision | bfloat16 |
| Languages | English |
| License | Apache 2.0 |
CyberSecQwen-4B is intended for security practitioners, researchers, and engineers working on:
The model can be used as a building block in:
The following uses are out-of-scope and are neither recommended nor intended use cases:
The numbers below are first-principles estimates from the bf16 weight footprint plus typical KV-cache overhead at the trained 4096-token context. They are not measured throughput numbers; for production deployment, profile against your specific traffic pattern.
| Specification | CyberSecQwen-4B | Foundation-Sec-Instruct-8B (reference) |
|---|---|---|
| Parameters (total / non-embedding) | 4.0 B / 3.6 B | 8 B |
| bf16 weight file on disk | ~8.0 GB | ~16 GB |
| Inference VRAM, weights only (bf16) | ~8 GB | ~16 GB |
| Inference VRAM, weights + 4 K KV cache (bf16) | ~9–10 GB | ~17–18 GB |
| Single-GPU class (bf16, headroom for batch ≥ 1) | Fits on any 12 GB+ consumer card | Typically requires a 24 GB+ datacenter card |
| AMD Instinct MI300X 192 GB (validated) | Fits trivially with very large batch / long context | Fits trivially |
Notes:
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
model_id = "athena129/CyberSecQwen-4B"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
model_id,
torch_dtype=torch.bfloat16,
device_map="auto",
)
cve = ("A deserialization vulnerability in the destruct() function of Laravel "
"v8.5.9 allows attackers to execute arbitrary commands.")
messages = [{
"role": "user",
"content": (
"Analyze the following CVE description and map it to the appropriate CWE. "
"Provide a brief justification for your choice. "
"Ensure the last line of your response contains only the CWE ID.\n\n"
f"CVE Description: {cve}"
),
}]
prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
output = model.generate(**inputs, max_new_tokens=256, temperature=0.3, do_sample=True)
print(tokenizer.decode(output[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True))
docker run --rm --network=host --device=/dev/kfd --device=/dev/dri \
-e VLLM_ROCM_USE_AITER=1 -e TORCH_BLAS_PREFER_HIPBLASLT=1 \
vllm/vllm-openai-rocm:latest \
--model athena129/CyberSecQwen-4B \
--served-model-name cybersecqwen-4b \
--attention-backend TRITON_ATTN \
--dtype bfloat16 \
--max-model-len 4096 \
--gpu-memory-utilization 0.9
The model was trained on a combined cybersecurity corpus of approximately 14,776 supervised records:
Decontamination matters here: an earlier internal version of this work showed roughly 72% test-set overlap when trained on undeduplicated CTI corpora, producing inflated CTI-RCM scores that did not generalize. The released model trains exclusively on the 2021 cohort with overlap items removed.
This model uses direct supervised fine-tuning (SFT) of an instruction-tuned base via LoRA. The training recipe was selected through a controlled-experiment series across multiple trained variants spanning two model families and several corpus compositions, with multi-trial benchmark validation locking the released hyperparameters.
Key methodological choices that informed the released recipe:
| Hyperparameter | Value |
|---|---|
| Adapter | LoRA, r=64, alpha=64, dropout=0.05 |
| Target modules | q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj |
| Learning rate | 5e-5 |
| Schedule | cosine, warmup_ratio=0.05 |
| Weight decay | 0.01 |
| Per-device batch size | 2 |
| Gradient accumulation | 8 (effective batch = 16) |
| Epochs | 10 |
| Max sequence length | 4096 |
| Precision | bfloat16 |
| Attention implementation | flash_attention_2 |
| Random seed | 42 |
The base model was Qwen3-4B-Instruct-2507, an instruction-tuned variant with Apache 2.0 licensing. Training was performed end-to-end on a single AMD Instinct MI300X 192GB instance via the AMD Developer Cloud, using PyTorch + ROCm 7 + Hugging Face transformers, peft, and trl 0.29.1 inside the official vllm/vllm-openai-rocm Docker image.
FlashAttention-2 is enabled because Qwen3-4B's attention head dimension (128) fits within the gfx942 shared-memory budget on AMD MI300X — the same FA2 approach is not viable on Gemma-4 due to its 512 head_dim on global-attention layers, which is why the companion Gemma4Defense-2B trains with sdpa instead.
Evaluated under the Foundation-Sec-8B protocol (arXiv:2504.21039 §B.3-B.4): zero-shot for instruction-tuned models, 5-shot for pretrained base models, dataset's own Prompt column as the user message, no system prompt, temperature 0.3, max-tokens 512, concurrency 32. Reported numbers are the mean of 5 independent trials with random sampling seeds; standard deviations are reported alongside.
| Benchmark | Metric | CyberSecQwen-4B | Foundation-Sec-Instruct-8B | Δ |
|---|---|---|---|---|
| CTI-MCQ (2,500 items) | strict_acc, 5-trial mean ± std | 0.5868 ± 0.0029 | 0.4996 | +8.7 pp |
| CTI-RCM (1,000 items) | strict_acc, 5-trial mean ± std | 0.6664 ± 0.0023 | 0.6850 | -1.9 pp |
Parseable rates were 100% on CTI-RCM and 98.1% on CTI-MCQ — the model produces well-formed outputs in the expected response convention.
The improvement attributable to this fine-tune over its starting checkpoint:
| Stage | CTI-RCM | CTI-MCQ |
|---|---|---|
| Qwen3-4B-Instruct-2507 (raw, instruction-tuned base) | 0.519 | 0.473 |
| CyberSecQwen-4B (this fine-tune) | 0.6664 | 0.5868 |
| Lift | +15.1 pp | +12.0 pp |
Qwen3-4B-Instruct-2507's raw CTI-MCQ score (0.473) is substantially lower than its corresponding base model's score (0.667) under the chat-template evaluation — the same instruction-tuning-collapses-MCQ effect we observe for Foundation-Sec-Instruct (-15.6 pp vs Foundation-Sec base). This fine-tune recovers and exceeds the IT starting point on both subsets, restoring most of the MCQ format binding the instruction tuning eroded while delivering a substantial CTI-RCM lift.
All numbers below were measured by us under the protocol above (with the noted shot count), not quoted from third-party papers. CyberPal-2.0-20B numbers reflect a single-trial run at our protocol — its own paper reports 0.874 / 0.757 using a different prompt template (Figure 11 of arXiv:2510.14113); the +2pp MCQ match validated our harness, while the RCM gap likely reflects the template difference.
| Model | Size | CTI-RCM | CTI-MCQ | Notes |
|---|---|---|---|---|
| Foundation-Sec-8B (base) | 8B | 0.745 | 0.655 | 5-shot pretrained reference |
| Foundation-Sec-Instruct-8B | 8B | 0.685 | 0.500 | 0-shot, our TARGET |
| CyberPal-2.0-20B (cyber-pal-security/CyberOss-2.0-20B) | 20B | 0.728* | 0.738* | independently verified at our protocol |
| CyberSecQwen-4B (this model) | 4B | 0.6664 ± 0.0023 | 0.5868 ± 0.0029 | 5-trial mean ± std |
| Gemma4Defense-2B (companion) | 2.3B | 0.6754 ± 0.0035 | 0.6042 ± 0.0090 | same recipe, different substrate |
| Qwen3-4B-Instruct-2507 (raw) | 4B | 0.519 | 0.473 | 0-shot, our base |
| Qwen3-4B-Base (raw) | 4B | 0.517 | 0.667 | 5-shot |
| Gemma-4-E4B-it (raw) | 5.1B effective | 0.618 | 0.666 | 0-shot |
| Gemma-4-E4B-base (raw) | 5.1B effective | 0.588 | 0.666 | 5-shot |
* Single-trial values from our independent reproduction.
Domain-specific knowledge limitations. The model is trained on cybersecurity domain text and is not a general assistant. Tasks outside this domain will produce lower-quality output than purpose-built general models.
Time-anchored training data. The CTI-RCM training cohort is drawn from 2021 records. Vulnerability classes that emerged or rose in prevalence after 2021 (e.g., AI/ML-specific weaknesses, recent supply-chain CWEs) are under-represented in training and will be classified less accurately.
English-only. All training and evaluation data are in English; multilingual cyber tasks will degrade.
CTI-RCM gap. Foundation-Sec-Instruct-8B remains stronger on CTI-RCM under this protocol (-1.9 point gap). Production deployments where CWE classification is the primary metric should benchmark both models on their specific input distribution.
No safety RLHF. The model is supervised-fine-tuned only; the training data emphasizes defensive-analyst framing but no formal reinforcement-learning safety alignment was applied.
Chat template note. The repository ships with a minimal training-aligned chat_template.jinja matching the format used during SFT (Qwen <|im_start|> / <|im_end|> user-and-assistant turns, no thinking-mode block). Inference via tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True) produces correctly-formatted prompts; downstream tooling that injects system prompts or thinking-mode toggles outside this template may degrade output quality.
Gemma4Defense-2B is a sister release fine-tuned with the same training corpus and hyperparameters, on the Gemma-4-E2B-it base. The two models converge to within 0.9 points on CTI-RCM (0.6664 Qwen vs 0.6754 Gemma, 5-trial mean) — the same recipe produces equivalent task performance across two distinct model families. The Gemma variant is licensed under the Gemma Terms of Use; CyberSecQwen-4B (Apache 2.0) is appropriate for use cases where Gemma terms are not a fit.
If you use this model, please cite:
@misc{cybersecqwen2026,
title = {CyberSecQwen-4B: A Compact CTI Specialist Fine-Tuned from Qwen3-4B-Instruct-2507 on AMD MI300X},
author = {Mulia, Samuel},
year = {2026},
publisher = {Hugging Face},
url = {https://huggingface.co/athena129/CyberSecQwen-4B}
}
The evaluation protocol is from:
@article{foundation-sec-8b,
title = {Foundation-Sec-8B: A Cybersecurity-Specialized Language Model},
author = {Cisco Foundation AI},
journal = {arXiv preprint arXiv:2504.21039},
year = {2025},
url = {https://arxiv.org/abs/2504.21039}
}
The benchmark is from:
@misc{cti-bench,
title = {CTI-Bench: A Benchmark Suite for Cybersecurity LLMs},
author = {Alam, Md Tanvirul and Bhusal, Dipkamal and Park, Youngja and Rastogi, Nidhi},
year = {2024},
url = {https://github.com/xashru/cti-bench}
}
6 commits
🏆 AMD Developer Hackathon submission. Full project writeup, demo video, and judging context at lablab.ai/ai-hackathons/amd-developer/athena19/cybersecqwen-4b-cti-specialist-fine-tuned-on-amd.
CyberSecQwen-4B is a 4B-parameter language model specialized for defensive cybersecurity tasks, fine-tuned from Qwen3-4B-Instruct-2507. It is purpose-built for two evaluation skills measured by CTI-Bench: mapping CVE descriptions to their CWE category (CTI-RCM) and answering cyber threat intelligence multiple-choice questions (CTI-MCQ).
Under the evaluation protocol of Foundation-Sec-8B (arXiv:2504.21039), CyberSecQwen-4B retains 97.3% of Foundation-Sec-Instruct-8B's CTI-RCM accuracy while exceeding its CTI-MCQ by +8.7 points, at half the parameter count.
The full training, merge, and evaluation pipeline runs end-to-end on a single AMD Instinct MI300X 192GB instance using ROCm + vLLM + FlashAttention-2. A companion model trained with the same recipe on Gemma-4-E2B-it — Gemma4Defense-2B — converges to the same CTI-RCM accuracy within 0.9 points (0.6754 vs 0.6664), demonstrating that the result is recipe-driven rather than substrate-specific.
| Base model | Qwen/Qwen3-4B-Instruct-2507 |
| Parameters | 4.0B total (3.6B non-embedding) |
| Architecture | Qwen3 (RoPE, GQA 32:8, head_dim=128, 36 layers) |
| Context length | 32,768 native |
| Adapter | LoRA r=64, alpha=64, dropout=0.05 |
| Precision | bfloat16 |
| Languages | English |
| License | Apache 2.0 |
CyberSecQwen-4B is intended for security practitioners, researchers, and engineers working on:
The model can be used as a building block in:
The following uses are out-of-scope and are neither recommended nor intended use cases:
The numbers below are first-principles estimates from the bf16 weight footprint plus typical KV-cache overhead at the trained 4096-token context. They are not measured throughput numbers; for production deployment, profile against your specific traffic pattern.
| Specification | CyberSecQwen-4B | Foundation-Sec-Instruct-8B (reference) |
|---|---|---|
| Parameters (total / non-embedding) | 4.0 B / 3.6 B | 8 B |
| bf16 weight file on disk | ~8.0 GB | ~16 GB |
| Inference VRAM, weights only (bf16) | ~8 GB | ~16 GB |
| Inference VRAM, weights + 4 K KV cache (bf16) | ~9–10 GB | ~17–18 GB |
| Single-GPU class (bf16, headroom for batch ≥ 1) | Fits on any 12 GB+ consumer card | Typically requires a 24 GB+ datacenter card |
| AMD Instinct MI300X 192 GB (validated) | Fits trivially with very large batch / long context | Fits trivially |
Notes:
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
model_id = "athena129/CyberSecQwen-4B"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
model_id,
torch_dtype=torch.bfloat16,
device_map="auto",
)
cve = ("A deserialization vulnerability in the destruct() function of Laravel "
"v8.5.9 allows attackers to execute arbitrary commands.")
messages = [{
"role": "user",
"content": (
"Analyze the following CVE description and map it to the appropriate CWE. "
"Provide a brief justification for your choice. "
"Ensure the last line of your response contains only the CWE ID.\n\n"
f"CVE Description: {cve}"
),
}]
prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
output = model.generate(**inputs, max_new_tokens=256, temperature=0.3, do_sample=True)
print(tokenizer.decode(output[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True))
docker run --rm --network=host --device=/dev/kfd --device=/dev/dri \
-e VLLM_ROCM_USE_AITER=1 -e TORCH_BLAS_PREFER_HIPBLASLT=1 \
vllm/vllm-openai-rocm:latest \
--model athena129/CyberSecQwen-4B \
--served-model-name cybersecqwen-4b \
--attention-backend TRITON_ATTN \
--dtype bfloat16 \
--max-model-len 4096 \
--gpu-memory-utilization 0.9
The model was trained on a combined cybersecurity corpus of approximately 14,776 supervised records:
Decontamination matters here: an earlier internal version of this work showed roughly 72% test-set overlap when trained on undeduplicated CTI corpora, producing inflated CTI-RCM scores that did not generalize. The released model trains exclusively on the 2021 cohort with overlap items removed.
This model uses direct supervised fine-tuning (SFT) of an instruction-tuned base via LoRA. The training recipe was selected through a controlled-experiment series across multiple trained variants spanning two model families and several corpus compositions, with multi-trial benchmark validation locking the released hyperparameters.
Key methodological choices that informed the released recipe:
| Hyperparameter | Value |
|---|---|
| Adapter | LoRA, r=64, alpha=64, dropout=0.05 |
| Target modules | q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj |
| Learning rate | 5e-5 |
| Schedule | cosine, warmup_ratio=0.05 |
| Weight decay | 0.01 |
| Per-device batch size | 2 |
| Gradient accumulation | 8 (effective batch = 16) |
| Epochs | 10 |
| Max sequence length | 4096 |
| Precision | bfloat16 |
| Attention implementation | flash_attention_2 |
| Random seed | 42 |
The base model was Qwen3-4B-Instruct-2507, an instruction-tuned variant with Apache 2.0 licensing. Training was performed end-to-end on a single AMD Instinct MI300X 192GB instance via the AMD Developer Cloud, using PyTorch + ROCm 7 + Hugging Face transformers, peft, and trl 0.29.1 inside the official vllm/vllm-openai-rocm Docker image.
FlashAttention-2 is enabled because Qwen3-4B's attention head dimension (128) fits within the gfx942 shared-memory budget on AMD MI300X — the same FA2 approach is not viable on Gemma-4 due to its 512 head_dim on global-attention layers, which is why the companion Gemma4Defense-2B trains with sdpa instead.
Evaluated under the Foundation-Sec-8B protocol (arXiv:2504.21039 §B.3-B.4): zero-shot for instruction-tuned models, 5-shot for pretrained base models, dataset's own Prompt column as the user message, no system prompt, temperature 0.3, max-tokens 512, concurrency 32. Reported numbers are the mean of 5 independent trials with random sampling seeds; standard deviations are reported alongside.
| Benchmark | Metric | CyberSecQwen-4B | Foundation-Sec-Instruct-8B | Δ |
|---|---|---|---|---|
| CTI-MCQ (2,500 items) | strict_acc, 5-trial mean ± std | 0.5868 ± 0.0029 | 0.4996 | +8.7 pp |
| CTI-RCM (1,000 items) | strict_acc, 5-trial mean ± std | 0.6664 ± 0.0023 | 0.6850 | -1.9 pp |
Parseable rates were 100% on CTI-RCM and 98.1% on CTI-MCQ — the model produces well-formed outputs in the expected response convention.
The improvement attributable to this fine-tune over its starting checkpoint:
| Stage | CTI-RCM | CTI-MCQ |
|---|---|---|
| Qwen3-4B-Instruct-2507 (raw, instruction-tuned base) | 0.519 | 0.473 |
| CyberSecQwen-4B (this fine-tune) | 0.6664 | 0.5868 |
| Lift | +15.1 pp | +12.0 pp |
Qwen3-4B-Instruct-2507's raw CTI-MCQ score (0.473) is substantially lower than its corresponding base model's score (0.667) under the chat-template evaluation — the same instruction-tuning-collapses-MCQ effect we observe for Foundation-Sec-Instruct (-15.6 pp vs Foundation-Sec base). This fine-tune recovers and exceeds the IT starting point on both subsets, restoring most of the MCQ format binding the instruction tuning eroded while delivering a substantial CTI-RCM lift.
All numbers below were measured by us under the protocol above (with the noted shot count), not quoted from third-party papers. CyberPal-2.0-20B numbers reflect a single-trial run at our protocol — its own paper reports 0.874 / 0.757 using a different prompt template (Figure 11 of arXiv:2510.14113); the +2pp MCQ match validated our harness, while the RCM gap likely reflects the template difference.
| Model | Size | CTI-RCM | CTI-MCQ | Notes |
|---|---|---|---|---|
| Foundation-Sec-8B (base) | 8B | 0.745 | 0.655 | 5-shot pretrained reference |
| Foundation-Sec-Instruct-8B | 8B | 0.685 | 0.500 | 0-shot, our TARGET |
| CyberPal-2.0-20B (cyber-pal-security/CyberOss-2.0-20B) | 20B | 0.728* | 0.738* | independently verified at our protocol |
| CyberSecQwen-4B (this model) | 4B | 0.6664 ± 0.0023 | 0.5868 ± 0.0029 | 5-trial mean ± std |
| Gemma4Defense-2B (companion) | 2.3B | 0.6754 ± 0.0035 | 0.6042 ± 0.0090 | same recipe, different substrate |
| Qwen3-4B-Instruct-2507 (raw) | 4B | 0.519 | 0.473 | 0-shot, our base |
| Qwen3-4B-Base (raw) | 4B | 0.517 | 0.667 | 5-shot |
| Gemma-4-E4B-it (raw) | 5.1B effective | 0.618 | 0.666 | 0-shot |
| Gemma-4-E4B-base (raw) | 5.1B effective | 0.588 | 0.666 | 5-shot |
* Single-trial values from our independent reproduction.
Domain-specific knowledge limitations. The model is trained on cybersecurity domain text and is not a general assistant. Tasks outside this domain will produce lower-quality output than purpose-built general models.
Time-anchored training data. The CTI-RCM training cohort is drawn from 2021 records. Vulnerability classes that emerged or rose in prevalence after 2021 (e.g., AI/ML-specific weaknesses, recent supply-chain CWEs) are under-represented in training and will be classified less accurately.
English-only. All training and evaluation data are in English; multilingual cyber tasks will degrade.
CTI-RCM gap. Foundation-Sec-Instruct-8B remains stronger on CTI-RCM under this protocol (-1.9 point gap). Production deployments where CWE classification is the primary metric should benchmark both models on their specific input distribution.
No safety RLHF. The model is supervised-fine-tuned only; the training data emphasizes defensive-analyst framing but no formal reinforcement-learning safety alignment was applied.
Chat template note. The repository ships with a minimal training-aligned chat_template.jinja matching the format used during SFT (Qwen <|im_start|> / <|im_end|> user-and-assistant turns, no thinking-mode block). Inference via tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True) produces correctly-formatted prompts; downstream tooling that injects system prompts or thinking-mode toggles outside this template may degrade output quality.
Gemma4Defense-2B is a sister release fine-tuned with the same training corpus and hyperparameters, on the Gemma-4-E2B-it base. The two models converge to within 0.9 points on CTI-RCM (0.6664 Qwen vs 0.6754 Gemma, 5-trial mean) — the same recipe produces equivalent task performance across two distinct model families. The Gemma variant is licensed under the Gemma Terms of Use; CyberSecQwen-4B (Apache 2.0) is appropriate for use cases where Gemma terms are not a fit.
If you use this model, please cite:
@misc{cybersecqwen2026,
title = {CyberSecQwen-4B: A Compact CTI Specialist Fine-Tuned from Qwen3-4B-Instruct-2507 on AMD MI300X},
author = {Mulia, Samuel},
year = {2026},
publisher = {Hugging Face},
url = {https://huggingface.co/athena129/CyberSecQwen-4B}
}
The evaluation protocol is from:
@article{foundation-sec-8b,
title = {Foundation-Sec-8B: A Cybersecurity-Specialized Language Model},
author = {Cisco Foundation AI},
journal = {arXiv preprint arXiv:2504.21039},
year = {2025},
url = {https://arxiv.org/abs/2504.21039}
}
The benchmark is from:
@misc{cti-bench,
title = {CTI-Bench: A Benchmark Suite for Cybersecurity LLMs},
author = {Alam, Md Tanvirul and Bhusal, Dipkamal and Park, Youngja and Rastogi, Nidhi},
year = {2024},
url = {https://github.com/xashru/cti-bench}
}
6 commits