Text Generation
PEFT
Safetensors
code
English
security
cybersecurity
secure-coding
ai-security
owasp
code-generation
lora
fine-tuned
securecode
conversational
Run this model with HF Jobs
Run scthornton/granite-20b-code-securecode 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/scthornton/granite-20b-code-securecode. 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/scthornton/granite-20b-code-securecode 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/scthornton/granite-20b-code-securecode. 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/scthornton/granite-20b-code-securecode. 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.
Instructions to use scthornton/granite-20b-code-securecode with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use scthornton/granite-20b-code-securecode with PEFT:
from peft import PeftModel from transformers import AutoModelForCausalLM base_model = AutoModelForCausalLM.from_pretrained("ibm-granite/granite-20b-code-instruct-8k") model = PeftModel.from_pretrained(base_model, "scthornton/granite-20b-code-securecode") - Notebooks
- Google Colab
- Kaggle
Model save
Browse filesFiles changed (3)
- README.md+37-184
- tokenizer.json+28-12
- tokenizer_config.json+7-159
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207---license: apache-2.0base_model: ibm-granite/granite-20b-code-instruct-8ktags:- security- cybersecurity- secure-coding- ai-security- owasp- code-generation- qlora- lora- fine-tuned- securecodedatasets:- scthornton/securecodelibrary_name: peftpipeline_tag: text-generationlanguage:- code- en---# Granite 20B Code SecureCode<div align="center">**Security-specialized code model fine-tuned on the [SecureCode](https://huggingface.co/datasets/scthornton/securecode) dataset**[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)</div>---## What This Model DoesThis model generates **secure code** when developers ask about building features. Instead of producing vulnerable implementations (like 45% of AI-generated code does), it:- Identifies the security risks in common coding patterns- Provides vulnerable *and* secure implementations side by side- Explains how attackers would exploit the vulnerability- Includes defense-in-depth guidance: logging, monitoring, SIEM integration, infrastructure hardeningThe model was fine-tuned on **2,185 security training examples** covering both traditional web security (OWASP Top 10 2021) and AI/ML security (OWASP LLM Top 10 2025).## Model Details| | ||---|---|| **Base Model** | [Granite 20B Code Instruct 8K](https://huggingface.co/ibm-granite/granite-20b-code-instruct-8k) || **Parameters** | 20B || **Architecture** | GPT-BigCode || **Tier** | Tier 4: XL Model || **Method** | QLoRA (4-bit NormalFloat quantization) || **LoRA Rank** | 8 (alpha=16) || **Target Modules** | `attn.c_attn, attn.c_proj, mlp.c_fc, mlp.c_proj` (4 modules) || **Training Data** | [scthornton/securecode](https://huggingface.co/datasets/scthornton/securecode) (2,185 examples) || **Hardware** | NVIDIA A100 40GB |Largest model in the collection. IBM's enterprise-grade code model with 8K context. Deepest security reasoning capabilities.## Quick Start```pythonfrom peft import PeftModelfrom transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfigimport torch# Load with 4-bit quantization (matches training)bnb_config = BitsAndBytesConfig(load_in_4bit=True,bnb_4bit_quant_type="nf4",bnb_4bit_compute_dtype=torch.bfloat16,)base_model = AutoModelForCausalLM.from_pretrained("ibm-granite/granite-20b-code-instruct-8k",quantization_config=bnb_config,device_map="auto",)tokenizer = AutoTokenizer.from_pretrained("scthornton/granite-20b-code-securecode")model = PeftModel.from_pretrained(base_model, "scthornton/granite-20b-code-securecode")# Ask a security-relevant coding questionmessages = [{"role": "user", "content": "How do I implement JWT authentication with refresh tokens in Python?"}]inputs = tokenizer.apply_chat_template(messages, return_tensors="pt").to(model.device)outputs = model.generate(inputs, max_new_tokens=2048, temperature=0.7)print(tokenizer.decode(outputs[0], skip_special_tokens=True))```## Training Details### DatasetTrained on the full **[SecureCode](https://huggingface.co/datasets/scthornton/securecode)** unified dataset:- **2,185 total examples** (1,435 web security + 750 AI/ML security)- **20 vulnerability categories** across OWASP Top 10 2021 and OWASP LLM Top 10 2025- **12+ programming languages** and **49+ frameworks**- **4-turn conversational structure**: feature request, vulnerable/secure implementations, advanced probing, operational guidance- **100% incident grounding**: every example tied to real CVEs, vendor advisories, or published attack research### Hyperparameters| Parameter | Value ||-----------|-------|| LoRA rank | 8 || LoRA alpha | 16 || LoRA dropout | 0.05 || Target modules | 4 linear layers || Quantization | 4-bit NormalFloat (NF4) || Learning rate | 2e-4 || LR scheduler | Cosine with 100-step warmup || Epochs | 3 || Per-device batch size | 1 || Gradient accumulation | 16x || Effective batch size | 16 || Max sequence length | 2048 tokens || Optimizer | paged_adamw_8bit || Precision | bf16 |**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.## Security Coverage### Web Security (1,435 examples)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.Languages: Python, JavaScript, Java, Go, PHP, C#, TypeScript, Ruby, Rust, Kotlin, YAML.### AI/ML Security (750 examples)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.Frameworks: LangChain, OpenAI, Anthropic, HuggingFace, LlamaIndex, ChromaDB, Pinecone, FastAPI, Flask, vLLM, CrewAI, and 30+ more.## SecureCode Model CollectionThis model is part of the **SecureCode** collection of 8 security-specialized models:| Model | Base | Size | Tier | HuggingFace ||-------|------|------|------|-------------|| 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) || 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) || 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) || CodeGemma SecureCode | google/codegemma-7b-it | 7B | Mid-size | [`codegemma-7b-securecode`](https://huggingface.co/scthornton/codegemma-7b-securecode) || CodeLlama SecureCode | codellama/CodeLlama-13b-Instruct-hf | 13B | Large | [`codellama-13b-securecode`](https://huggingface.co/scthornton/codellama-13b-securecode) || 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) || StarCoder2 SecureCode | bigcode/starcoder2-15b-instruct-v0.1 | 15B | Large | [`starcoder2-15b-securecode`](https://huggingface.co/scthornton/starcoder2-15b-securecode) || 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) |Choose based on your deployment constraints: **3B** for edge/mobile, **7B** for general use, **13B-15B** for deeper reasoning, **20B** for maximum capability.## SecureCode Dataset Family| Dataset | Examples | Focus | Link ||---------|----------|-------|------|| **SecureCode** | 2,185 | Unified (web + AI/ML) | [scthornton/securecode](https://huggingface.co/datasets/scthornton/securecode) || SecureCode Web | 1,435 | Web security (OWASP Top 10 2021) | [scthornton/securecode-web](https://huggingface.co/datasets/scthornton/securecode-web) || SecureCode AI/ML | 750 | AI/ML security (OWASP LLM Top 10 2025) | [scthornton/securecode-aiml](https://huggingface.co/datasets/scthornton/securecode-aiml) |## Intended Use**Use this model for:**- Training AI coding assistants to write secure code- Security education and training- Vulnerability research and secure code review- Building security-aware development tools**Do not use this model for:**- Offensive exploitation or automated attack generation- Circumventing security controls- Any activity that violates the base model's license## Citation```bibtex@misc{thornton2026securecode,title={SecureCode: A Production-Grade Multi-Turn Dataset for Training Security-Aware Code Generation Models},author={Thornton, Scott},year={2026},publisher={perfecXion.ai},url={https://huggingface.co/datasets/scthornton/securecode},note={arXiv:2512.18542}}```## Links- **Dataset**: [scthornton/securecode](https://huggingface.co/datasets/scthornton/securecode)- **Research Paper**: [arXiv:2512.18542](https://arxiv.org/abs/2512.18542)- **Model Collection**: [huggingface.co/collections/scthornton/securecode](https://huggingface.co/collections/scthornton/securecode)- **Author**: [perfecXion.ai](https://perfecxion.ai)## LicenseThis 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**.123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960---library_name: peftlicense: apache-2.0base_model: ibm-granite/granite-20b-code-instruct-8ktags:- base_model:adapter:ibm-granite/granite-20b-code-instruct-8k- lora- transformerspipeline_tag: text-generationmodel-index:- name: granite-20b-code-securecoderesults: []---<!-- This model card has been generated automatically according to the information the Trainer had access to. Youshould probably proofread and complete it, then remove this comment. --># granite-20b-code-securecodeThis model is a fine-tuned version of [ibm-granite/granite-20b-code-instruct-8k](https://huggingface.co/ibm-granite/granite-20b-code-instruct-8k) on the None dataset.## Model descriptionMore information needed## Intended uses & limitationsMore information needed## Training and evaluation dataMore information needed## Training procedure### Training hyperparametersThe following hyperparameters were used during training:- learning_rate: 0.0002- train_batch_size: 1- eval_batch_size: 8- seed: 42- gradient_accumulation_steps: 16- total_train_batch_size: 16- optimizer: Use paged_adamw_8bit with betas=(0.9,0.999) and epsilon=1e-08 and optimizer_args=No additional optimizer arguments- lr_scheduler_type: cosine- lr_scheduler_warmup_steps: 100- num_epochs: 3### Training results### Framework versions- PEFT 0.18.1- Transformers 5.1.0- Pytorch 2.7.1+cu128- Datasets 2.21.0- Tokenizers 0.22.2
190 unmodified lines1911921931941951961971981992002012022032042052062072082092102114 unmodified lines216217218219220221222223190 unmodified lines],"normalizer": null,"pre_tokenizer": {"type": "Sequence","pretokenizers": [{"type": "Digits","individual_digits": true},{"type": "ByteLevel","add_prefix_space": false,"trim_offsets": true,"use_regex": true}]},"post_processor": null,"decoder": {"type": "ByteLevel","add_prefix_space": true,4 unmodified lines"type": "BPE","dropout": null,"unk_token": null,"continuing_subword_prefix": null,"end_of_word_suffix": null,"fuse_unk": false,"byte_fallback": false,"ignore_merges": false,190 unmodified lines1911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262274 unmodified lines232233234235236237238239190 unmodified lines],"normalizer": null,"pre_tokenizer": {"type": "ByteLevel","add_prefix_space": false,"trim_offsets": true,"use_regex": true},"post_processor": {"type": "TemplateProcessing","single": [{"Sequence": {"id": "A","type_id": 0}}],"pair": [{"Sequence": {"id": "A","type_id": 0}},{"Sequence": {"id": "B","type_id": 1}}],"special_tokens": {}},"decoder": {"type": "ByteLevel","add_prefix_space": true,4 unmodified lines"type": "BPE","dropout": null,"unk_token": null,"continuing_subword_prefix": "","end_of_word_suffix": "","fuse_unk": false,"byte_fallback": false,"ignore_merges": false,
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916014 unmodified lines175176177178179180181182183184{"add_prefix_space": false,"added_tokens_decoder": {"0": {"content": "<|endoftext|>","lstrip": false,"normalized": false,"rstrip": false,"single_word": false,"special": true},"1": {"content": "<fim_prefix>","lstrip": false,"normalized": false,"rstrip": false,"single_word": false,"special": true},"2": {"content": "<fim_middle>","lstrip": false,"normalized": false,"rstrip": false,"single_word": false,"special": true},"3": {"content": "<fim_suffix>","lstrip": false,"normalized": false,"rstrip": false,"single_word": false,"special": true},"4": {"content": "<fim_pad>","lstrip": false,"normalized": false,"rstrip": false,"single_word": false,"special": true},"5": {"content": "<filename>","lstrip": false,"normalized": false,"rstrip": false,"single_word": false,"special": true},"6": {"content": "<gh_stars>","lstrip": false,"normalized": false,"rstrip": false,"single_word": false,"special": true},"7": {"content": "<issue_start>","lstrip": false,"normalized": false,"rstrip": false,"single_word": false,"special": true},"8": {"content": "<issue_comment>","lstrip": false,"normalized": false,"rstrip": false,"single_word": false,"special": true},"9": {"content": "<issue_closed>","lstrip": false,"normalized": false,"rstrip": false,"single_word": false,"special": true},"10": {"content": "<jupyter_start>","lstrip": false,"normalized": false,"rstrip": false,"single_word": false,"special": true},"11": {"content": "<jupyter_text>","lstrip": false,"normalized": false,"rstrip": false,"single_word": false,"special": true},"12": {"content": "<jupyter_code>","lstrip": false,"normalized": false,"rstrip": false,"single_word": false,"special": true},"13": {"content": "<jupyter_output>","lstrip": false,"normalized": false,"rstrip": false,"single_word": false,"special": true},"14": {"content": "<empty_output>","lstrip": false,"normalized": false,"rstrip": false,"single_word": false,"special": true},"15": {"content": "<commit_before>","lstrip": false,"normalized": false,"rstrip": false,"single_word": false,"special": true},"16": {"content": "<commit_msg>","lstrip": false,"normalized": false,"rstrip": false,"single_word": false,"special": true},"17": {"content": "<commit_after>","lstrip": false,"normalized": false,"rstrip": false,"single_word": false,"special": true},"18": {"content": "<reponame>","lstrip": false,"normalized": false,"rstrip": false,"single_word": false,"special": true}},"additional_special_tokens": ["<|endoftext|>","<fim_prefix>","<fim_middle>",14 unmodified lines"<commit_after>","<reponame>"],"bos_token": "<|endoftext|>","clean_up_tokenization_spaces": true,"eos_token": "<|endoftext|>","extra_special_tokens": {},"model_max_length": 8192,"pad_token": "<|endoftext|>","padding_side": "right",123456789101114 unmodified lines26272829303132{"add_prefix_space": false,"backend": "tokenizers","bos_token": "<|endoftext|>","clean_up_tokenization_spaces": true,"eos_token": "<|endoftext|>","errors": "replace","extra_special_tokens": ["<|endoftext|>","<fim_prefix>","<fim_middle>",14 unmodified lines"<commit_after>","<reponame>"],"is_local": false,"model_max_length": 8192,"pad_token": "<|endoftext|>","padding_side": "right",
README.md+37-184
tokenizer.json+28-12
tokenizer_config.json+7-159