melihcatal commited on
Commit
80c43e2
Β·
verified Β·
1 Parent(s): f075ba4

Add model card

Browse files
Files changed (1) hide show
  1. README.md +186 -0
README.md ADDED
@@ -0,0 +1,186 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - code
4
+ license: apache-2.0
5
+ tags:
6
+ - differential-privacy
7
+ - code-generation
8
+ - continued-pretraining
9
+ - lora
10
+ - dp-sgd
11
+ - opacus
12
+ - privacy
13
+ datasets:
14
+ - melihcatal/codedp-cpt
15
+ base_model:
16
+ - ibm-granite/granite-4.0-h-tiny
17
+ - deepseek-ai/deepseek-coder-6.7b-instruct
18
+ - Qwen/Qwen3-4B-Instruct-2507
19
+ library_name: peft
20
+ pipeline_tag: text-generation
21
+ ---
22
+
23
+ # CodeDP-CPT: Differentially Private Continued Pre-Training for Code Models
24
+
25
+ This repository contains LoRA adapters for code language models trained with **Continued Pre-Training (CPT)** under **Differential Privacy (DP-SGD)**. The models demonstrate that formal privacy guarantees can be applied to code generation models while preserving utility.
26
+
27
+ ## Models
28
+
29
+ Nine adapter checkpoints are provided β€” three base models Γ— three privacy configurations:
30
+
31
+ | Base Model | Variant | DP | Target Ξ΅ | Achieved Ξ΅ | Adapter Path |
32
+ |---|---|---|---|---|---|
33
+ | [ibm-granite/granite-4.0-h-tiny](https://huggingface.co/ibm-granite/granite-4.0-h-tiny) | base | No | β€” | β€” | `granite-4.0-h-tiny/base/adapter/` |
34
+ | [ibm-granite/granite-4.0-h-tiny](https://huggingface.co/ibm-granite/granite-4.0-h-tiny) | dp3 | Yes | 3.0 | 2.99 | `granite-4.0-h-tiny/dp3/adapter/` |
35
+ | [ibm-granite/granite-4.0-h-tiny](https://huggingface.co/ibm-granite/granite-4.0-h-tiny) | dp8 | Yes | 8.0 | 8.00 | `granite-4.0-h-tiny/dp8/adapter/` |
36
+ | [deepseek-ai/deepseek-coder-6.7b-instruct](https://huggingface.co/deepseek-ai/deepseek-coder-6.7b-instruct) | base | No | β€” | β€” | `deepseek-coder-6.7b/base/adapter/` |
37
+ | [deepseek-ai/deepseek-coder-6.7b-instruct](https://huggingface.co/deepseek-ai/deepseek-coder-6.7b-instruct) | dp3 | Yes | 3.0 | 3.00 | `deepseek-coder-6.7b/dp3/adapter/` |
38
+ | [deepseek-ai/deepseek-coder-6.7b-instruct](https://huggingface.co/deepseek-ai/deepseek-coder-6.7b-instruct) | dp8 | Yes | 8.0 | 8.00 | `deepseek-coder-6.7b/dp8/adapter/` |
39
+ | [Qwen/Qwen3-4B-Instruct-2507](https://huggingface.co/Qwen/Qwen3-4B-Instruct-2507) | base | No | β€” | β€” | `qwen3-4b-instruct/base/adapter/` |
40
+ | [Qwen/Qwen3-4B-Instruct-2507](https://huggingface.co/Qwen/Qwen3-4B-Instruct-2507) | dp3 | Yes | 3.0 | 2.99 | `qwen3-4b-instruct/dp3/adapter/` |
41
+ | [Qwen/Qwen3-4B-Instruct-2507](https://huggingface.co/Qwen/Qwen3-4B-Instruct-2507) | dp8 | Yes | 8.0 | 8.00 | `qwen3-4b-instruct/dp8/adapter/` |
42
+
43
+ ## Usage
44
+
45
+ ```python
46
+ from transformers import AutoModelForCausalLM, AutoTokenizer
47
+ from peft import PeftModel
48
+
49
+ base_model_name = "ibm-granite/granite-4.0-h-tiny"
50
+ adapter_path = "melihcatal/codedp-cpt-models"
51
+ subfolder = "granite-4.0-h-tiny/dp8/adapter"
52
+
53
+ tokenizer = AutoTokenizer.from_pretrained(base_model_name, trust_remote_code=True)
54
+ model = AutoModelForCausalLM.from_pretrained(base_model_name, trust_remote_code=True)
55
+ model = PeftModel.from_pretrained(model, adapter_path, subfolder=subfolder)
56
+ ```
57
+
58
+ ## Training Details
59
+
60
+ ### Dataset
61
+
62
+ - **Dataset:** [melihcatal/codedp-cpt](https://huggingface.co/datasets/melihcatal/codedp-cpt) β€” code mined from GitHub repositories with quality filtering and decontamination (file-level, Type-1, and Type-2 clone detection against evaluation benchmarks)
63
+ - **Mode:** Causal language modeling (continued pre-training)
64
+ - **Validation split:** 5% held out
65
+
66
+ ### LoRA Configuration
67
+
68
+ | Parameter | Value |
69
+ |---|---|
70
+ | Rank (r) | 16 |
71
+ | Alpha (Ξ±) | 32 |
72
+ | Dropout | 0.05 |
73
+ | Target modules | q_proj, k_proj, v_proj, o_proj |
74
+ | Modules to save | lm_head |
75
+
76
+ ### Training Hyperparameters
77
+
78
+ | Parameter | No-DP (base) | DP variants |
79
+ |---|---|---|
80
+ | Epochs | 2 | 2 |
81
+ | Batch size (per GPU) | 8 | 8 |
82
+ | Learning rate | 1e-4 | 2e-4 |
83
+ | Optimizer | AdamW | AdamW |
84
+ | LR scheduler | Cosine | Cosine |
85
+ | Warmup ratio | 5% | 5% |
86
+ | Grad accumulation steps | 4–8 | 16 |
87
+ | Max gradient norm | 1.0 | 1.0 |
88
+ | Sequence length | 1024 | 1024 |
89
+ | Precision | bfloat16 | bfloat16 |
90
+ | Seed | 42 | 42 |
91
+
92
+ ### Differential Privacy
93
+
94
+ | Parameter | Value |
95
+ |---|---|
96
+ | Engine | Opacus PrivacyEngine |
97
+ | Mechanism | Gaussian (DP-SGD) |
98
+ | Per-sample gradients | Hook-based |
99
+ | Clipping | Flat (global) |
100
+ | Target Ξ΄ | 1e-5 |
101
+ | Target Ξ΅ | 3.0 or 8.0 |
102
+ | Privacy accounting | RDP (RΓ©nyi Differential Privacy) |
103
+
104
+ ### Infrastructure
105
+
106
+ - **Distributed strategy:** DDP (Distributed Data Parallel) with NCCL backend
107
+ - **Hardware:** NVIDIA H200 GPUs
108
+
109
+ ## Evaluation Results
110
+
111
+ ### Functional Correctness β€” CodeDP-FC (Granite-4.0-H-Tiny)
112
+
113
+ 103 code generation tasks, 10 samples per task, temperature 0.8.
114
+
115
+ | Variant | pass@1 | pass@5 | pass@10 |
116
+ |---|---|---|---|
117
+ | No fine-tuning | 13.5% | 18.4% | 20.4% |
118
+ | CPT (no DP) | 10.1% | 16.6% | 18.4% |
119
+ | CPT + DP (Ξ΅=3) | 13.7% | 19.1% | 21.4% |
120
+ | CPT + DP (Ξ΅=8) | **14.5%** | **21.1%** | **23.3%** |
121
+
122
+ ### Training Loss (Eval Set)
123
+
124
+ | Model | No-DP | DP Ξ΅=3 | DP Ξ΅=8 |
125
+ |---|---|---|---|
126
+ | Granite-4.0-H-Tiny | 0.946 | 1.044 | 1.038 |
127
+ | DeepSeek-Coder-6.7B | 4.840 | 10.326 | 7.523 |
128
+ | Qwen3-4B-Instruct | 0.808 | 0.941 | 0.925 |
129
+
130
+ ### Privacy Audit
131
+
132
+ New-token canary audit (500 members, 500 non-members, 49-token random prefixes). Higher AUC = more memorization; lower = better privacy.
133
+
134
+ | Model | Variant | Loss AUC | Embedding AUC | Empirical Ξ΅ (p=0.01) |
135
+ |---|---|---|---|---|
136
+ | Granite-4.0-H-Tiny | base | 1.000 | 1.000 | 3.02 |
137
+ | Granite-4.0-H-Tiny | dp3 | 0.543 | 0.513 | 0.00 |
138
+ | Granite-4.0-H-Tiny | dp8 | 0.564 | 0.508 | 0.16 |
139
+ | DeepSeek-Coder-6.7B | base | 0.957 | 0.968 | 3.02 |
140
+ | DeepSeek-Coder-6.7B | dp3 | 0.522 | 0.543 | 0.00 |
141
+ | DeepSeek-Coder-6.7B | dp8 | 0.533 | 0.545 | 0.00 |
142
+ | Qwen3-4B-Instruct | base | 0.969 | 0.884 | 3.02 |
143
+ | Qwen3-4B-Instruct | dp3 | 0.505 | 0.515 | 0.00 |
144
+ | Qwen3-4B-Instruct | dp8 | 0.515 | 0.516 | 0.00 |
145
+
146
+ **Key finding:** DP training reduces canary audit AUC to near-random (0.5), with empirical Ξ΅ dropping to 0 in most cases β€” confirming that the formal privacy guarantees hold in practice.
147
+
148
+ ## Repository Structure
149
+
150
+ ```
151
+ β”œβ”€β”€ granite-4.0-h-tiny/
152
+ β”‚ β”œβ”€β”€ base/ # No-DP baseline
153
+ β”‚ β”œβ”€β”€ dp3/ # DP Ξ΅=3
154
+ β”‚ └── dp8/ # DP Ξ΅=8
155
+ β”œβ”€β”€ deepseek-coder-6.7b/
156
+ β”‚ β”œβ”€β”€ base/
157
+ β”‚ β”œβ”€β”€ dp3/
158
+ β”‚ └── dp8/
159
+ └── qwen3-4b-instruct/
160
+ β”œβ”€β”€ base/
161
+ β”œβ”€β”€ dp3/
162
+ └── dp8/
163
+ ```
164
+
165
+ Each variant directory contains:
166
+ - `adapter/` β€” LoRA adapter weights (PEFT-compatible)
167
+ - `tokenizer/` β€” Tokenizer with any added audit tokens
168
+ - `resolved_config.yaml` β€” Full training configuration
169
+ - `summary.json` β€” Training and audit metrics
170
+ - `audit_results.json`, `audit_scores.npz` β€” Privacy audit artifacts
171
+ - `metrics.jsonl`, `scalars.csv` β€” Training logs
172
+ - `tensorboard/` β€” TensorBoard events
173
+ - `codecarbon.csv` β€” Carbon emissions tracking
174
+ - `epochs/` β€” Per-epoch checkpoints and audit results
175
+
176
+ ## Limitations
177
+
178
+ - These are **LoRA adapters**, not standalone models. They require the corresponding base model for inference.
179
+ - The adapters include additional tokenizer tokens added during the privacy audit process (canary tokens). These do not affect normal generation.
180
+ - Evaluation results are on the CodeDP-FC benchmark; performance may vary on other code generation tasks.
181
+ - DP training with tight privacy budgets (Ξ΅=3) incurs a utility cost, particularly visible in validation loss.
182
+
183
+ ## Related Resources
184
+
185
+ - **Training dataset:** [melihcatal/codedp-cpt](https://huggingface.co/datasets/melihcatal/codedp-cpt)
186
+ - **MIA benchmark:** [melihcatal/codedp-bench-mia-cpt](https://huggingface.co/datasets/melihcatal/codedp-bench-mia-cpt)