Text Generation
PEFT
Safetensors
English
code
python
cybersecurity
vulnerability-detection
vulnerability-repair
secure-code-generation
conversational
Instructions to use abkmystery/PySecPatch-7B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use abkmystery/PySecPatch-7B with PEFT:
from peft import PeftModel from transformers import AutoModelForCausalLM base_model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen2.5-Coder-7B-Instruct") model = PeftModel.from_pretrained(base_model, "abkmystery/PySecPatch-7B") - Notebooks
- Google Colab
- Kaggle
Publish PySecPatch 0.1.1
Browse files- .gitattributes +1 -0
- CITATION.cff +16 -0
- LICENSE +183 -0
- README.md +123 -0
- SHA256SUMS.txt +9 -0
- adapter_config.json +48 -0
- adapter_model.safetensors +3 -0
- chat_template.jinja +54 -0
- tokenizer.json +3 -0
- tokenizer_config.json +30 -0
- training_metadata.json +68 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
CITATION.cff
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
cff-version: 1.2.0
|
| 2 |
+
message: "If you use PySecPatch-7B, please cite the model and accompanying paper."
|
| 3 |
+
title: "PySecPatch-7B: Defensive Python Security Adapter"
|
| 4 |
+
type: software
|
| 5 |
+
authors:
|
| 6 |
+
- family-names: Bin Khalid
|
| 7 |
+
given-names: Ahmed
|
| 8 |
+
email: ahmed.khalid2108@gmail.com
|
| 9 |
+
orcid: "https://orcid.org/0000-0002-0616-2604"
|
| 10 |
+
affiliation: "Independent Researcher"
|
| 11 |
+
version: 0.1.1
|
| 12 |
+
doi: "10.5281/zenodo.21015885"
|
| 13 |
+
date-released: 2026-06-28
|
| 14 |
+
license: Apache-2.0
|
| 15 |
+
repository-code: "https://github.com/abkmystery/PySecPatch"
|
| 16 |
+
url: "https://huggingface.co/abkmystery/PySecPatch-7B"
|
LICENSE
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Apache License
|
| 2 |
+
Version 2.0, January 2004
|
| 3 |
+
http://www.apache.org/licenses/
|
| 4 |
+
|
| 5 |
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
| 6 |
+
|
| 7 |
+
1. Definitions.
|
| 8 |
+
|
| 9 |
+
"License" shall mean the terms and conditions for use, reproduction, and
|
| 10 |
+
distribution as defined by Sections 1 through 9 of this document.
|
| 11 |
+
|
| 12 |
+
"Licensor" shall mean the copyright owner or entity authorized by the copyright
|
| 13 |
+
owner that is granting the License.
|
| 14 |
+
|
| 15 |
+
"Legal Entity" shall mean the union of the acting entity and all other entities
|
| 16 |
+
that control, are controlled by, or are under common control with that entity.
|
| 17 |
+
For the purposes of this definition, "control" means (i) the power, direct or
|
| 18 |
+
indirect, to cause the direction or management of such entity, whether by
|
| 19 |
+
contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
| 20 |
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
| 21 |
+
|
| 22 |
+
"You" (or "Your") shall mean an individual or Legal Entity exercising
|
| 23 |
+
permissions granted by this License.
|
| 24 |
+
|
| 25 |
+
"Source" form shall mean the preferred form for making modifications, including
|
| 26 |
+
but not limited to software source code, documentation source, and configuration
|
| 27 |
+
files.
|
| 28 |
+
|
| 29 |
+
"Object" form shall mean any form resulting from mechanical transformation or
|
| 30 |
+
translation of a Source form, including but not limited to compiled object code,
|
| 31 |
+
generated documentation, and conversions to other media types.
|
| 32 |
+
|
| 33 |
+
"Work" shall mean the work of authorship, whether in Source or Object form, made
|
| 34 |
+
available under the License, as indicated by a copyright notice that is included
|
| 35 |
+
in or attached to the work (an example is provided in the Appendix below).
|
| 36 |
+
|
| 37 |
+
"Derivative Works" shall mean any work, whether in Source or Object form, that
|
| 38 |
+
is based on (or derived from) the Work and for which the editorial revisions,
|
| 39 |
+
annotations, elaborations, or other modifications represent, as a whole, an
|
| 40 |
+
original work of authorship. For the purposes of this License, Derivative Works
|
| 41 |
+
shall not include works that remain separable from, or merely link (or bind by
|
| 42 |
+
name) to the interfaces of, the Work and Derivative Works thereof.
|
| 43 |
+
|
| 44 |
+
"Contribution" shall mean any work of authorship, including the original version
|
| 45 |
+
of the Work and any modifications or additions to that Work or Derivative Works
|
| 46 |
+
thereof, that is intentionally submitted to Licensor for inclusion in the Work
|
| 47 |
+
by the copyright owner or by an individual or Legal Entity authorized to submit
|
| 48 |
+
on behalf of the copyright owner. For the purposes of this definition,
|
| 49 |
+
"submitted" means any form of electronic, verbal, or written communication sent
|
| 50 |
+
to the Licensor or its representatives, including but not limited to
|
| 51 |
+
communication on electronic mailing lists, source code control systems, and
|
| 52 |
+
issue tracking systems that are managed by, or on behalf of, the Licensor for
|
| 53 |
+
the purpose of discussing and improving the Work, but excluding communication
|
| 54 |
+
that is conspicuously marked or otherwise designated in writing by the copyright
|
| 55 |
+
owner as "Not a Contribution."
|
| 56 |
+
|
| 57 |
+
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf
|
| 58 |
+
of whom a Contribution has been received by Licensor and subsequently
|
| 59 |
+
incorporated within the Work.
|
| 60 |
+
|
| 61 |
+
2. Grant of Copyright License. Subject to the terms and conditions of this
|
| 62 |
+
License, each Contributor hereby grants to You a perpetual, worldwide,
|
| 63 |
+
non-exclusive, no-charge, royalty-free, irrevocable copyright license to
|
| 64 |
+
reproduce, prepare Derivative Works of, publicly display, publicly perform,
|
| 65 |
+
sublicense, and distribute the Work and such Derivative Works in Source or Object
|
| 66 |
+
form.
|
| 67 |
+
|
| 68 |
+
3. Grant of Patent License. Subject to the terms and conditions of this License,
|
| 69 |
+
each Contributor hereby grants to You a perpetual, worldwide, non-exclusive,
|
| 70 |
+
no-charge, royalty-free, irrevocable (except as stated in this section) patent
|
| 71 |
+
license to make, have made, use, offer to sell, sell, import, and otherwise
|
| 72 |
+
transfer the Work, where such license applies only to those patent claims
|
| 73 |
+
licensable by such Contributor that are necessarily infringed by their
|
| 74 |
+
Contribution(s) alone or by combination of their Contribution(s) with the Work
|
| 75 |
+
to which such Contribution(s) was submitted. If You institute patent litigation
|
| 76 |
+
against any entity (including a cross-claim or counterclaim in a lawsuit)
|
| 77 |
+
alleging that the Work or a Contribution incorporated within the Work
|
| 78 |
+
constitutes direct or contributory patent infringement, then any patent licenses
|
| 79 |
+
granted to You under this License for that Work shall terminate as of the date
|
| 80 |
+
such litigation is filed.
|
| 81 |
+
|
| 82 |
+
4. Redistribution. You may reproduce and distribute copies of the Work or
|
| 83 |
+
Derivative Works thereof in any medium, with or without modifications, and in
|
| 84 |
+
Source or Object form, provided that You meet the following conditions:
|
| 85 |
+
|
| 86 |
+
(a) You must give any other recipients of the Work or Derivative Works a copy of
|
| 87 |
+
this License; and
|
| 88 |
+
|
| 89 |
+
(b) You must cause any modified files to carry prominent notices stating that
|
| 90 |
+
You changed the files; and
|
| 91 |
+
|
| 92 |
+
(c) You must retain, in the Source form of any Derivative Works that You
|
| 93 |
+
distribute, all copyright, patent, trademark, and attribution notices from the
|
| 94 |
+
Source form of the Work, excluding those notices that do not pertain to any part
|
| 95 |
+
of the Derivative Works; and
|
| 96 |
+
|
| 97 |
+
(d) If the Work includes a "NOTICE" text file as part of its distribution, then
|
| 98 |
+
any Derivative Works that You distribute must include a readable copy of the
|
| 99 |
+
attribution notices contained within such NOTICE file, excluding those notices
|
| 100 |
+
that do not pertain to any part of the Derivative Works, in at least one of the
|
| 101 |
+
following places: within a NOTICE text file distributed as part of the
|
| 102 |
+
Derivative Works; within the Source form or documentation, if provided along
|
| 103 |
+
with the Derivative Works; or, within a display generated by the Derivative Works,
|
| 104 |
+
if and wherever such third-party notices normally appear. The contents of the
|
| 105 |
+
NOTICE file are for informational purposes only and do not modify the License.
|
| 106 |
+
You may add Your own attribution notices within Derivative Works that You
|
| 107 |
+
distribute, alongside or as an addendum to the NOTICE text from the Work,
|
| 108 |
+
provided that such additional attribution notices cannot be construed as
|
| 109 |
+
modifying the License.
|
| 110 |
+
|
| 111 |
+
You may add Your own copyright statement to Your modifications and may provide
|
| 112 |
+
additional or different license terms and conditions for use, reproduction, or
|
| 113 |
+
distribution of Your modifications, or for any such Derivative Works as a whole,
|
| 114 |
+
provided Your use, reproduction, and distribution of the Work otherwise complies
|
| 115 |
+
with the conditions stated in this License.
|
| 116 |
+
|
| 117 |
+
5. Submission of Contributions. Unless You explicitly state otherwise, any
|
| 118 |
+
Contribution intentionally submitted for inclusion in the Work by You to the
|
| 119 |
+
Licensor shall be under the terms and conditions of this License, without any
|
| 120 |
+
additional terms or conditions. Notwithstanding the above, nothing herein shall
|
| 121 |
+
supersede or modify the terms of any separate license agreement you may have
|
| 122 |
+
executed with Licensor regarding such Contributions.
|
| 123 |
+
|
| 124 |
+
6. Trademarks. This License does not grant permission to use the trade names,
|
| 125 |
+
trademarks, service marks, or product names of the Licensor, except as required
|
| 126 |
+
for reasonable and customary use in describing the origin of the Work and
|
| 127 |
+
reproducing the content of the NOTICE file.
|
| 128 |
+
|
| 129 |
+
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in
|
| 130 |
+
writing, Licensor provides the Work (and each Contributor provides its
|
| 131 |
+
Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
| 132 |
+
either express or implied, including, without limitation, any warranties or
|
| 133 |
+
conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
| 134 |
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
| 135 |
+
appropriateness of using or redistributing the Work and assume any risks
|
| 136 |
+
associated with Your exercise of permissions under this License.
|
| 137 |
+
|
| 138 |
+
8. Limitation of Liability. In no event and under no legal theory, whether in
|
| 139 |
+
tort (including negligence), contract, or otherwise, unless required by
|
| 140 |
+
applicable law (such as deliberate and grossly negligent acts) or agreed to in
|
| 141 |
+
writing, shall any Contributor be liable to You for damages, including any direct,
|
| 142 |
+
indirect, special, incidental, or consequential damages of any character arising
|
| 143 |
+
as a result of this License or out of the use or inability to use the Work
|
| 144 |
+
(including but not limited to damages for loss of goodwill, work stoppage,
|
| 145 |
+
computer failure or malfunction, or any and all other commercial damages or
|
| 146 |
+
losses), even if such Contributor has been advised of the possibility of such
|
| 147 |
+
damages.
|
| 148 |
+
|
| 149 |
+
9. Accepting Warranty or Additional Liability. While redistributing the Work or
|
| 150 |
+
Derivative Works thereof, You may choose to offer, and charge a fee for,
|
| 151 |
+
acceptance of support, warranty, indemnity, or other liability obligations and/or
|
| 152 |
+
rights consistent with this License. However, in accepting such obligations, You
|
| 153 |
+
may act only on Your own behalf and on Your sole responsibility, not on behalf of
|
| 154 |
+
any other Contributor, and only if You agree to indemnify, defend, and hold each
|
| 155 |
+
Contributor harmless for any liability incurred by, or claims asserted against,
|
| 156 |
+
such Contributor by reason of your accepting any such warranty or additional
|
| 157 |
+
liability.
|
| 158 |
+
|
| 159 |
+
END OF TERMS AND CONDITIONS
|
| 160 |
+
|
| 161 |
+
APPENDIX: How to apply the Apache License to your work.
|
| 162 |
+
|
| 163 |
+
To apply the Apache License to your work, attach the following boilerplate
|
| 164 |
+
notice, with the fields enclosed by brackets "[]" replaced with your own
|
| 165 |
+
identifying information. (Don't include the brackets!) The text should be
|
| 166 |
+
enclosed in the appropriate comment syntax for the file format. We also
|
| 167 |
+
recommend that a file or class name and description of purpose be included on
|
| 168 |
+
the same "printed page" as the copyright notice for easier identification within
|
| 169 |
+
third-party archives.
|
| 170 |
+
|
| 171 |
+
Copyright [yyyy] [name of copyright owner]
|
| 172 |
+
|
| 173 |
+
Licensed under the Apache License, Version 2.0 (the "License");
|
| 174 |
+
you may not use this file except in compliance with the License.
|
| 175 |
+
You may obtain a copy of the License at
|
| 176 |
+
|
| 177 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 178 |
+
|
| 179 |
+
Unless required by applicable law or agreed to in writing, software
|
| 180 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
| 181 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 182 |
+
See the License for the specific language governing permissions and
|
| 183 |
+
limitations under the License.
|
README.md
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
base_model: Qwen/Qwen2.5-Coder-7B-Instruct
|
| 3 |
+
library_name: peft
|
| 4 |
+
pipeline_tag: text-generation
|
| 5 |
+
license: apache-2.0
|
| 6 |
+
language:
|
| 7 |
+
- en
|
| 8 |
+
tags:
|
| 9 |
+
- code
|
| 10 |
+
- python
|
| 11 |
+
- cybersecurity
|
| 12 |
+
- vulnerability-detection
|
| 13 |
+
- vulnerability-repair
|
| 14 |
+
- secure-code-generation
|
| 15 |
+
datasets:
|
| 16 |
+
- abkmystery/PySecPatch-72K
|
| 17 |
+
---
|
| 18 |
+
|
| 19 |
+
# PySecPatch-7B
|
| 20 |
+
|
| 21 |
+
PySecPatch-7B is a defensive Python security adapter for `Qwen/Qwen2.5-Coder-7B-Instruct`. It is designed for vulnerability triage, CWE classification, security explanation, and candidate secure-code generation. It should be used with human review and automated verification.
|
| 22 |
+
|
| 23 |
+
**Author:** Ahmed Bin Khalid, Independent Researcher ([ORCID 0000-0002-0616-2604](https://orcid.org/0000-0002-0616-2604))
|
| 24 |
+
|
| 25 |
+
This repository contains the PEFT adapter, tokenizer files, training metadata, and chat template. The Qwen base weights are not redistributed.
|
| 26 |
+
|
| 27 |
+
## Evaluation
|
| 28 |
+
|
| 29 |
+
### Family-disjoint holdout
|
| 30 |
+
|
| 31 |
+
The final adapter and unmodified base were evaluated on the same 3,200 records.
|
| 32 |
+
|
| 33 |
+
| Metric | Base | PySecPatch |
|
| 34 |
+
|---|---:|---:|
|
| 35 |
+
| Classification accuracy | 4.81% | 90.72% |
|
| 36 |
+
| Classification F1 | 9.18% | 93.40% |
|
| 37 |
+
| Strict JSON | 91.53% | 99.44% |
|
| 38 |
+
| Clean-negative preservation | 0.00% | 100.00% |
|
| 39 |
+
| Security-control pass | 1.63% | 88.08% |
|
| 40 |
+
| Normalized exact repair | 0.17% | 83.33% |
|
| 41 |
+
| Parseable fixed code | 6.42% | 99.21% |
|
| 42 |
+
|
| 43 |
+
Paired classification yielded 2,770 adapter-only correct predictions and 21 base-only correct predictions across 3,200 records (`log10(p) = -787.25`, exact two-sided McNemar).
|
| 44 |
+
|
| 45 |
+
### External and repository evaluation
|
| 46 |
+
|
| 47 |
+
On the pinned SALLM scored subset, PySecPatch achieved 26.77% functional pass, 31.88% security-test pass, and 9.58% secure-functional pass. Four of 100 prompts lacked upstream fixtures.
|
| 48 |
+
|
| 49 |
+
Repository-format holdout performance was 38.00% patch application and 34.38% security-control pass. On a frozen 24-case repository suite, vulnerability detection and clean preservation were perfect, but none of 12 vulnerable patches passed every acceptance gate. These results do not support autonomous repair or state-of-the-art claims.
|
| 50 |
+
|
| 51 |
+
## Training
|
| 52 |
+
|
| 53 |
+
The adapter was trained in two consecutive QLoRA stages. Stage A used 8,400 train records from a 12,000-record corpus. Stage B continued from that adapter using 48,000 train records from a separate 60,000-record corpus. Validation, test, and holdout splits never entered optimization.
|
| 54 |
+
|
| 55 |
+
Both corpora contain generated Python examples and are released under Apache-2.0. The combined dataset repository contains 72,000 records spanning 43 CWEs in the second stage and 35 CWEs in the first stage.
|
| 56 |
+
|
| 57 |
+
## Usage
|
| 58 |
+
|
| 59 |
+
```python
|
| 60 |
+
from peft import PeftModel
|
| 61 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 62 |
+
|
| 63 |
+
base = "Qwen/Qwen2.5-Coder-7B-Instruct"
|
| 64 |
+
adapter = "abkmystery/PySecPatch-7B"
|
| 65 |
+
|
| 66 |
+
tokenizer = AutoTokenizer.from_pretrained(adapter)
|
| 67 |
+
model = AutoModelForCausalLM.from_pretrained(base, device_map="auto")
|
| 68 |
+
model = PeftModel.from_pretrained(model, adapter)
|
| 69 |
+
```
|
| 70 |
+
|
| 71 |
+
Use the system instruction:
|
| 72 |
+
|
| 73 |
+
```text
|
| 74 |
+
You are PySecPatch, a defensive Python secure coding model. Identify vulnerabilities, explain risk, and produce minimal safe patches. Return strict JSON only.
|
| 75 |
+
```
|
| 76 |
+
|
| 77 |
+
The expected response keys are `is_vulnerable`, `cwe`, `vuln_type`, `vulnerable_lines`, `explanation`, `fixed_code`, `patch_summary`, and `safe_test`.
|
| 78 |
+
|
| 79 |
+
## Intended Use
|
| 80 |
+
|
| 81 |
+
- Defensive analysis of user-supplied Python code.
|
| 82 |
+
- Candidate finding classification and CWE identification.
|
| 83 |
+
- Security explanations and review assistance.
|
| 84 |
+
- Candidate snippet repairs subject to tests and human review.
|
| 85 |
+
- Research on security specialization and generalization.
|
| 86 |
+
|
| 87 |
+
## Limitations
|
| 88 |
+
|
| 89 |
+
- External secure-functional generation is substantially weaker than controlled holdout performance.
|
| 90 |
+
- Repository-level unified diffs often fail to apply or pass verification.
|
| 91 |
+
- Line localization is moderate (`F1 = 0.4407`).
|
| 92 |
+
- The training corpora are generated rather than mined from real repositories.
|
| 93 |
+
- The model can miss vulnerabilities and can produce plausible but incomplete repairs.
|
| 94 |
+
|
| 95 |
+
Do not use PySecPatch for autonomous deployment, unauthorized scanning, exploit development, or offensive automation.
|
| 96 |
+
|
| 97 |
+
## Reproducibility
|
| 98 |
+
|
| 99 |
+
Adapter model SHA-256:
|
| 100 |
+
|
| 101 |
+
```text
|
| 102 |
+
4c2b5c7c0d2982b99de9c319e998274fc12f3aae5bf8d2c3b5db58c5864dc65b
|
| 103 |
+
```
|
| 104 |
+
|
| 105 |
+
Full evaluation reports, raw predictions, frozen hashes, and scripts are linked from the GitHub and archival releases.
|
| 106 |
+
|
| 107 |
+
Training dataset: [`10.5281/zenodo.21016753`](https://doi.org/10.5281/zenodo.21016753).
|
| 108 |
+
|
| 109 |
+
## Citation
|
| 110 |
+
|
| 111 |
+
```bibtex
|
| 112 |
+
@software{khalid2026pysecpatch,
|
| 113 |
+
author = {Bin Khalid, Ahmed},
|
| 114 |
+
title = {PySecPatch: Defensive Python Vulnerability Triage and Repair Research Artifacts},
|
| 115 |
+
year = {2026},
|
| 116 |
+
version = {0.1.1},
|
| 117 |
+
url = {https://github.com/abkmystery/PySecPatch}
|
| 118 |
+
}
|
| 119 |
+
```
|
| 120 |
+
|
| 121 |
+
Released under the Apache License 2.0. See `LICENSE`.
|
| 122 |
+
|
| 123 |
+
Current software archive: [`10.5281/zenodo.21015885`](https://doi.org/10.5281/zenodo.21015885). All versions: [`10.5281/zenodo.21015503`](https://doi.org/10.5281/zenodo.21015503).
|
SHA256SUMS.txt
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
eb09a53c96e81a089c5c2e9cfe356ab450a6093b3d81f4885f5c7447388d1a39 adapter_config.json
|
| 2 |
+
4c2b5c7c0d2982b99de9c319e998274fc12f3aae5bf8d2c3b5db58c5864dc65b adapter_model.safetensors
|
| 3 |
+
cd8e9439f0570856fd70470bf8889ebd8b5d1107207f67a5efb46e342330527f chat_template.jinja
|
| 4 |
+
337c42ffd6b43349403283bc3dea7ed22900d08bce9edc8246f94167d1c7865e CITATION.cff
|
| 5 |
+
b1bf03230164f7ab55ecd2284689b7bd7d7d5488e5bbb920b34b93e99f65a5b0 LICENSE
|
| 6 |
+
9e79a5e4a77a9c7394c78c5b128c0a8bbdea428449c920cd3cd000515addd2c6 README.md
|
| 7 |
+
3fd169731d2cbde95e10bf356d66d5997fd885dd8dbb6fb4684da3f23b2585d8 tokenizer.json
|
| 8 |
+
8b6f658e2435ec8da6866013cb485a1d2a6559bed4bf76ed99ea68b031854b41 tokenizer_config.json
|
| 9 |
+
48bfdb7e76558b2ef3be78cbf26bb6de53736f8e9500b585b3b0f71e424925ac training_metadata.json
|
adapter_config.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"alora_invocation_tokens": null,
|
| 3 |
+
"alpha_pattern": {},
|
| 4 |
+
"arrow_config": null,
|
| 5 |
+
"auto_mapping": null,
|
| 6 |
+
"base_model_name_or_path": "Qwen/Qwen2.5-Coder-7B-Instruct",
|
| 7 |
+
"bias": "none",
|
| 8 |
+
"corda_config": null,
|
| 9 |
+
"ensure_weight_tying": false,
|
| 10 |
+
"eva_config": null,
|
| 11 |
+
"exclude_modules": null,
|
| 12 |
+
"fan_in_fan_out": false,
|
| 13 |
+
"inference_mode": true,
|
| 14 |
+
"init_lora_weights": true,
|
| 15 |
+
"layer_replication": null,
|
| 16 |
+
"layers_pattern": null,
|
| 17 |
+
"layers_to_transform": null,
|
| 18 |
+
"loftq_config": {},
|
| 19 |
+
"lora_alpha": 32,
|
| 20 |
+
"lora_bias": false,
|
| 21 |
+
"lora_dropout": 0.05,
|
| 22 |
+
"lora_ga_config": null,
|
| 23 |
+
"megatron_config": null,
|
| 24 |
+
"megatron_core": "megatron.core",
|
| 25 |
+
"modules_to_save": null,
|
| 26 |
+
"peft_type": "LORA",
|
| 27 |
+
"peft_version": "0.19.1",
|
| 28 |
+
"qalora_group_size": 16,
|
| 29 |
+
"r": 16,
|
| 30 |
+
"rank_pattern": {},
|
| 31 |
+
"revision": null,
|
| 32 |
+
"target_modules": [
|
| 33 |
+
"down_proj",
|
| 34 |
+
"gate_proj",
|
| 35 |
+
"q_proj",
|
| 36 |
+
"o_proj",
|
| 37 |
+
"up_proj",
|
| 38 |
+
"v_proj",
|
| 39 |
+
"k_proj"
|
| 40 |
+
],
|
| 41 |
+
"target_parameters": null,
|
| 42 |
+
"task_type": "CAUSAL_LM",
|
| 43 |
+
"trainable_token_indices": null,
|
| 44 |
+
"use_bdlora": null,
|
| 45 |
+
"use_dora": false,
|
| 46 |
+
"use_qalora": false,
|
| 47 |
+
"use_rslora": false
|
| 48 |
+
}
|
adapter_model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4c2b5c7c0d2982b99de9c319e998274fc12f3aae5bf8d2c3b5db58c5864dc65b
|
| 3 |
+
size 80792880
|
chat_template.jinja
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{%- if tools %}
|
| 2 |
+
{{- '<|im_start|>system\n' }}
|
| 3 |
+
{%- if messages[0]['role'] == 'system' %}
|
| 4 |
+
{{- messages[0]['content'] }}
|
| 5 |
+
{%- else %}
|
| 6 |
+
{{- 'You are Qwen, created by Alibaba Cloud. You are a helpful assistant.' }}
|
| 7 |
+
{%- endif %}
|
| 8 |
+
{{- "\n\n# Tools\n\nYou may call one or more functions to assist with the user query.\n\nYou are provided with function signatures within <tools></tools> XML tags:\n<tools>" }}
|
| 9 |
+
{%- for tool in tools %}
|
| 10 |
+
{{- "\n" }}
|
| 11 |
+
{{- tool | tojson }}
|
| 12 |
+
{%- endfor %}
|
| 13 |
+
{{- "\n</tools>\n\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\n<tool_call>\n{\"name\": <function-name>, \"arguments\": <args-json-object>}\n</tool_call><|im_end|>\n" }}
|
| 14 |
+
{%- else %}
|
| 15 |
+
{%- if messages[0]['role'] == 'system' %}
|
| 16 |
+
{{- '<|im_start|>system\n' + messages[0]['content'] + '<|im_end|>\n' }}
|
| 17 |
+
{%- else %}
|
| 18 |
+
{{- '<|im_start|>system\nYou are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>\n' }}
|
| 19 |
+
{%- endif %}
|
| 20 |
+
{%- endif %}
|
| 21 |
+
{%- for message in messages %}
|
| 22 |
+
{%- if (message.role == "user") or (message.role == "system" and not loop.first) or (message.role == "assistant" and not message.tool_calls) %}
|
| 23 |
+
{{- '<|im_start|>' + message.role + '\n' + message.content + '<|im_end|>' + '\n' }}
|
| 24 |
+
{%- elif message.role == "assistant" %}
|
| 25 |
+
{{- '<|im_start|>' + message.role }}
|
| 26 |
+
{%- if message.content %}
|
| 27 |
+
{{- '\n' + message.content }}
|
| 28 |
+
{%- endif %}
|
| 29 |
+
{%- for tool_call in message.tool_calls %}
|
| 30 |
+
{%- if tool_call.function is defined %}
|
| 31 |
+
{%- set tool_call = tool_call.function %}
|
| 32 |
+
{%- endif %}
|
| 33 |
+
{{- '\n<tool_call>\n{"name": "' }}
|
| 34 |
+
{{- tool_call.name }}
|
| 35 |
+
{{- '", "arguments": ' }}
|
| 36 |
+
{{- tool_call.arguments | tojson }}
|
| 37 |
+
{{- '}\n</tool_call>' }}
|
| 38 |
+
{%- endfor %}
|
| 39 |
+
{{- '<|im_end|>\n' }}
|
| 40 |
+
{%- elif message.role == "tool" %}
|
| 41 |
+
{%- if (loop.index0 == 0) or (messages[loop.index0 - 1].role != "tool") %}
|
| 42 |
+
{{- '<|im_start|>user' }}
|
| 43 |
+
{%- endif %}
|
| 44 |
+
{{- '\n<tool_response>\n' }}
|
| 45 |
+
{{- message.content }}
|
| 46 |
+
{{- '\n</tool_response>' }}
|
| 47 |
+
{%- if loop.last or (messages[loop.index0 + 1].role != "tool") %}
|
| 48 |
+
{{- '<|im_end|>\n' }}
|
| 49 |
+
{%- endif %}
|
| 50 |
+
{%- endif %}
|
| 51 |
+
{%- endfor %}
|
| 52 |
+
{%- if add_generation_prompt %}
|
| 53 |
+
{{- '<|im_start|>assistant\n' }}
|
| 54 |
+
{%- endif %}
|
tokenizer.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:3fd169731d2cbde95e10bf356d66d5997fd885dd8dbb6fb4684da3f23b2585d8
|
| 3 |
+
size 11421892
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"add_prefix_space": false,
|
| 3 |
+
"backend": "tokenizers",
|
| 4 |
+
"bos_token": null,
|
| 5 |
+
"clean_up_tokenization_spaces": false,
|
| 6 |
+
"eos_token": "<|im_end|>",
|
| 7 |
+
"errors": "replace",
|
| 8 |
+
"extra_special_tokens": [
|
| 9 |
+
"<|im_start|>",
|
| 10 |
+
"<|im_end|>",
|
| 11 |
+
"<|object_ref_start|>",
|
| 12 |
+
"<|object_ref_end|>",
|
| 13 |
+
"<|box_start|>",
|
| 14 |
+
"<|box_end|>",
|
| 15 |
+
"<|quad_start|>",
|
| 16 |
+
"<|quad_end|>",
|
| 17 |
+
"<|vision_start|>",
|
| 18 |
+
"<|vision_end|>",
|
| 19 |
+
"<|vision_pad|>",
|
| 20 |
+
"<|image_pad|>",
|
| 21 |
+
"<|video_pad|>"
|
| 22 |
+
],
|
| 23 |
+
"is_local": false,
|
| 24 |
+
"local_files_only": false,
|
| 25 |
+
"model_max_length": 32768,
|
| 26 |
+
"pad_token": "<|endoftext|>",
|
| 27 |
+
"split_special_tokens": false,
|
| 28 |
+
"tokenizer_class": "Qwen2Tokenizer",
|
| 29 |
+
"unk_token": null
|
| 30 |
+
}
|
training_metadata.json
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"schema_version": 1,
|
| 3 |
+
"release": "0.1.1",
|
| 4 |
+
"model": "PySecPatch-7B",
|
| 5 |
+
"author": {
|
| 6 |
+
"name": "Ahmed Bin Khalid",
|
| 7 |
+
"affiliation": "Independent Researcher",
|
| 8 |
+
"orcid": "0000-0002-0616-2604"
|
| 9 |
+
},
|
| 10 |
+
"base_model": "Qwen/Qwen2.5-Coder-7B-Instruct",
|
| 11 |
+
"base_license": "Apache-2.0",
|
| 12 |
+
"method": "continued QLoRA supervised fine-tuning",
|
| 13 |
+
"lineage": [
|
| 14 |
+
{
|
| 15 |
+
"stage": "A",
|
| 16 |
+
"training_records": 8400,
|
| 17 |
+
"validation_records": 1200,
|
| 18 |
+
"epochs": 2.0,
|
| 19 |
+
"learning_rate": 0.0002,
|
| 20 |
+
"max_sequence_length": 4096,
|
| 21 |
+
"effective_batch_size": 8
|
| 22 |
+
},
|
| 23 |
+
{
|
| 24 |
+
"stage": "B",
|
| 25 |
+
"training_records": 48000,
|
| 26 |
+
"validation_records": 4000,
|
| 27 |
+
"epochs": 1.0,
|
| 28 |
+
"learning_rate": 0.0001,
|
| 29 |
+
"max_sequence_length": 2048,
|
| 30 |
+
"effective_batch_size": 16,
|
| 31 |
+
"optimizer": "paged_adamw_8bit",
|
| 32 |
+
"quantization": "4-bit NF4 with double quantization",
|
| 33 |
+
"train_steps": 3000,
|
| 34 |
+
"train_loss": 0.1284,
|
| 35 |
+
"validation_loss": 0.3163
|
| 36 |
+
}
|
| 37 |
+
],
|
| 38 |
+
"lora": {
|
| 39 |
+
"rank": 16,
|
| 40 |
+
"alpha": 32,
|
| 41 |
+
"dropout": 0.05,
|
| 42 |
+
"target_modules": [
|
| 43 |
+
"q_proj",
|
| 44 |
+
"k_proj",
|
| 45 |
+
"v_proj",
|
| 46 |
+
"o_proj",
|
| 47 |
+
"gate_proj",
|
| 48 |
+
"up_proj",
|
| 49 |
+
"down_proj"
|
| 50 |
+
]
|
| 51 |
+
},
|
| 52 |
+
"seed": 20260627,
|
| 53 |
+
"training_examples_total": 56400,
|
| 54 |
+
"validation_examples_total": 5200,
|
| 55 |
+
"test_or_holdout_records_used_for_training": 0,
|
| 56 |
+
"push_to_hub_during_training": false,
|
| 57 |
+
"final_adapter_sha256": "4c2b5c7c0d2982b99de9c319e998274fc12f3aae5bf8d2c3b5db58c5864dc65b",
|
| 58 |
+
"software": {
|
| 59 |
+
"python": "3.11.10",
|
| 60 |
+
"torch": "2.5.1+cu124",
|
| 61 |
+
"transformers": "5.12.1",
|
| 62 |
+
"peft": "0.19.1",
|
| 63 |
+
"trl": "1.6.0",
|
| 64 |
+
"bitsandbytes": "0.49.2",
|
| 65 |
+
"datasets": "5.0.0"
|
| 66 |
+
},
|
| 67 |
+
"provenance_note": "This release metadata removes machine-local paths and internal stage labels. Untouched trainer logs and configuration files are retained in the hashed evaluation evidence bundle."
|
| 68 |
+
}
|