koushikkb12 commited on
Commit
7e2433d
·
verified ·
1 Parent(s): 0aba9e3

Upload Qwen2.5-7B Code LoRA adapter (rank 128, 122K code instructions)

Browse files
.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
README.md ADDED
@@ -0,0 +1,136 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: peft
3
+ license: apache-2.0
4
+ base_model: Qwen/Qwen2.5-7B
5
+ tags:
6
+ - code-generation
7
+ - lora
8
+ - fine-tuned
9
+ - qwen2
10
+ - python
11
+ - transformers
12
+ - peft
13
+ - trl
14
+ datasets:
15
+ - TokenBender/code_instructions_122k_alpaca_style
16
+ language:
17
+ - en
18
+ pipeline_tag: text-generation
19
+ ---
20
+
21
+ # Qwen2.5-7B Code LoRA
22
+
23
+ LoRA adapter fine-tuned on [Qwen/Qwen2.5-7B](https://huggingface.co/Qwen/Qwen2.5-7B) for Python code generation.
24
+
25
+ ## Training Summary
26
+
27
+ | Detail | Value |
28
+ |---|---|
29
+ | Base Model | Qwen/Qwen2.5-7B (7.6B params) |
30
+ | Method | LoRA (rank 128, alpha 64) |
31
+ | Trainable Params | 323M / 7.9B (4.07%) |
32
+ | Dataset | [122K code instructions (Alpaca format)](https://huggingface.co/datasets/TokenBender/code_instructions_122k_alpaca_style) |
33
+ | Train / Eval Split | 115,861 / 6,098 |
34
+ | Epochs | 3 |
35
+ | Effective Batch Size | 32 (16 x 2 gradient accumulation) |
36
+ | Learning Rate | 2e-4 (cosine schedule, 3% warmup) |
37
+ | Max Sequence Length | 2048 (with packing) |
38
+ | Precision | bf16 |
39
+ | Training Time | ~4 hrs 26 min |
40
+ | GPU | NVIDIA RTX PRO 6000 Blackwell (96 GB) |
41
+ | Best Eval Loss | **0.7324** (step 600) |
42
+ | Eval Token Accuracy | **82.7%** |
43
+
44
+ ## LoRA Configuration
45
+
46
+ - **Rank**: 128
47
+ - **Alpha**: 64
48
+ - **Dropout**: 0.05
49
+ - **Target Modules**: q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj
50
+ - **Adapter Size**: ~1.2 GB
51
+
52
+ ## Usage
53
+
54
+ ```python
55
+ from transformers import AutoModelForCausalLM, AutoTokenizer
56
+ from peft import PeftModel
57
+ import torch
58
+
59
+ base = AutoModelForCausalLM.from_pretrained(
60
+ "Qwen/Qwen2.5-7B", dtype=torch.bfloat16, device_map="auto"
61
+ )
62
+ model = PeftModel.from_pretrained(base, "koushikkb12/Qwen2.5-7B-Code-LoRA")
63
+ model = model.merge_and_unload()
64
+
65
+ tokenizer = AutoTokenizer.from_pretrained("koushikkb12/Qwen2.5-7B-Code-LoRA")
66
+
67
+ messages = [
68
+ {"role": "system", "content": "You are a highly skilled Python programmer. Write clean, efficient, and correct code."},
69
+ {"role": "user", "content": "Write a function to flatten a nested list."},
70
+ ]
71
+ text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
72
+ inputs = tokenizer(text, return_tensors="pt").to(model.device)
73
+
74
+ with torch.no_grad():
75
+ out = model.generate(**inputs, max_new_tokens=256, temperature=0.7, top_p=0.9)
76
+
77
+ print(tokenizer.decode(out[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True))
78
+ ```
79
+
80
+ ## Example Outputs
81
+
82
+ **Prompt**: *Write a Python function that checks if a given string is a palindrome.*
83
+ ```python
84
+ def is_palindrome(s):
85
+ return s == s[::-1]
86
+ ```
87
+
88
+ **Prompt**: *Implement a binary search algorithm in Python.*
89
+ ```python
90
+ def binary_search(arr, target):
91
+ low, high = 0, len(arr) - 1
92
+ while low <= high:
93
+ mid = (low + high) // 2
94
+ if arr[mid] == target:
95
+ return mid
96
+ elif arr[mid] < target:
97
+ low = mid + 1
98
+ else:
99
+ high = mid - 1
100
+ return -1
101
+ ```
102
+
103
+ **Prompt**: *Write a Python class for a stack with push, pop, peek, and is_empty.*
104
+ ```python
105
+ class Stack:
106
+ def __init__(self):
107
+ self.items = []
108
+ def push(self, item):
109
+ self.items.append(item)
110
+ def pop(self):
111
+ if not self.is_empty():
112
+ return self.items.pop()
113
+ def peek(self):
114
+ if not self.is_empty():
115
+ return self.items[-1]
116
+ def is_empty(self):
117
+ return len(self.items) == 0
118
+ ```
119
+
120
+ ## Training Curves
121
+
122
+ | Step | Train Loss | Eval Loss | Eval Token Acc |
123
+ |---|---|---|---|
124
+ | 100 | 0.758 | 0.741 | 82.6% |
125
+ | 200 | 0.749 | 0.737 | 82.6% |
126
+ | 300 | 0.739 | 0.734 | 82.7% |
127
+ | 400 | 0.731 | 0.734 | 82.7% |
128
+ | 500 | 0.720 | 0.733 | 82.7% |
129
+ | 600 | 0.718 | **0.732** | **82.7%** |
130
+ | 700 | 0.725 | 0.734 | 82.7% |
131
+ | 800 | 0.710 | 0.734 | 82.7% |
132
+ | 900 | 0.739 | 0.734 | 82.7% |
133
+
134
+ ## License
135
+
136
+ This adapter inherits the [Apache 2.0 license](https://www.apache.org/licenses/LICENSE-2.0) from Qwen2.5-7B.
adapter_config.json ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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-7B",
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": 64,
20
+ "lora_bias": false,
21
+ "lora_dropout": 0.05,
22
+ "megatron_config": null,
23
+ "megatron_core": "megatron.core",
24
+ "modules_to_save": null,
25
+ "peft_type": "LORA",
26
+ "peft_version": "0.18.1",
27
+ "qalora_group_size": 16,
28
+ "r": 128,
29
+ "rank_pattern": {},
30
+ "revision": null,
31
+ "target_modules": [
32
+ "v_proj",
33
+ "gate_proj",
34
+ "up_proj",
35
+ "down_proj",
36
+ "q_proj",
37
+ "k_proj",
38
+ "o_proj"
39
+ ],
40
+ "target_parameters": null,
41
+ "task_type": "CAUSAL_LM",
42
+ "trainable_token_indices": null,
43
+ "use_dora": false,
44
+ "use_qalora": false,
45
+ "use_rslora": false
46
+ }
adapter_model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c86b68754732afce1796d985eb74183b49edf674eb2b6eab03e74c97c5424f61
3
+ size 1291899160
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 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 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,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": false,
3
+ "backend": "tokenizers",
4
+ "bos_token": null,
5
+ "clean_up_tokenization_spaces": false,
6
+ "eos_token": "<|endoftext|>",
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
+ "model_max_length": 131072,
25
+ "pad_token": "<|endoftext|>",
26
+ "split_special_tokens": false,
27
+ "tokenizer_class": "Qwen2Tokenizer",
28
+ "unk_token": null
29
+ }
training_args.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:dbd1aff7a35b248eebb41bc354261742aa196faf9c4a8dfd9f09d6785b0dc444
3
+ size 5649