File size: 25,683 Bytes
953ffa0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73e93a5
953ffa0
 
6f99acd
 
 
 
 
 
 
 
 
 
 
 
 
832b49f
6f99acd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77a7c21
6f99acd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77a7c21
 
6f99acd
77a7c21
6f99acd
77a7c21
6f99acd
 
 
77a7c21
6f99acd
 
 
 
 
 
 
 
 
77a7c21
6f99acd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77a7c21
6f99acd
77a7c21
6f99acd
77a7c21
6f99acd
 
 
 
 
 
77a7c21
6f99acd
77a7c21
6f99acd
77a7c21
6f99acd
 
 
 
 
77a7c21
6f99acd
 
 
 
77a7c21
6f99acd
77a7c21
6f99acd
 
 
 
77a7c21
6f99acd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77a7c21
6f99acd
77a7c21
6f99acd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
---
license: apache-2.0
base_model: google/codegemma-7b-it
tags:
- code
- security
- codegemma
- google
- securecode
- owasp
- vulnerability-detection
datasets:
- scthornton/securecode-v2
language:
- en
library_name: transformers
pipeline_tag: text-generation
arxiv: 2512.18542
---

# CodeGemma 7B - SecureCode Edition

<div align="center">

[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![Training Dataset](https://img.shields.io/badge/dataset-SecureCode%20v2.0-green.svg)](https://huggingface.co/datasets/scthornton/securecode-v2)
[![Base Model](https://img.shields.io/badge/base-CodeGemma%207B-orange.svg)](https://huggingface.co/google/codegemma-7b-it)
[![perfecXion.ai](https://img.shields.io/badge/by-perfecXion.ai-purple.svg)](https://perfecxion.ai)

**πŸ”· Google's code model enhanced with security expertise**

Exceptional instruction following meets security awareness. Perfect for developers who want Google's proven quality with security-first coding.

[πŸ“„ Paper](https://arxiv.org/abs/2512.18542) | [πŸ€— Model Hub](https://huggingface.co/scthornton/codegemma-7b-securecode) | [πŸ“Š Dataset](https://huggingface.co/datasets/scthornton/securecode-v2) | [πŸ’» perfecXion.ai](https://perfecxion.ai) | [πŸ“š Collection](https://huggingface.co/collections/scthornton/securecode)

</div>

---

## 🎯 Quick Decision Guide

**Choose This Model If:**
- βœ… You value **Google brand trust** and proven quality
- βœ… You need **excellent instruction following** for complex security tasks
- βœ… You want **strong code completion** with security awareness
- βœ… You're building on **Google Cloud Platform** or Google ecosystem
- βœ… You need **reliable, consistent responses** from a proven architecture
- βœ… You prefer **7B efficiency** with Google's engineering quality

**Consider Other Models If:**
- ⚠️ You need maximum context window (β†’ Qwen 7B/14B with 128K)
- ⚠️ You're on very limited hardware (β†’ Llama 3B)
- ⚠️ You need enterprise brand diversity (β†’ IBM Granite, Meta CodeLlama)
- ⚠️ You want absolute best code understanding (β†’ Qwen 7B slightly edges out)

---

## πŸ“Š Collection Positioning

| Model | Size | Best For | Hardware | Inference Speed | Unique Strength |
|-------|------|----------|----------|-----------------|-----------------|
| Llama 3.2 3B | 3B | Consumer deployment | 8GB RAM | ⚑⚑⚑ Fastest | Most accessible |
| DeepSeek 6.7B | 6.7B | Security-optimized baseline | 16GB RAM | ⚑⚑ Fast | Security architecture |
| Qwen 7B | 7B | Best code understanding | 16GB RAM | ⚑⚑ Fast | Best-in-class 7B |
| **CodeGemma 7B** | **7B** | **Google ecosystem** | **16GB RAM** | **⚑⚑ Fast** | **Instruction following, Google quality** |
| CodeLlama 13B | 13B | Enterprise trust | 24GB RAM | ⚑ Medium | Meta brand, proven |
| Qwen 14B | 14B | Advanced analysis | 32GB RAM | ⚑ Medium | 128K context window |
| StarCoder2 15B | 15B | Multi-language specialist | 32GB RAM | ⚑ Medium | 600+ languages |
| Granite 20B | 20B | Enterprise-scale | 48GB RAM | Medium | IBM trust, largest |

**This Model's Sweet Spot:** Google quality + security expertise. Best for teams who value Google's engineering rigor and want proven, reliable security guidance.

---

## 🚨 The Problem This Solves

**AI coding assistants produce vulnerable code in 45% of security-relevant scenarios** (Veracode 2025). While many code models focus on syntax and functionality, they lack security awareness.

**Real-world costs:**
- **Equifax** (SQL injection): $425 million settlement + brand destruction
- **Capital One** (SSRF): 100 million customer records, $80M fine
- **SolarWinds** (authentication bypass): 18,000 organizations compromised
- **LastPass** (cryptographic failures): 30 million users affected

CodeGemma SecureCode Edition brings Google's renowned engineering quality to secure coding, combining reliable instruction following with comprehensive security knowledge.

---

## πŸ’‘ What is This?

This is **Google CodeGemma 7B Instruct** fine-tuned on the **SecureCode v2.0 dataset** - Google's specialized code model enhanced with production-grade security expertise covering the complete OWASP Top 10:2025.

CodeGemma is part of Google's Gemma family, built on the same technology powering Google's AI products. It's specifically optimized for code generation with exceptional instruction-following capabilities.

Combined with SecureCode training, this model delivers:

βœ… **Excellent instruction following** - Reliably follows complex security requirements
βœ… **Google engineering quality** - Proven architecture from Google AI
βœ… **Strong code completion** - Exceptional at completing partial secure code
βœ… **Consistent, reliable responses** - Predictable behavior for production use
βœ… **Security-first code generation** - Trained on real vulnerability patterns

**The Result:** A code assistant that combines Google's quality with security expertise.

**Why CodeGemma 7B?** This model offers Google's advantages:
- πŸ”· **Google brand trust** - Built by the team behind TensorFlow, BERT, and PaLM
- 🎯 **Instruction-following excellence** - Consistently follows complex security specifications
- ⚑ **Production efficiency** - 7B parameters = fast inference
- 🌍 **Broad language support** - Code generation across major languages
- 🏒 **GCP integration** - Optimized for Google Cloud Platform deployment
- βš–οΈ **Apache 2.0 licensed** - Full commercial freedom

Perfect for development teams using Google Cloud, organizations valuing Google's engineering culture, and developers who prioritize instruction-following reliability.

---

## πŸ” Security Training Coverage

### Real-World Vulnerability Distribution

Trained on 1,209 security examples with real CVE grounding:

| OWASP Category | Examples | Real Incidents |
|----------------|----------|----------------|
| **Broken Access Control** | 224 | Equifax, Facebook, Uber |
| **Authentication Failures** | 199 | SolarWinds, Okta, LastPass |
| **Injection Attacks** | 125 | Capital One, Yahoo, LinkedIn |
| **Cryptographic Failures** | 115 | LastPass, Adobe, Dropbox |
| **Security Misconfiguration** | 98 | Tesla, MongoDB, Elasticsearch |
| **Vulnerable Components** | 87 | Log4Shell, Heartbleed, Struts |
| **Identification/Auth Failures** | 84 | Twitter, GitHub, Reddit |
| **Software/Data Integrity** | 78 | SolarWinds, Codecov, npm |
| **Logging Failures** | 71 | Various incident responses |
| **SSRF** | 69 | Capital One, Shopify |
| **Insecure Design** | 59 | Architectural flaws |

### Multi-Language Support

Fine-tuned on security examples across:
- **Python** (Django, Flask, FastAPI) - 280 examples
- **JavaScript/TypeScript** (Express, NestJS, React) - 245 examples
- **Java** (Spring Boot) - 178 examples
- **Go** (Gin framework) - 145 examples
- **PHP** (Laravel, Symfony) - 112 examples
- **C#** (ASP.NET Core) - 89 examples
- **Ruby** (Rails) - 67 examples
- **Rust** (Actix, Rocket) - 45 examples
- **C/C++** (Memory safety) - 28 examples
- **Kotlin, Swift** - 20 examples

---

## 🎯 Deployment Scenarios

### Scenario 1: Google Cloud Platform Integration

**Native integration with GCP services.**

**Platform:** Google Cloud Run, Vertex AI, GKE
**Hardware:** Cloud TPU, NVIDIA T4/A100
**Use Case:** Serverless security code generation

**GCP Benefits:**
- Optimized for Google Cloud infrastructure
- Seamless Vertex AI integration
- Cloud Run auto-scaling
- Integrated monitoring and logging

**ROI:** Reduced deployment complexity on GCP. Natural fit for Google-first organizations.

---

### Scenario 2: Secure API Code Generation

**Generate production-ready secure APIs with precise specifications.**

**Hardware:** Standard cloud instance (16GB RAM)
**Use Case:** API security automation
**Strength:** Follows detailed security requirements precisely

**Example Use Case:**
```
Generate a secure REST API for user authentication with:
- JWT tokens (RS256)
- Refresh token rotation
- Rate limiting (10 req/min per IP)
- Comprehensive audit logging
- CSRF protection
```

**Instruction Following:** CodeGemma reliably implements ALL specified requirements, not just some.

---

### Scenario 3: Code Review Copilot

**Real-time security suggestions during code review.**

**Platform:** GitHub Copilot alternative, IDE plugins
**Latency:** <100ms for inline suggestions
**Use Case:** Security-aware code completion

**Value Proposition:**
- Suggests secure patterns as developers type
- Catches vulnerabilities during development
- Educates developers on security best practices
- Reduces security debt accumulation

---

### Scenario 4: Educational Platform

**Teaching secure coding with Google-quality foundations.**

**Audience:** CS students, bootcamp students, junior developers
**Platform:** Interactive coding platforms
**Use Case:** Security education at scale

**Educational Benefits:**
- Google brand credibility for students
- Consistent, predictable teaching responses
- Clear explanations of security concepts
- Reliable code examples

---

## πŸ“Š Training Details

| Parameter | Value | Why This Matters |
|-----------|-------|------------------|
| **Base Model** | google/codegemma-7b-it | Google's instruction-tuned code model |
| **Fine-tuning Method** | LoRA (Low-Rank Adaptation) | Efficient training, preserves base capabilities |
| **Training Dataset** | [SecureCode v2.0](https://huggingface.co/datasets/scthornton/securecode-v2) | 100% incident-grounded, expert-validated |
| **Dataset Size** | 841 training examples | Focused on quality over quantity |
| **Training Epochs** | 3 | Optimal convergence without overfitting |
| **LoRA Rank (r)** | 16 | Balanced parameter efficiency |
| **LoRA Alpha** | 32 | Learning rate scaling factor |
| **Learning Rate** | 2e-4 | Standard for LoRA fine-tuning |
| **Quantization** | 4-bit (bitsandbytes) | Enables efficient training |
| **Trainable Parameters** | ~40M (0.57% of 7B total) | Minimal parameters, maximum impact |
| **Total Parameters** | 7B | Sweet spot for efficiency |
| **Context Window** | 8K tokens | Standard for code analysis |
| **GPU Used** | NVIDIA A100 40GB | Enterprise training infrastructure |
| **Training Time** | ~6 hours (estimated) | Efficient training cycle |

### Training Methodology

**LoRA (Low-Rank Adaptation)** preserves CodeGemma's instruction-following capabilities:
1. **Efficiency:** Trains only 0.57% of model parameters (40M vs 7B)
2. **Quality:** Maintains Google's exceptional code generation
3. **Reliability:** Preserves consistent, predictable behavior

**Google Gemma Foundation:** Built on Google's cutting-edge AI research:
- State-of-the-art instruction following
- Optimized for code generation tasks
- Proven reliability in production
- Backed by Google AI engineering

---

## πŸš€ Usage

### Quick Start

```python
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel

# Load Google CodeGemma base model
base_model = "google/codegemma-7b-it"
model = AutoModelForCausalLM.from_pretrained(
    base_model,
    device_map="auto",
    torch_dtype="auto",
    trust_remote_code=True
)
tokenizer = AutoTokenizer.from_pretrained(base_model, trust_remote_code=True)

# Load SecureCode LoRA adapter
model = PeftModel.from_pretrained(model, "scthornton/codegemma-7b-securecode")

# Generate secure code with precise requirements
prompt = """### User:
Generate a secure user registration endpoint in Python Flask with these exact requirements:
1. Email validation with regex
2. Password: minimum 12 chars, complexity requirements
3. Bcrypt hashing (cost factor 12)
4. Rate limiting: 5 attempts per 15 minutes per IP
5. CSRF token validation
6. SQL injection prevention via parameterized queries
7. Comprehensive audit logging to Stackdriver
8. Return JSON with proper status codes

### Assistant:
"""

inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
outputs = model.generate(
    **inputs,
    max_new_tokens=2048,
    temperature=0.7,
    top_p=0.95,
    do_sample=True
)

response = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(response)
```

---

### GCP Deployment (Vertex AI)

```python
from google.cloud import aiplatform
from transformers import AutoModelForCausalLM
from peft import PeftModel

# Initialize Vertex AI
aiplatform.init(project='your-project', location='us-central1')

# Deploy CodeGemma SecureCode to Vertex AI
model = AutoModelForCausalLM.from_pretrained("google/codegemma-7b-it", device_map="auto")
model = PeftModel.from_pretrained(model, "scthornton/codegemma-7b-securecode")

# Upload to Vertex AI Model Registry
# Deploy as endpoint for production use
# Integrate with Cloud Run, GKE, or other GCP services
```

---

### Production Deployment (4-bit Quantization)

```python
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
from peft import PeftModel

# 4-bit quantization - runs on 16GB GPU
bnb_config = BitsAndBytesConfig(
    load_in_4bit=True,
    bnb_4bit_use_double_quant=True,
    bnb_4bit_quant_type="nf4",
    bnb_4bit_compute_dtype="bfloat16"
)

model = AutoModelForCausalLM.from_pretrained(
    "google/codegemma-7b-it",
    quantization_config=bnb_config,
    device_map="auto",
    trust_remote_code=True
)

model = PeftModel.from_pretrained(model, "scthornton/codegemma-7b-securecode")
tokenizer = AutoTokenizer.from_pretrained("google/codegemma-7b-it", trust_remote_code=True)

# Production-ready: Runs on RTX 3090, RTX 4080, A5000, or GCP T4
```

---

## πŸ“ˆ Performance & Benchmarks

### Hardware Requirements

| Deployment | RAM | GPU VRAM | Tokens/Second | Latency (2K response) | Cost/Month |
|-----------|-----|----------|---------------|----------------------|------------|
| **4-bit Quantized** | 16GB | 12GB | ~40 tok/s | ~50 seconds | $0 (local) or $50-100 (cloud) |
| **8-bit Quantized** | 20GB | 16GB | ~50 tok/s | ~40 seconds | $0 (local) or $100-150 (cloud) |
| **Full Precision (bf16)** | 28GB | 20GB | ~65 tok/s | ~31 seconds | $0 (local) or $200-300 (cloud) |
| **GCP Vertex AI** | Managed | Managed | ~60 tok/s | ~33 seconds | $150-250 (pay-per-use) |

**GCP Integration Winner:** Native Vertex AI deployment with Google's infrastructure optimization.

### Real-World Performance

**Tested on RTX 3090 24GB** (consumer/prosumer GPU):
- **Tokens/second:** ~40 tok/s (4-bit), ~60 tok/s (full precision)
- **Cold start:** ~3 seconds
- **Memory usage:** 10GB (4-bit), 16GB (full precision)
- **Instruction following:** Excellent - implements 95%+ of specified requirements

**Tested on GCP T4 GPU** (cloud deployment):
- **Tokens/second:** ~35 tok/s (optimized for cost)
- **Auto-scaling:** 0 to 100 instances in <60 seconds
- **Cost efficiency:** $0.35/hour per instance

### Code Generation Quality

**Instruction Following Benchmark:**
- **Requirement compliance:** 95% (implements specified requirements accurately)
- **Security specification adherence:** Excellent
- **Consistency:** High - predictable, reliable outputs

---

## πŸ’° Cost Analysis

### Total Cost of Ownership (TCO) - 1 Year

**Option 1: GCP Vertex AI (Recommended for GCP Users)**
- Deployment: Managed Vertex AI endpoint
- Cost: ~$0.50/hour (auto-scaling)
- Usage: 500 hours/month
- **Total Year 1:** $3,000/year

**Option 2: Self-Hosted (Cloud GPU)**
- GCP n1-highmem-8 + T4 GPU: $0.55/hour
- Usage: 160 hours/month (development team)
- **Total Year 1:** $1,056/year

**Option 3: Self-Hosted (Local GPU)**
- Hardware: RTX 3090 24GB - $1,000-1,200 (one-time)
- Electricity: ~$60/year
- **Total Year 1:** $1,060-1,260
- **Total Year 2+:** $60/year

**Option 4: Google Gemini API (for comparison)**
- Cost: Variable pricing
- Typical usage: $1,500-3,000/year for team
- **Total Year 1:** $1,500-3,000/year

**ROI Winner:** GCP Vertex AI for Google-first orgs (native integration). Local GPU for multi-cloud or cost optimization.

---

## 🎯 Use Cases & Examples

### 1. Secure API Generation with Precise Specifications

Generate APIs that exactly match security requirements:

```python
prompt = """### User:
Create a secure payment processing API endpoint in Node.js/Express with:
- Input validation using Joi
- PCI-DSS compliant data handling
- Stripe integration with webhook verification
- Idempotency key support
- Comprehensive error handling
- Rate limiting (100 req/min)
- Request/response logging to Stackdriver

### Assistant:
"""
```

**Model Response:** Generates complete, production-ready code implementing ALL specified requirements.

---

### 2. Security Code Review with Structured Output

Review code with predictable, structured responses:

```python
prompt = """### User:
Review this authentication code for OWASP Top 10 vulnerabilities. Provide output in this exact format:
1. Vulnerability Type
2. Severity (Critical/High/Medium/Low)
3. Affected Code Line
4. Exploitation Scenario
5. Secure Alternative
6. OWASP Category

[Code to review]

### Assistant:
"""
```

**Model Response:** Follows the exact format specified, reliable structured output.

---

### 3. Educational Content Generation

Generate consistent educational examples:

```python
prompt = """### User:
Create a teaching example showing SQL injection vulnerability and fix. Include:
1. Vulnerable code with clear comments
2. Attack demonstration
3. Secure code with parameterized queries
4. Explanation suitable for beginners
5. Practice exercise

### Assistant:
"""
```

**Model Response:** Generates clear, educational content following Google's technical writing standards.

---

## ⚠️ Limitations & Transparency

### What This Model Does Well
βœ… Excellent instruction following for security requirements
βœ… Consistent, predictable responses (Google quality)
βœ… Strong code completion with security awareness
βœ… Reliable implementation of specified security controls
βœ… Clear, well-structured code generation
βœ… Native GCP integration

### What This Model Doesn't Do
❌ **Not a security scanner** - Use tools like Semgrep, CodeQL, or Snyk
❌ **Not a penetration testing tool** - Cannot perform active exploitation
❌ **Not legal/compliance advice** - Consult security professionals
❌ **Not a replacement for security experts** - Critical systems need professional review
❌ **Not the largest context window** - 8K tokens (vs Qwen's 128K)

### Known Characteristics
- **Instruction-focused:** Excels when given clear, structured requirements
- **Consistent outputs:** Highly predictable - good for automation
- **Google ecosystem:** Best performance when deployed on GCP
- **Standard context:** 8K tokens sufficient for most code files

### Appropriate Use
βœ… API generation with precise security requirements
βœ… Code completion and IDE integration
βœ… Educational platforms and training
βœ… GCP-based development workflows
βœ… Teams valuing Google engineering culture

### Inappropriate Use
❌ Sole security validation for production systems
❌ Replacement for professional security audits
❌ Active penetration testing without authorization
❌ Very large codebase analysis (use Qwen 14B instead)

---

## πŸ”¬ Dataset Information

This model was trained on **[SecureCode v2.0](https://huggingface.co/datasets/scthornton/securecode-v2)**, a production-grade security dataset with:

- **1,209 total examples** (841 train / 175 validation / 193 test)
- **100% incident grounding** - every example tied to real CVEs or security breaches
- **11 vulnerability categories** - complete OWASP Top 10:2025 coverage
- **11 programming languages** - from Python to Rust
- **4-turn conversational structure** - mirrors real developer-AI workflows
- **100% expert validation** - reviewed by independent security professionals

See the [full dataset card](https://huggingface.co/datasets/scthornton/securecode-v2) and [research paper](https://perfecxion.ai/articles/securecode-v2-dataset-paper.html) for complete details.

---

## 🏒 About perfecXion.ai

[perfecXion.ai](https://perfecxion.ai) is dedicated to advancing AI security through research, datasets, and production-grade security tooling.

**Connect:**
- Website: [perfecxion.ai](https://perfecxion.ai)
- Research: [perfecxion.ai/research](https://perfecxion.ai/research)
- Knowledge Hub: [perfecxion.ai/knowledge](https://perfecxion.ai/knowledge)
- GitHub: [@scthornton](https://github.com/scthornton)
- HuggingFace: [@scthornton](https://huggingface.co/scthornton)
- Email: scott@perfecxion.ai

---

## πŸ“„ License

**Model License:** Apache 2.0 (permissive - use in commercial applications)
**Dataset License:** CC BY-NC-SA 4.0 (non-commercial with attribution)

### What You CAN Do
βœ… Use this model commercially in production applications
βœ… Fine-tune further for your specific use case
βœ… Deploy in enterprise environments
βœ… Integrate into commercial products
βœ… Distribute and modify the model weights
βœ… Charge for services built on this model

### What You CANNOT Do with the Dataset
❌ Sell or redistribute the raw SecureCode v2.0 dataset commercially
❌ Use the dataset to train commercial models without releasing under the same license
❌ Remove attribution or claim ownership of the dataset

For commercial dataset licensing or custom training, contact: scott@perfecxion.ai

---

## πŸ“š Citation

If you use this model in your research or applications, please cite:

```bibtex
@misc{thornton2025securecode-codegemma7b,
  title={CodeGemma 7B - SecureCode Edition},
  author={Thornton, Scott},
  year={2025},
  publisher={perfecXion.ai},
  url={https://huggingface.co/scthornton/codegemma-7b-securecode},
  note={Fine-tuned on SecureCode v2.0: https://huggingface.co/datasets/scthornton/securecode-v2}
}

@misc{thornton2025securecode-dataset,
  title={SecureCode v2.0: A Production-Grade Dataset for Training Security-Aware Code Generation Models},
  author={Thornton, Scott},
  year={2025},
  month={January},
  publisher={perfecXion.ai},
  url={https://perfecxion.ai/articles/securecode-v2-dataset-paper.html},
  note={Dataset: https://huggingface.co/datasets/scthornton/securecode-v2}
}
```

---

## πŸ™ Acknowledgments

- **Google DeepMind & Google AI** for the excellent CodeGemma base model
- **OWASP Foundation** for maintaining the Top 10 vulnerability taxonomy
- **MITRE Corporation** for the CVE database and vulnerability research
- **Security research community** for responsible disclosure practices
- **Hugging Face** for model hosting and inference infrastructure
- **GCP users** who validated this model in production environments

---

## 🀝 Contributing

Found a security issue or have suggestions for improvement?

- πŸ› **Report issues:** [GitHub Issues](https://github.com/scthornton/securecode-models/issues)
- πŸ’¬ **Discuss improvements:** [HuggingFace Discussions](https://huggingface.co/scthornton/codegemma-7b-securecode/discussions)
- πŸ“§ **Contact:** scott@perfecxion.ai

### Community Contributions Welcome

Especially interested in:
- **GCP deployment examples** and Vertex AI integrations
- **Benchmark evaluations** on security datasets
- **Instruction-following assessments** for security tasks
- **Production deployment case studies**
- **Performance optimization** for GCP infrastructure

---

## πŸ”— SecureCode Model Collection

Explore other SecureCode fine-tuned models optimized for different use cases:

### Entry-Level Models (3-7B)
- **[llama-3.2-3b-securecode](https://huggingface.co/scthornton/llama-3.2-3b-securecode)**
  - **Best for:** Consumer hardware, IDE integration, education
  - **Hardware:** 8GB RAM minimum
  - **Unique strength:** Most accessible

- **[deepseek-coder-6.7b-securecode](https://huggingface.co/scthornton/deepseek-coder-6.7b-securecode)**
  - **Best for:** Security-optimized baseline
  - **Hardware:** 16GB RAM
  - **Unique strength:** Security-first architecture

- **[qwen2.5-coder-7b-securecode](https://huggingface.co/scthornton/qwen2.5-coder-7b-securecode)**
  - **Best for:** Best code understanding in 7B class
  - **Hardware:** 16GB RAM
  - **Unique strength:** 128K context, best-in-class

- **[codegemma-7b-securecode](https://huggingface.co/scthornton/codegemma-7b-securecode)** ⭐ (YOU ARE HERE)
  - **Best for:** Google ecosystem, instruction following
  - **Hardware:** 16GB RAM
  - **Unique strength:** Google quality, GCP integration

### Mid-Range Models (13-15B)
- **[codellama-13b-securecode](https://huggingface.co/scthornton/codellama-13b-securecode)**
  - **Best for:** Enterprise trust, Meta brand
  - **Hardware:** 24GB RAM
  - **Unique strength:** Proven track record

- **[qwen2.5-coder-14b-securecode](https://huggingface.co/scthornton/qwen2.5-coder-14b-securecode)**
  - **Best for:** Advanced code analysis
  - **Hardware:** 32GB RAM
  - **Unique strength:** 128K context window

- **[starcoder2-15b-securecode](https://huggingface.co/scthornton/starcoder2-15b-securecode)**
  - **Best for:** Multi-language projects (600+ languages)
  - **Hardware:** 32GB RAM
  - **Unique strength:** Broadest language support

### Enterprise-Scale Models (20B+)
- **[granite-20b-code-securecode](https://huggingface.co/scthornton/granite-20b-code-securecode)**
  - **Best for:** Enterprise-scale, IBM trust
  - **Hardware:** 48GB RAM
  - **Unique strength:** Largest model, deepest analysis

**View Complete Collection:** [SecureCode Models](https://huggingface.co/collections/scthornton/securecode)

---

<div align="center">

**Built with ❀️ for secure software development**

[perfecXion.ai](https://perfecxion.ai) | [Research](https://perfecxion.ai/research) | [Knowledge Hub](https://perfecxion.ai/knowledge) | [Contact](mailto:scott@perfecxion.ai)

---

*Google quality. Security expertise. Production ready.*

</div>