Functional and Secure Code Generation with Task Vectors
Not on the map. Why?
Abstract (arXiv)
Large language models (LLMs) are increasingly used for code generation, but they struggle to generate functional code free of security vulnerabilities. Prior work to improve the secure code generation abilities of such coding LLMs has largely focused on evaluating code functionality and security separately using different datasets, or focused on finding vulnerabilities post-generation. At the same time, the text-generation domain has seen significant work on alignment techniques, where models are tuned such that their outputs exhibit certain qualities (e.g., helpfulness, harmlessness). Of particular interest is task-vector arithmetic, where linear operations on LLM weights can be used to arbitrarily enhance alignment while incurring only minimal computational overhead. We develop a novel method, SecVecCoder, leveraging task vectors to produce trustworthy code that is simultaneously functional and secure without the need for post-generation adjustment. Across six coding LLMs from three families on the CodeGuard+ benchmark, SecVecCoder improves the rate of trustworthy code completions by 2.1-36.0 percentage points over the base model, with improvements on unseen CWE types reaching up to 39.1 percentage points. Since the effectiveness of the coding LLM relies only on changing the model weights, SecVecCoder requires no method-specific decoding and hence achieves a decoding latency within 0.6% of the base model's, on average.
Key facts. No citing papers in the map yet (data through 14 Oct 2026). Builds on 27 of its 35 references that are in the map. First posted on arXiv 8 Jul 2026.
Builds on
27 of 35 references.
References · 27
- 2022Training language models to follow instructions with human feedbackcited by 15,971
- 2021LoRA: Low-Rank Adaptation of Large Language Modelscited by 14,380
- 2021Evaluating Large Language Models Trained on Codecited by 8,320
- 2023Direct Preference Optimization: Your Language Model is Secretly a Reward Modelcited by 8,065
- 2021Program Synthesis with Large Language Modelscited by 3,637
- 2023Code Llama: Open Foundation Models for Codecited by 2,139
- 2022Model soups: averaging weights of multiple fine-tuned models improves accuracy without increasing inference timecited by 1,396
- 2024Qwen2.5-Coder Technical Reportcited by 1,203
- 2024DeepSeek-Coder: When the Large Language Model Meets Programming -- The Rise of Code Intelligencecited by 1,181
- 2022Editing Models with Task Arithmeticcited by 1,120
- 2023TIES-Merging: Resolving Interference When Merging Modelscited by 818
- 2023WizardCoder: Empowering Code Large Language Models with Evol-Instructcited by 733
15 more
- 2024StarCoder 2 and The Stack v2: The Next Generationcited by 502
- 2021Asleep at the Keyboard? Assessing the Security of GitHub Copilot's Code Contributionscited by 431
- 2022Do Users Write More Insecure Code with AI Assistants?cited by 192
- 2023Large Language Models for Code: Security Hardening and Adversarial Testingcited by 155
- 2024CodeGemma: Open Code Models Based on Gemmacited by 150
- 2024Vulnerability Detection with Code Language Models: How Far Are We?cited by 139
- 2021Examining Zero-Shot Vulnerability Repair with Large Language Modelscited by 105
- 2022Lost at C: A User Study on the Security Implications of Large Language Model Code Assistantscited by 91
- 2024Instruction Tuning for Secure Code Generationcited by 68
- 2023A Survey on Large Language Models for Software Engineeringcited by 59
- 2024Constrained Decoding for Secure Code Generationcited by 37
- 2025Steering Language Models with Weight Arithmeticcited by 20
- 2023A User-centered Security Evaluation of Copilotcited by 15
- 2025Teaching an Old LLM Secure Coding: Localized Preference Optimization on Distilled Preferencescited by 10
- 2026DeepGuard: Secure Code Generation via Multi-Layer Semantic Aggregationcited by 2
Built on by
Not cited yet.