Upload 11 files
Browse files- .gitattributes +1 -0
- README.md +152 -0
- adapter_config.json +34 -0
- adapter_model.safetensors +3 -0
- added_tokens.json +12 -0
- chat_template.jinja +1 -0
- merges.txt +0 -0
- special_tokens_map.json +24 -0
- tokenizer.json +3 -0
- tokenizer_config.json +111 -0
- training_args.bin +3 -0
- vocab.json +0 -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
|
README.md
ADDED
@@ -0,0 +1,152 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
base_model: microsoft/Phi-4-mini-instruct
|
3 |
+
library_name: peft
|
4 |
+
tags:
|
5 |
+
- text-generation
|
6 |
+
- instruction-tuning
|
7 |
+
- lora
|
8 |
+
- fine-tuned
|
9 |
+
- phi-4
|
10 |
+
- pytorch
|
11 |
+
- transformers
|
12 |
+
license: mit
|
13 |
+
language:
|
14 |
+
- en
|
15 |
+
pipeline_tag: text-generation
|
16 |
+
inference: true
|
17 |
+
---
|
18 |
+
|
19 |
+
# Model Card for Phi-4 LoRA Fine-tuned Model
|
20 |
+
|
21 |
+
This model is a LoRA fine-tuned version of Microsoft's Phi-4-mini-instruct, optimized for improved code review using GitHub data.
|
22 |
+
|
23 |
+
## Model Details
|
24 |
+
|
25 |
+
### Model Description
|
26 |
+
|
27 |
+
This is a fine-tuned version of Microsoft's Phi-4-mini-instruct model using LoRA (Low-Rank Adaptation) technique. The model has been trained on 10k instruction-response pairs to enhance its ability to follow instructions and generate high-quality responses across various tasks.
|
28 |
+
|
29 |
+
The model uses 4-bit quantization with NF4 for efficient inference while maintaining performance quality. It's designed to be a lightweight yet capable language model suitable for various text generation tasks.
|
30 |
+
|
31 |
+
- **Developed by:** Milos Kotlar
|
32 |
+
- **Model type:** Causal Language Model
|
33 |
+
- **Language(s) (NLP):** English
|
34 |
+
- **License:** MIT
|
35 |
+
- **Finetuned from model:** microsoft/Phi-4-mini-instruct
|
36 |
+
|
37 |
+
### Model Sources
|
38 |
+
|
39 |
+
- **Repository:** https://github.com/kotlarmilos/phi4-finetuned
|
40 |
+
- **Demo:** https://huggingface.co/spaces/kotlarmilos/dotnet-runtime
|
41 |
+
|
42 |
+
## Uses
|
43 |
+
|
44 |
+
### Direct Use
|
45 |
+
|
46 |
+
The model is designed for:
|
47 |
+
|
48 |
+
- **Instruction Following**: Generate responses to user instructions and queries
|
49 |
+
- **Conversational AI**: Engage in multi-turn conversations
|
50 |
+
- **Task Completion**: Help with various text-based tasks like summarization, explanation, and creative writing
|
51 |
+
- **Educational Support**: Provide explanations and assistance for learning
|
52 |
+
|
53 |
+
### Downstream Use
|
54 |
+
|
55 |
+
The model can be integrated into:
|
56 |
+
|
57 |
+
- **Chatbot Applications**: Web applications, mobile apps, and customer service systems
|
58 |
+
- **Content Generation Tools**: Writing assistants and creative content platforms
|
59 |
+
- **Educational Platforms**: Tutoring systems and interactive learning environments
|
60 |
+
- **API Services**: Text generation services and intelligent automation workflows
|
61 |
+
|
62 |
+
### Out-of-Scope Use
|
63 |
+
|
64 |
+
The model is **not intended for**:
|
65 |
+
|
66 |
+
- **Factual Information Retrieval**: May generate plausible but incorrect information
|
67 |
+
- **Professional Medical/Legal Advice**: Not qualified for specialized professional guidance
|
68 |
+
- **Real-time Critical Systems**: Not suitable for safety-critical applications
|
69 |
+
- **Harmful Content Generation**: Should not be used to create misleading, harmful, or malicious content
|
70 |
+
|
71 |
+
## How to Get Started with the Model
|
72 |
+
|
73 |
+
```python
|
74 |
+
import torch
|
75 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
|
76 |
+
from peft import PeftModel
|
77 |
+
|
78 |
+
# Load base model with quantization
|
79 |
+
base_model = "kotlarmilos/Phi-4-mini-instruct"
|
80 |
+
lora_path = "artifacts/phi4-finetuned"
|
81 |
+
|
82 |
+
bnb_config = BitsAndBytesConfig(
|
83 |
+
load_in_4bit=True,
|
84 |
+
bnb_4bit_quant_type="nf4",
|
85 |
+
bnb_4bit_use_double_quant=True,
|
86 |
+
bnb_4bit_compute_dtype=torch.bfloat16,
|
87 |
+
)
|
88 |
+
|
89 |
+
tokenizer = AutoTokenizer.from_pretrained(base_model, use_fast=True)
|
90 |
+
|
91 |
+
base = AutoModelForCausalLM.from_pretrained(
|
92 |
+
base_model,
|
93 |
+
quantization_config=bnb_config,
|
94 |
+
device_map="auto",
|
95 |
+
trust_remote_code=True
|
96 |
+
)
|
97 |
+
|
98 |
+
# Load LoRA adapter
|
99 |
+
model = PeftModel.from_pretrained(base, lora_path)
|
100 |
+
|
101 |
+
# Generate text
|
102 |
+
def generate(prompt):
|
103 |
+
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
104 |
+
output = model.generate(
|
105 |
+
**inputs,
|
106 |
+
max_new_tokens=256,
|
107 |
+
do_sample=True,
|
108 |
+
temperature=0.7,
|
109 |
+
pad_token_id=tokenizer.eos_token_id
|
110 |
+
)
|
111 |
+
return tokenizer.decode(output[0], skip_special_tokens=True)
|
112 |
+
|
113 |
+
# Example usage
|
114 |
+
prompt = "Review the following code changes:"
|
115 |
+
response = generate(prompt)
|
116 |
+
print(response)
|
117 |
+
```
|
118 |
+
|
119 |
+
## Training Details
|
120 |
+
|
121 |
+
### Training Data
|
122 |
+
|
123 |
+
The model was fine-tuned on approximately 10,000 high-quality instruction-response pairs designed to improve the model's ability to follow instructions and generate helpful, accurate responses across various domains.
|
124 |
+
|
125 |
+
**Data Characteristics**:
|
126 |
+
- **Size**: ~10,000 instruction-response pairs
|
127 |
+
- **Format**: Structured instruction-following conversations
|
128 |
+
- **Coverage**: Diverse topics and instruction types
|
129 |
+
|
130 |
+
### Training Procedure
|
131 |
+
|
132 |
+
#### Preprocessing
|
133 |
+
|
134 |
+
1. **Data Preparation**: Instruction-response pairs formatted for causal language modeling
|
135 |
+
2. **Tokenization**: Text processed using Phi-4's tokenizer with appropriate special tokens
|
136 |
+
3. **Sequence Formatting**: Proper formatting for instruction-following tasks
|
137 |
+
4. **Quality Filtering**: Removal of low-quality or potentially harmful content
|
138 |
+
|
139 |
+
#### Training Hyperparameters
|
140 |
+
|
141 |
+
**LoRA Configuration**:
|
142 |
+
- **LoRA Rank (r)**: 8
|
143 |
+
- **LoRA Alpha**: 16
|
144 |
+
- **LoRA Dropout**: 0.05
|
145 |
+
- **Target Modules**: ["qkv_proj", "gate_up_proj"]
|
146 |
+
- **Task Type**: CAUSAL_LM
|
147 |
+
|
148 |
+
**Training Setup**:
|
149 |
+
- **Base Model**: microsoft/Phi-4-mini-instruct
|
150 |
+
- **Training Method**: LoRA (Low-Rank Adaptation)
|
151 |
+
- **Quantization**: 4-bit NF4 with BitsAndBytes
|
152 |
+
- **Training regime**: Mixed precision training with appropriate optimization
|
adapter_config.json
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"alpha_pattern": {},
|
3 |
+
"auto_mapping": null,
|
4 |
+
"base_model_name_or_path": "microsoft/Phi-4-mini-instruct",
|
5 |
+
"bias": "none",
|
6 |
+
"corda_config": null,
|
7 |
+
"eva_config": null,
|
8 |
+
"exclude_modules": null,
|
9 |
+
"fan_in_fan_out": false,
|
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": 16,
|
17 |
+
"lora_bias": false,
|
18 |
+
"lora_dropout": 0.05,
|
19 |
+
"megatron_config": null,
|
20 |
+
"megatron_core": "megatron.core",
|
21 |
+
"modules_to_save": null,
|
22 |
+
"peft_type": "LORA",
|
23 |
+
"r": 8,
|
24 |
+
"rank_pattern": {},
|
25 |
+
"revision": null,
|
26 |
+
"target_modules": [
|
27 |
+
"qkv_proj",
|
28 |
+
"gate_up_proj"
|
29 |
+
],
|
30 |
+
"task_type": "CAUSAL_LM",
|
31 |
+
"trainable_token_indices": null,
|
32 |
+
"use_dora": false,
|
33 |
+
"use_rslora": false
|
34 |
+
}
|
adapter_model.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:6130c7058b38413eeaf6a45ad42952db91caafdcc896b9b3b0c7130f0662a93a
|
3 |
+
size 28328760
|
added_tokens.json
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"<|/tool_call|>": 200026,
|
3 |
+
"<|/tool|>": 200024,
|
4 |
+
"<|assistant|>": 200019,
|
5 |
+
"<|end|>": 200020,
|
6 |
+
"<|system|>": 200022,
|
7 |
+
"<|tag|>": 200028,
|
8 |
+
"<|tool_call|>": 200025,
|
9 |
+
"<|tool_response|>": 200027,
|
10 |
+
"<|tool|>": 200023,
|
11 |
+
"<|user|>": 200021
|
12 |
+
}
|
chat_template.jinja
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{% for message in messages %}{% if message['role'] == 'system' and 'tools' in message and message['tools'] is not none %}{{ '<|' + message['role'] + '|>' + message['content'] + '<|tool|>' + message['tools'] + '<|/tool|>' + '<|end|>' }}{% else %}{{ '<|' + message['role'] + '|>' + message['content'] + '<|end|>' }}{% endif %}{% endfor %}{% if add_generation_prompt %}{{ '<|assistant|>' }}{% else %}{{ eos_token }}{% endif %}
|
merges.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|
special_tokens_map.json
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"bos_token": {
|
3 |
+
"content": "<|endoftext|>",
|
4 |
+
"lstrip": false,
|
5 |
+
"normalized": false,
|
6 |
+
"rstrip": false,
|
7 |
+
"single_word": false
|
8 |
+
},
|
9 |
+
"eos_token": {
|
10 |
+
"content": "<|endoftext|>",
|
11 |
+
"lstrip": false,
|
12 |
+
"normalized": false,
|
13 |
+
"rstrip": false,
|
14 |
+
"single_word": false
|
15 |
+
},
|
16 |
+
"pad_token": "<|endoftext|>",
|
17 |
+
"unk_token": {
|
18 |
+
"content": "<|endoftext|>",
|
19 |
+
"lstrip": false,
|
20 |
+
"normalized": false,
|
21 |
+
"rstrip": false,
|
22 |
+
"single_word": false
|
23 |
+
}
|
24 |
+
}
|
tokenizer.json
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:d4135203a50c29adbcd8561c02affe1dff17c91c27f03f7a57b5ad0503ac248b
|
3 |
+
size 15524375
|
tokenizer_config.json
ADDED
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"add_bos_token": false,
|
3 |
+
"add_eos_token": false,
|
4 |
+
"add_prefix_space": false,
|
5 |
+
"added_tokens_decoder": {
|
6 |
+
"199999": {
|
7 |
+
"content": "<|endoftext|>",
|
8 |
+
"lstrip": false,
|
9 |
+
"normalized": false,
|
10 |
+
"rstrip": false,
|
11 |
+
"single_word": false,
|
12 |
+
"special": true
|
13 |
+
},
|
14 |
+
"200018": {
|
15 |
+
"content": "<|endofprompt|>",
|
16 |
+
"lstrip": false,
|
17 |
+
"normalized": false,
|
18 |
+
"rstrip": false,
|
19 |
+
"single_word": false,
|
20 |
+
"special": true
|
21 |
+
},
|
22 |
+
"200019": {
|
23 |
+
"content": "<|assistant|>",
|
24 |
+
"lstrip": false,
|
25 |
+
"normalized": false,
|
26 |
+
"rstrip": true,
|
27 |
+
"single_word": false,
|
28 |
+
"special": true
|
29 |
+
},
|
30 |
+
"200020": {
|
31 |
+
"content": "<|end|>",
|
32 |
+
"lstrip": false,
|
33 |
+
"normalized": false,
|
34 |
+
"rstrip": true,
|
35 |
+
"single_word": false,
|
36 |
+
"special": true
|
37 |
+
},
|
38 |
+
"200021": {
|
39 |
+
"content": "<|user|>",
|
40 |
+
"lstrip": false,
|
41 |
+
"normalized": false,
|
42 |
+
"rstrip": true,
|
43 |
+
"single_word": false,
|
44 |
+
"special": true
|
45 |
+
},
|
46 |
+
"200022": {
|
47 |
+
"content": "<|system|>",
|
48 |
+
"lstrip": false,
|
49 |
+
"normalized": false,
|
50 |
+
"rstrip": true,
|
51 |
+
"single_word": false,
|
52 |
+
"special": true
|
53 |
+
},
|
54 |
+
"200023": {
|
55 |
+
"content": "<|tool|>",
|
56 |
+
"lstrip": false,
|
57 |
+
"normalized": false,
|
58 |
+
"rstrip": true,
|
59 |
+
"single_word": false,
|
60 |
+
"special": false
|
61 |
+
},
|
62 |
+
"200024": {
|
63 |
+
"content": "<|/tool|>",
|
64 |
+
"lstrip": false,
|
65 |
+
"normalized": false,
|
66 |
+
"rstrip": true,
|
67 |
+
"single_word": false,
|
68 |
+
"special": false
|
69 |
+
},
|
70 |
+
"200025": {
|
71 |
+
"content": "<|tool_call|>",
|
72 |
+
"lstrip": false,
|
73 |
+
"normalized": false,
|
74 |
+
"rstrip": true,
|
75 |
+
"single_word": false,
|
76 |
+
"special": false
|
77 |
+
},
|
78 |
+
"200026": {
|
79 |
+
"content": "<|/tool_call|>",
|
80 |
+
"lstrip": false,
|
81 |
+
"normalized": false,
|
82 |
+
"rstrip": true,
|
83 |
+
"single_word": false,
|
84 |
+
"special": false
|
85 |
+
},
|
86 |
+
"200027": {
|
87 |
+
"content": "<|tool_response|>",
|
88 |
+
"lstrip": false,
|
89 |
+
"normalized": false,
|
90 |
+
"rstrip": true,
|
91 |
+
"single_word": false,
|
92 |
+
"special": false
|
93 |
+
},
|
94 |
+
"200028": {
|
95 |
+
"content": "<|tag|>",
|
96 |
+
"lstrip": false,
|
97 |
+
"normalized": false,
|
98 |
+
"rstrip": true,
|
99 |
+
"single_word": false,
|
100 |
+
"special": true
|
101 |
+
}
|
102 |
+
},
|
103 |
+
"bos_token": "<|endoftext|>",
|
104 |
+
"clean_up_tokenization_spaces": false,
|
105 |
+
"eos_token": "<|endoftext|>",
|
106 |
+
"extra_special_tokens": {},
|
107 |
+
"model_max_length": 131072,
|
108 |
+
"pad_token": "<|endoftext|>",
|
109 |
+
"tokenizer_class": "GPT2Tokenizer",
|
110 |
+
"unk_token": "<|endoftext|>"
|
111 |
+
}
|
training_args.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:4b928a8fe1b231f20c3315b5a354c7f1c7396e1c306cde76958718fb0129657b
|
3 |
+
size 5240
|
vocab.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|