hilaryc112 commited on
Commit
a17749b
·
verified ·
1 Parent(s): 0913ddc

Upload folder using huggingface_hub

Browse files
README.md ADDED
@@ -0,0 +1,137 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ base_model: gpt2-large
4
+ tags:
5
+ - natural-language-inference
6
+ - lora
7
+ - peft
8
+ - gpt2
9
+ - multinli
10
+ - text-classification
11
+ datasets:
12
+ - nyu-mll/multi_nli
13
+ language:
14
+ - en
15
+ pipeline_tag: text-classification
16
+ ---
17
+
18
+ # GPT2-Large LoRA Fine-tuned for Natural Language Inference
19
+
20
+ This model is a LoRA (Low-Rank Adaptation) fine-tuned version of GPT2-large for Natural Language Inference (NLI) on the MultiNLI dataset.
21
+
22
+ ## Model Details
23
+
24
+ - **Base Model**: GPT2-large (774M parameters)
25
+ - **Fine-tuning Method**: LoRA (Low-Rank Adaptation)
26
+ - **Trainable Parameters**: ~2.3M (0.3% of total parameters)
27
+ - **Dataset**: MultiNLI (50K training samples)
28
+ - **Task**: Natural Language Inference (3-class classification)
29
+
30
+ ## Performance
31
+
32
+ - **Test Accuracy (Matched)**: ~79.22%
33
+ - **Test Accuracy (Mismatched)**: ~78.xx%
34
+ - **Training Method**: Parameter-efficient fine-tuning with LoRA
35
+ - **Hardware**: Trained on 36G vGPU
36
+
37
+ ## Usage
38
+
39
+ ```python
40
+ from transformers import AutoTokenizer, AutoModelForCausalLM
41
+ from peft import PeftModel
42
+
43
+ # Load tokenizer and base model
44
+ tokenizer = AutoTokenizer.from_pretrained("gpt2-large")
45
+ base_model = AutoModelForCausalLM.from_pretrained("gpt2-large")
46
+
47
+ # Load LoRA adapter
48
+ model = PeftModel.from_pretrained(base_model, "hilaryc112/LoRA-GPT2-Project")
49
+
50
+ # Format input
51
+ premise = "A person is outdoors, on a horse."
52
+ hypothesis = "A person is at a diner, ordering an omelette."
53
+ input_text = f"Premise: {premise}\nHypothesis: {hypothesis}\nRelationship:"
54
+
55
+ # Tokenize and generate
56
+ inputs = tokenizer(input_text, return_tensors="pt")
57
+ with torch.no_grad():
58
+ outputs = model.generate(**inputs, max_new_tokens=10, pad_token_id=tokenizer.eos_token_id)
59
+
60
+ prediction = tokenizer.decode(outputs[0][inputs['input_ids'].shape[1]:], skip_special_tokens=True).strip()
61
+ print(f"Prediction: {prediction}") # Should output: contradiction, neutral, or entailment
62
+ ```
63
+
64
+ ## Training Configuration
65
+
66
+ {
67
+ "model_name": "gpt2-large",
68
+ "max_length": 512,
69
+ "lora_r": 16,
70
+ "lora_alpha": 32,
71
+ "lora_dropout": 0.1,
72
+ "target_modules": [
73
+ "c_attn",
74
+ "c_proj",
75
+ "c_fc"
76
+ ],
77
+ "num_epochs": 3,
78
+ "train_batch_size": 4,
79
+ "eval_batch_size": 12,
80
+ "gradient_accumulation_steps": 6,
81
+ "learning_rate": 0.0002,
82
+ "weight_decay": 0.01,
83
+ "max_grad_norm": 1.0,
84
+ "use_fp16": true,
85
+ "gradient_checkpointing": true,
86
+ "logging_steps": 100,
87
+ "eval_steps": 500,
88
+ "save_steps": 500,
89
+ "save_total_limit": 3,
90
+ "early_stopping_patience": 5,
91
+ "data_dir": "./processed_data",
92
+ "output_dir": "./gpt2_lora_multinli",
93
+ "seed": 42,
94
+ "use_wandb": false,
95
+ "_comments": {
96
+ "effective_batch_size": "6 * 6 = 36 (optimized for 36G vGPU)",
97
+ "memory_optimization": "FP16 + gradient checkpointing enabled",
98
+ "lora_config": "Rank 16 with alpha 32 for good performance/efficiency balance",
99
+ "target_modules": "GPT2 attention and MLP layers for comprehensive adaptation",
100
+ "training_data": "Uses 50K samples from MultiNLI training set (configured in preprocessing)",
101
+ "evaluation_data": "Uses local dev files for matched/mismatched evaluation",
102
+ "training_adjustments": "Reduced epochs to 2 and LR to 1e-4 for better training with real data",
103
+ "eval_frequency": "Less frequent evaluation (every 500 steps) due to larger dataset"
104
+ }
105
+ }
106
+
107
+ ## Dataset Format
108
+
109
+ The model was trained on text-to-text format:
110
+ ```
111
+ Premise: [premise text]
112
+ Hypothesis: [hypothesis text]
113
+ Relationship: [entailment/neutral/contradiction]
114
+ ```
115
+
116
+ ## Files
117
+
118
+ - `adapter_config.json`: LoRA adapter configuration
119
+ - `adapter_model.safetensors`: LoRA adapter weights
120
+ - `training_config.json`: Training hyperparameters and settings
121
+
122
+ ## Citation
123
+
124
+ If you use this model, please cite:
125
+
126
+ ```bibtex
127
+ @misc{gpt2-lora-multinli,
128
+ title={GPT2-Large LoRA Fine-tuned for Natural Language Inference},
129
+ author={CSIT6000R Individual Project},
130
+ year={2024},
131
+ howpublished={\url{https://huggingface.co/hilaryc112/LoRA-GPT2-Project}}
132
+ }
133
+ ```
134
+
135
+ ## License
136
+
137
+ This model is released under the MIT License.
adapter_config.json ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "alpha_pattern": {},
3
+ "auto_mapping": null,
4
+ "base_model_name_or_path": "gpt2-large",
5
+ "bias": "none",
6
+ "corda_config": null,
7
+ "eva_config": null,
8
+ "exclude_modules": null,
9
+ "fan_in_fan_out": true,
10
+ "inference_mode": true,
11
+ "init_lora_weights": true,
12
+ "layer_replication": null,
13
+ "layers_pattern": null,
14
+ "layers_to_transform": null,
15
+ "loftq_config": {},
16
+ "lora_alpha": 32,
17
+ "lora_bias": false,
18
+ "lora_dropout": 0.1,
19
+ "megatron_config": null,
20
+ "megatron_core": "megatron.core",
21
+ "modules_to_save": null,
22
+ "peft_type": "LORA",
23
+ "qalora_group_size": 16,
24
+ "r": 16,
25
+ "rank_pattern": {},
26
+ "revision": null,
27
+ "target_modules": [
28
+ "c_proj",
29
+ "c_fc",
30
+ "c_attn"
31
+ ],
32
+ "target_parameters": null,
33
+ "task_type": "CAUSAL_LM",
34
+ "trainable_token_indices": null,
35
+ "use_dora": false,
36
+ "use_qalora": false,
37
+ "use_rslora": false
38
+ }
adapter_model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:59f763302a1cc4b8de5f2c792b540217ff3f316d30fadf9885d968e89c2f26cb
3
+ size 47223184
merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
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,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ "extra_special_tokens": {},
17
+ "model_max_length": 1024,
18
+ "pad_token": "<|endoftext|>",
19
+ "padding_side": "right",
20
+ "tokenizer_class": "GPT2Tokenizer",
21
+ "unk_token": "<|endoftext|>"
22
+ }
training_args.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:bc0186ecb5b87402f02a8e41ad8c17b5ec0acae3d2a412aa2837b0da4bf374c3
3
+ size 5841
vocab.json ADDED
The diff for this file is too large to render. See raw diff