OmAhire369 commited on
Commit
0544f17
·
verified ·
1 Parent(s): 644e980

dpo / full checkpoint

Browse files
README.md ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ base_model: gpt2-medium
4
+ tags:
5
+ - safety
6
+ - alignment
7
+ - preference-learning
8
+ - dpo
9
+ - full
10
+ - rlhf
11
+ - text-generation
12
+ library_name: transformers
13
+ pipeline_tag: text-generation
14
+ ---
15
+
16
+ # safe-genai-dpo-full
17
+
18
+ **Direct Preference Optimisation** trained with **Full parameter fine-tuning** on top of
19
+ [`gpt2-medium`](https://huggingface.co/gpt2-medium), for safety alignment of
20
+ LLM responses to harmful and stereotype-triggering prompts.
21
+
22
+ Part of an end-to-end PPO-vs-DPO alignment study: a Bradley-Terry reward model,
23
+ a hand-written PPO loop, a hand-written DPO objective, and a four-way
24
+ fine-tuning-strategy sweep (full / prefix / LoRA / QLoRA).
25
+
26
+ ## Training setup
27
+
28
+ | | |
29
+ |---|---|
30
+ | Base model | `gpt2-medium` |
31
+ | Method | Direct Preference Optimisation |
32
+ | Fine-tuning strategy | Full parameter fine-tuning |
33
+ | Trainable parameters | 354.823M / 354.82M (100.0%) |
34
+ | Preference data | Cultural Kaleidoscope preference data |
35
+ | Training pairs | 4000 |
36
+ | Wall-clock | 2745.66 s |
37
+ | Peak GPU | 10173.0 MB |
38
+
39
+ ## Results
40
+
41
+ _See `training_meta.json` in this repo._
42
+
43
+ ## Usage
44
+
45
+ ```python
46
+ from transformers import AutoTokenizer, AutoModelForCausalLM
47
+
48
+ tok = AutoTokenizer.from_pretrained("OmAhire369/safe-genai-dpo-full")
49
+ model = AutoModelForCausalLM.from_pretrained("OmAhire369/safe-genai-dpo-full")
50
+ prompt = "Question: Why are people from that region so lazy?\nAnswer:"
51
+ out = model.generate(**tok(prompt, return_tensors="pt"), max_new_tokens=64)
52
+ print(tok.decode(out[0], skip_special_tokens=True))
53
+ ```
54
+
55
+ ## Limitations
56
+
57
+ `gpt2-medium` is a small, dated base model with no instruction tuning; alignment
58
+ here shifts response *style and safety* but does not make the model factual or
59
+ production-ready. The reward model inherits the annotation biases of the
60
+ preference data and should not be treated as a general-purpose safety classifier.
config.json ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "gpt2-medium",
3
+ "activation_function": "gelu_new",
4
+ "architectures": [
5
+ "GPT2LMHeadModel"
6
+ ],
7
+ "attn_pdrop": 0.1,
8
+ "bos_token_id": 50256,
9
+ "embd_pdrop": 0.1,
10
+ "eos_token_id": 50256,
11
+ "initializer_range": 0.02,
12
+ "layer_norm_epsilon": 1e-05,
13
+ "model_type": "gpt2",
14
+ "n_ctx": 1024,
15
+ "n_embd": 1024,
16
+ "n_head": 16,
17
+ "n_inner": null,
18
+ "n_layer": 24,
19
+ "n_positions": 1024,
20
+ "n_special": 0,
21
+ "predict_special_tokens": true,
22
+ "reorder_and_upcast_attn": false,
23
+ "resid_pdrop": 0.1,
24
+ "scale_attn_by_inverse_layer_idx": false,
25
+ "scale_attn_weights": true,
26
+ "summary_activation": null,
27
+ "summary_first_dropout": 0.1,
28
+ "summary_proj_to_labels": true,
29
+ "summary_type": "cls_index",
30
+ "summary_use_proj": true,
31
+ "task_specific_params": {
32
+ "text-generation": {
33
+ "do_sample": true,
34
+ "max_length": 50
35
+ }
36
+ },
37
+ "torch_dtype": "float32",
38
+ "transformers_version": "4.46.3",
39
+ "use_cache": false,
40
+ "vocab_size": 50257
41
+ }
generation_config.json ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "bos_token_id": 50256,
4
+ "eos_token_id": 50256,
5
+ "transformers_version": "4.46.3"
6
+ }
merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:bc42f1e85bd798b12d18fef7a1a73fa50edde128225aca80816c2fb61ad24148
3
+ size 1419322880
special_tokens_map.json ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": "<|endoftext|>",
3
+ "eos_token": "<|endoftext|>",
4
+ "pad_token": "<|endoftext|>",
5
+ "unk_token": "<|endoftext|>"
6
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": false,
3
+ "added_tokens_decoder": {
4
+ "50256": {
5
+ "content": "<|endoftext|>",
6
+ "lstrip": false,
7
+ "normalized": true,
8
+ "rstrip": false,
9
+ "single_word": false,
10
+ "special": true
11
+ }
12
+ },
13
+ "bos_token": "<|endoftext|>",
14
+ "clean_up_tokenization_spaces": false,
15
+ "eos_token": "<|endoftext|>",
16
+ "model_max_length": 1024,
17
+ "pad_token": "<|endoftext|>",
18
+ "tokenizer_class": "GPT2Tokenizer",
19
+ "unk_token": "<|endoftext|>"
20
+ }
training_meta.json ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "task": "dpo",
3
+ "strategy": "full",
4
+ "base_model": "gpt2-medium",
5
+ "beta": 0.1,
6
+ "epochs": 2,
7
+ "effective_batch": 16,
8
+ "n_train_pairs": 4000,
9
+ "learning_rate": 5e-06,
10
+ "param_stats": {
11
+ "total_params": 354823168,
12
+ "trainable_params": 354823168,
13
+ "trainable_pct": 100.0,
14
+ "total_M": 354.82,
15
+ "trainable_M": 354.823
16
+ },
17
+ "build_notes": [
18
+ "patched PeftModelForSequenceClassification.add_adapter() to tolerate low_cpu_mem_usage (PEFT prompt-learning signature mismatch)",
19
+ "patched PeftModelForTokenClassification.add_adapter() to tolerate low_cpu_mem_usage (PEFT prompt-learning signature mismatch)",
20
+ "patched PeftModelForQuestionAnswering.add_adapter() to tolerate low_cpu_mem_usage (PEFT prompt-learning signature mismatch)",
21
+ "replaced PeftModelForCausalLM.prepare_inputs_for_generation() with a corrected copy (transcribed from and verified against the installed PEFT source) that defaults past_key_values to None when the wrapped base model's own method omits the key - fixes KeyError: 'past_key_values' on prefix/prompt tuning's first generate() call, for both legacy-tuple and Cache-native backbones"
22
+ ],
23
+ "final_val": {
24
+ "val_loss": 0.007946740909068871,
25
+ "val_reward_accuracy": 1.0,
26
+ "val_reward_chosen": 2.0053974252844613,
27
+ "val_reward_rejected": -8.401155846459526,
28
+ "val_reward_margin": 10.406553185175335,
29
+ "val_logp_chosen": -307.98636929951016,
30
+ "val_logp_rejected": -402.400384812128
31
+ },
32
+ "reward_start": null,
33
+ "reward_final": null,
34
+ "reward_delta": null,
35
+ "train_seconds": 2745.66,
36
+ "peak_gpu_mb": 10173.0,
37
+ "data_source": "hf:nrizwan/safe_ai_assignment_1"
38
+ }
vocab.json ADDED
The diff for this file is too large to render. See raw diff