scthornton commited on
Commit
c2824ae
·
verified ·
1 Parent(s): 4d99962

Update model card: audited SecureCode 2,372 dataset, bf16 LoRA on DGX Spark GB10

Browse files
Files changed (1) hide show
  1. README.md +154 -84
README.md CHANGED
@@ -1,143 +1,213 @@
1
  ---
2
- library_name: peft
3
- pipeline_tag: text-generation
4
  license: apache-2.0
5
- language:
6
- - code
7
- base_model:
8
- - ibm-granite/granite-20b-code-instruct-8k
9
  tags:
10
- - securecode
11
- - security
12
- - owasp
13
- - code-generation
14
- - secure-coding
15
- - lora
16
- - qlora
17
- - vulnerability-detection
18
- - cybersecurity
19
  datasets:
20
- - scthornton/securecode
21
- model-index:
22
- - name: granite-20b-code-securecode
23
- results: []
 
 
24
  ---
25
 
26
  # Granite 20B Code SecureCode
27
 
28
- [![Parameters](https://img.shields.io/badge/parameters-20B-blue.svg)](#model-details) [![Dataset](https://img.shields.io/badge/dataset-2,185_examples-green.svg)](https://huggingface.co/datasets/scthornton/securecode) [![OWASP](https://img.shields.io/badge/OWASP-Top_10_2021_+_LLM_Top_10-red.svg)](#security-coverage) [![Method](https://img.shields.io/badge/method-QLoRA-purple.svg)](#training-details) [![License](https://img.shields.io/badge/license-Apache_2.0-orange.svg)](https://opensource.org/licenses/Apache-2.0)
29
 
30
- **Enterprise flagship security-aware code generation model (IBM-grade trust). Fine-tuned on 2,185 real-world vulnerability examples covering OWASP Top 10 2021 and OWASP LLM Top 10 2025.**
 
 
 
31
 
32
- [Dataset](https://huggingface.co/datasets/scthornton/securecode) | [Paper](https://huggingface.co/papers/2512.18542) | [Model Collection](https://huggingface.co/collections/scthornton/securecode) | [perfecXion.ai](https://perfecxion.ai) | [Blog Post](https://huggingface.co/blog/scthornton/securecode-models)
 
 
 
 
33
 
34
  ---
35
 
36
  ## What This Model Does
37
 
38
- Granite 20B Code SecureCode generates security-aware code by teaching the model to recognize vulnerability patterns and produce secure implementations. Every training example includes:
39
 
40
- - **Real-world incident grounding** Tied to documented CVEs and breach reports
41
- - **Vulnerable + secure implementations** Side-by-side comparison
42
- - **Attack demonstrations** Concrete exploit code
43
- - **Defense-in-depth guidance** — SIEM rules, logging, monitoring, infrastructure hardening
44
 
45
- ---
46
 
47
  ## Model Details
48
 
49
- | Property | Value |
50
- |----------|-------|
51
- | **Base Model** | [ibm-granite/granite-20b-code-instruct-8k](https://huggingface.co/ibm-granite/granite-20b-code-instruct-8k) |
52
  | **Parameters** | 20B |
53
- | **Architecture** | GPT (IBM Granite Code) |
54
- | **Method** | QLoRA (4-bit quantization + LoRA) |
55
- | **LoRA Rank** | 16 |
56
- | **LoRA Alpha** | 32 |
57
- | **Training Data** | [scthornton/securecode](https://huggingface.co/datasets/scthornton/securecode) (2,185 examples) |
58
- | **Training Time** | ~1h 19min |
59
- | **Hardware** | 2x NVIDIA A100 40GB (GCP) |
60
- | **Framework** | PEFT 0.18.1, Transformers 5.1.0, PyTorch 2.7.1 |
61
 
62
- ---
63
 
64
  ## Quick Start
65
 
66
  ```python
67
- from transformers import AutoModelForCausalLM, AutoTokenizer
68
  from peft import PeftModel
 
 
 
 
 
 
 
 
 
69
 
70
  base_model = AutoModelForCausalLM.from_pretrained(
71
  "ibm-granite/granite-20b-code-instruct-8k",
 
72
  device_map="auto",
73
- load_in_4bit=True
74
  )
75
- model = PeftModel.from_pretrained(base_model, "scthornton/granite-20b-code-securecode")
76
  tokenizer = AutoTokenizer.from_pretrained("scthornton/granite-20b-code-securecode")
 
 
 
 
 
 
77
 
78
- prompt = "Write a secure JWT authentication handler in Python with proper token validation"
79
- inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
80
- outputs = model.generate(**inputs, max_new_tokens=512, temperature=0.7)
81
  print(tokenizer.decode(outputs[0], skip_special_tokens=True))
82
  ```
83
 
84
- ---
85
-
86
  ## Training Details
87
 
88
- | Hyperparameter | Value |
89
- |----------------|-------|
90
- | Learning Rate | 2e-4 |
91
- | Batch Size | 1 |
92
- | Gradient Accumulation | 16 |
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93
  | Epochs | 3 |
94
- | Scheduler | Cosine |
95
- | Warmup Steps | 100 |
96
- | Optimizer | paged_adamw_8bit |
97
- | Final Loss | 1.639 |
 
 
 
98
 
99
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
100
 
101
  ## SecureCode Model Collection
102
 
103
- | Model | Parameters | Base | Training Time | Link |
104
- |-------|------------|------|---------------|------|
105
- | Llama 3.2 3B | 3B | Meta Llama 3.2 | 1h 5min | [scthornton/llama-3.2-3b-securecode](https://huggingface.co/scthornton/llama-3.2-3b-securecode) |
106
- | Qwen Coder 7B | 7B | Qwen 2.5 Coder | 1h 24min | [scthornton/qwen-coder-7b-securecode](https://huggingface.co/scthornton/qwen-coder-7b-securecode) |
107
- | CodeGemma 7B | 7B | Google CodeGemma | 1h 27min | [scthornton/codegemma-7b-securecode](https://huggingface.co/scthornton/codegemma-7b-securecode) |
108
- | DeepSeek Coder 6.7B | 6.7B | DeepSeek Coder | 1h 15min | [scthornton/deepseek-coder-6.7b-securecode](https://huggingface.co/scthornton/deepseek-coder-6.7b-securecode) |
109
- | CodeLlama 13B | 13B | Meta CodeLlama | 1h 32min | [scthornton/codellama-13b-securecode](https://huggingface.co/scthornton/codellama-13b-securecode) |
110
- | Qwen Coder 14B | 14B | Qwen 2.5 Coder | 1h 19min | [scthornton/qwen2.5-coder-14b-securecode](https://huggingface.co/scthornton/qwen2.5-coder-14b-securecode) |
111
- | StarCoder2 15B | 15B | BigCode StarCoder2 | 1h 40min | [scthornton/starcoder2-15b-securecode](https://huggingface.co/scthornton/starcoder2-15b-securecode) |
112
- | **Granite 20B** | **20B** | **IBM Granite Code** | **1h 19min** | **This model** |
113
 
114
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
 
116
  ## Citation
117
 
118
  ```bibtex
119
- @misc{thornton2025securecode,
120
- title={SecureCode v2.0: A Production-Grade Dataset for Training Security-Aware Code Generation Models},
121
  author={Thornton, Scott},
122
- year={2025},
123
  publisher={perfecXion.ai},
124
- url={https://perfecxion.ai/articles/securecode-v2-dataset-paper.html},
125
- note={Model: https://huggingface.co/scthornton/granite-20b-code-securecode}
126
  }
127
  ```
128
 
129
- ---
130
-
131
  ## Links
132
 
133
- - **Dataset**: [scthornton/securecode](https://huggingface.co/datasets/scthornton/securecode) (2,185 examples)
134
- - **Paper**: [SecureCode v2.0](https://huggingface.co/papers/2512.18542)
135
- - **Model Collection**: [SecureCode Models](https://huggingface.co/collections/scthornton/securecode) (8 models)
136
- - **Blog Post**: [Training Security-Aware Code Models](https://huggingface.co/blog/scthornton/securecode-models)
137
- - **Publisher**: [perfecXion.ai](https://perfecxion.ai)
138
-
139
- ---
140
 
141
  ## License
142
 
143
- Apache 2.0
 
1
  ---
 
 
2
  license: apache-2.0
3
+ base_model: ibm-granite/granite-20b-code-instruct-8k
 
 
 
4
  tags:
5
+ - security
6
+ - cybersecurity
7
+ - secure-coding
8
+ - ai-security
9
+ - owasp
10
+ - code-generation
11
+ - lora
12
+ - fine-tuned
13
+ - securecode
14
  datasets:
15
+ - scthornton/securecode
16
+ library_name: peft
17
+ pipeline_tag: text-generation
18
+ language:
19
+ - code
20
+ - en
21
  ---
22
 
23
  # Granite 20B Code SecureCode
24
 
25
+ <div align="center">
26
 
27
+ ![Parameters](https://img.shields.io/badge/params-20B-blue.svg)
28
+ ![Dataset](https://img.shields.io/badge/dataset-2,372_examples-green.svg)
29
+ ![OWASP](https://img.shields.io/badge/OWASP-Top_10_2021_+_LLM_Top_10_2025-orange.svg)
30
+ ![Method](https://img.shields.io/badge/method-bf16_LoRA-purple.svg)
31
 
32
+ **Security-specialized code model fine-tuned on the [SecureCode](https://huggingface.co/datasets/scthornton/securecode) dataset**
33
+
34
+ [Dataset](https://huggingface.co/datasets/scthornton/securecode) | [Paper (arXiv:2512.18542)](https://arxiv.org/abs/2512.18542) | [Model Collection](https://huggingface.co/collections/scthornton/securecode) | [perfecXion.ai](https://perfecxion.ai)
35
+
36
+ </div>
37
 
38
  ---
39
 
40
  ## What This Model Does
41
 
42
+ This model generates **secure code** when developers ask about building features. Instead of producing vulnerable implementations (like 45% of AI-generated code does), it:
43
 
44
+ - Identifies the security risks in common coding patterns
45
+ - Provides vulnerable *and* secure implementations side by side
46
+ - Explains how attackers would exploit the vulnerability
47
+ - Includes defense-in-depth guidance: logging, monitoring, SIEM integration, infrastructure hardening
48
 
49
+ The model was fine-tuned on **2,372 security training examples** covering both traditional web security (OWASP Top 10 2021) and AI/ML security (OWASP LLM Top 10 2025).
50
 
51
  ## Model Details
52
 
53
+ | | |
54
+ |---|---|
55
+ | **Base Model** | [Granite 20B Code Instruct 8K](https://huggingface.co/ibm-granite/granite-20b-code-instruct-8k) |
56
  | **Parameters** | 20B |
57
+ | **Architecture** | GPT-BigCode |
58
+ | **Tier** | Tier 4: XL Model |
59
+ | **Method** | bf16 LoRA (no quantization) |
60
+ | **LoRA Rank** | 8 (alpha=16) |
61
+ | **Target Modules** | `attn.c_attn, attn.c_proj, mlp.c_fc, mlp.c_proj` (4 modules) |
62
+ | **Training Data** | [scthornton/securecode](https://huggingface.co/datasets/scthornton/securecode) (2,372 examples) |
63
+ | **Hardware** | NVIDIA DGX Spark GB10 (Blackwell, unified memory) |
 
64
 
65
+ Largest model in the collection. IBM's enterprise-grade code model with 8K context. Deepest security reasoning capabilities.
66
 
67
  ## Quick Start
68
 
69
  ```python
 
70
  from peft import PeftModel
71
+ from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
72
+ import torch
73
+
74
+ # Optional: 4-bit quantization for low-VRAM inference (training was bf16 LoRA)
75
+ bnb_config = BitsAndBytesConfig(
76
+ load_in_4bit=True,
77
+ bnb_4bit_quant_type="nf4",
78
+ bnb_4bit_compute_dtype=torch.bfloat16,
79
+ )
80
 
81
  base_model = AutoModelForCausalLM.from_pretrained(
82
  "ibm-granite/granite-20b-code-instruct-8k",
83
+ quantization_config=bnb_config,
84
  device_map="auto",
 
85
  )
 
86
  tokenizer = AutoTokenizer.from_pretrained("scthornton/granite-20b-code-securecode")
87
+ model = PeftModel.from_pretrained(base_model, "scthornton/granite-20b-code-securecode")
88
+
89
+ # Ask a security-relevant coding question
90
+ messages = [
91
+ {"role": "user", "content": "How do I implement JWT authentication with refresh tokens in Python?"}
92
+ ]
93
 
94
+ inputs = tokenizer.apply_chat_template(messages, return_tensors="pt").to(model.device)
95
+ outputs = model.generate(inputs, max_new_tokens=2048, temperature=0.7)
 
96
  print(tokenizer.decode(outputs[0], skip_special_tokens=True))
97
  ```
98
 
 
 
99
  ## Training Details
100
 
101
+ ### Dataset
102
+
103
+ Trained on the full **[SecureCode](https://huggingface.co/datasets/scthornton/securecode)** unified dataset:
104
+
105
+ - **2,372 total examples** (1,625 web security + 747 AI/ML security)
106
+ - **20 vulnerability categories** across OWASP Top 10 2021 and OWASP LLM Top 10 2025
107
+ - **12+ programming languages** and **49+ frameworks**
108
+ - **4-turn conversational structure**: feature request, vulnerable/secure implementations, advanced probing, operational guidance
109
+ - **100% incident grounding**: every example tied to real CVEs, vendor advisories, or published attack research
110
+
111
+ ### Hyperparameters
112
+
113
+ | Parameter | Value |
114
+ |-----------|-------|
115
+ | LoRA rank | 8 |
116
+ | LoRA alpha | 16 |
117
+ | LoRA dropout | 0.05 |
118
+ | Target modules | 4 linear layers |
119
+ | Quantization | None (bf16 base weights) |
120
+ | Learning rate | 2e-4 |
121
+ | LR scheduler | Cosine with 100-step warmup |
122
  | Epochs | 3 |
123
+ | Per-device batch size | 1 |
124
+ | Gradient accumulation | 16x |
125
+ | Effective batch size | 16 |
126
+ | Max sequence length | 2048 tokens |
127
+ | Optimizer | adamw_torch_fused |
128
+ | Attention | PyTorch SDPA (fused) |
129
+ | Precision | bf16 |
130
 
131
+ **Notes:** Reduced LoRA rank (8) and max sequence length (2048) for A100 40GB memory. Gradient checkpointing with `use_reentrant=False`. Max gradient norm 1.0.
132
+
133
+ ## Security Coverage
134
+
135
+ ### Web Security (1,625 examples)
136
+
137
+ OWASP Top 10 2021: Broken Access Control, Cryptographic Failures, Injection, Insecure Design, Security Misconfiguration, Vulnerable Components, Authentication Failures, Software Integrity Failures, Logging/Monitoring Failures, SSRF.
138
+
139
+ Languages: Python, JavaScript, Java, Go, PHP, C#, TypeScript, Ruby, Rust, Kotlin, YAML.
140
+
141
+ ### AI/ML Security (747 examples)
142
+
143
+ OWASP LLM Top 10 2025: Prompt Injection, Sensitive Information Disclosure, Supply Chain Vulnerabilities, Data/Model Poisoning, Improper Output Handling, Excessive Agency, System Prompt Leakage, Vector/Embedding Weaknesses, Misinformation, Unbounded Consumption.
144
+
145
+ Frameworks: LangChain, OpenAI, Anthropic, HuggingFace, LlamaIndex, ChromaDB, Pinecone, FastAPI, Flask, vLLM, CrewAI, and 30+ more.
146
 
147
  ## SecureCode Model Collection
148
 
149
+ This model is part of the **SecureCode** collection of 9 security-specialized models:
 
 
 
 
 
 
 
 
 
150
 
151
+ | Model | Base | Size | Tier | HuggingFace |
152
+ |-------|------|------|------|-------------|
153
+ | Llama 3.2 SecureCode | meta-llama/Llama-3.2-3B-Instruct | 3B | Accessible | [`llama-3.2-3b-securecode`](https://huggingface.co/scthornton/llama-3.2-3b-securecode) |
154
+ | Gemma 4 E4B SecureCode | google/gemma-4-E4B-it | E4B (8B raw) | Accessible | [`gemma-4-e4b-securecode`](https://huggingface.co/scthornton/gemma-4-e4b-securecode) |
155
+ | Qwen2.5 Coder SecureCode | Qwen/Qwen2.5-Coder-7B-Instruct | 7B | Mid-size | [`qwen2.5-coder-7b-securecode`](https://huggingface.co/scthornton/qwen2.5-coder-7b-securecode) |
156
+ | DeepSeek Coder SecureCode | deepseek-ai/deepseek-coder-6.7b-instruct | 6.7B | Mid-size | [`deepseek-coder-6.7b-securecode`](https://huggingface.co/scthornton/deepseek-coder-6.7b-securecode) |
157
+ | CodeGemma SecureCode | google/codegemma-7b-it | 7B | Mid-size | [`codegemma-7b-securecode`](https://huggingface.co/scthornton/codegemma-7b-securecode) |
158
+ | CodeLlama SecureCode | codellama/CodeLlama-13b-Instruct-hf | 13B | Large | [`codellama-13b-securecode`](https://huggingface.co/scthornton/codellama-13b-securecode) |
159
+ | Qwen2.5 Coder 14B SecureCode | Qwen/Qwen2.5-Coder-14B-Instruct | 14B | Large | [`qwen2.5-coder-14b-securecode`](https://huggingface.co/scthornton/qwen2.5-coder-14b-securecode) |
160
+ | StarCoder2 SecureCode | bigcode/starcoder2-15b-instruct-v0.1 | 15B | Large | [`starcoder2-15b-securecode`](https://huggingface.co/scthornton/starcoder2-15b-securecode) |
161
+ | Granite 20B Code SecureCode | ibm-granite/granite-20b-code-instruct-8k | 20B | XL | [`granite-20b-code-securecode`](https://huggingface.co/scthornton/granite-20b-code-securecode) |
162
+
163
+ Choose based on your deployment constraints: **3B** for edge/mobile, **7B** for general use, **13B-15B** for deeper reasoning, **20B** for maximum capability.
164
+
165
+ ## SecureCode Dataset Family
166
+
167
+ | Dataset | Examples | Focus | Link |
168
+ |---------|----------|-------|------|
169
+ | **SecureCode** | 2,372 | Unified (web + AI/ML) | [scthornton/securecode](https://huggingface.co/datasets/scthornton/securecode) |
170
+ | SecureCode Web | 1,625 | Web security (OWASP Top 10 2021) | [scthornton/securecode-web](https://huggingface.co/datasets/scthornton/securecode-web) |
171
+ | SecureCode AI/ML | 747 | AI/ML security (OWASP LLM Top 10 2025) | [scthornton/securecode-aiml](https://huggingface.co/datasets/scthornton/securecode-aiml) |
172
+
173
+ ## Intended Use
174
+
175
+ **Use this model for:**
176
+ - Training AI coding assistants to write secure code
177
+ - Security education and training
178
+ - Vulnerability research and secure code review
179
+ - Building security-aware development tools
180
+
181
+ **Do not use this model for:**
182
+ - Offensive exploitation or automated attack generation
183
+ - Circumventing security controls
184
+ - Any activity that violates the base model's license
185
+
186
+ ## Changelog
187
+
188
+ - **2026-07 (v2, current)**: Retrained on the audited SecureCode release (**2,372 examples**: 1,625 web + 747 AI/ML) using **bf16 LoRA on an NVIDIA DGX Spark GB10 (Blackwell)**. Same LoRA shape and hyperparameters as v1, except: no quantization during training, optimizer adamw_torch_fused instead of paged_adamw_8bit, PyTorch SDPA attention, dynamic per-batch padding. A new family member, [gemma-4-e4b-securecode](https://huggingface.co/scthornton/gemma-4-e4b-securecode), was added in this refresh.
189
+ - **v1 (2026-02)**: QLoRA 4-bit NF4 on NVIDIA A100 40GB, trained on the pre-audit 2,185-example dataset.
190
 
191
  ## Citation
192
 
193
  ```bibtex
194
+ @misc{thornton2026securecode,
195
+ title={SecureCode: A Production-Grade Multi-Turn Dataset for Training Security-Aware Code Generation Models},
196
  author={Thornton, Scott},
197
+ year={2026},
198
  publisher={perfecXion.ai},
199
+ url={https://huggingface.co/datasets/scthornton/securecode},
200
+ note={arXiv:2512.18542}
201
  }
202
  ```
203
 
 
 
204
  ## Links
205
 
206
+ - **Dataset**: [scthornton/securecode](https://huggingface.co/datasets/scthornton/securecode)
207
+ - **Research Paper**: [arXiv:2512.18542](https://arxiv.org/abs/2512.18542)
208
+ - **Model Collection**: [huggingface.co/collections/scthornton/securecode](https://huggingface.co/collections/scthornton/securecode)
209
+ - **Author**: [perfecXion.ai](https://perfecxion.ai)
 
 
 
210
 
211
  ## License
212
 
213
+ This model is released under the **apache-2.0** license (inherited from the base model). The training dataset ([SecureCode](https://huggingface.co/datasets/scthornton/securecode)) is licensed under **CC BY-NC-SA 4.0**.