Update README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,161 @@
|
|
1 |
---
|
2 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
+
tags:
|
3 |
+
- generated_from_trainer
|
4 |
+
model-index:
|
5 |
+
- name: Qra-1b-dolly-instruction-0.1
|
6 |
+
results: []
|
7 |
+
datasets:
|
8 |
+
- s3nh/alpaca-dolly-instruction-only-polish
|
9 |
+
language:
|
10 |
+
- pl
|
11 |
+
base_model: Qra-1b
|
12 |
---
|
13 |
+
|
14 |
+
# Qra-1b-dolly-instruction-0.1
|
15 |
+
|
16 |
+
This model if a fine-tuned version of [OPI-PG/Qra-1b](https://huggingface.co/OPI-PG/Qra-1b) on the [s3nh/alpaca-dolly-instruction-only-polish](https://huggingface.co/datasets/s3nh/alpaca-dolly-instruction-only-polish) dataset.
|
17 |
+
|
18 |
+
## Model Description
|
19 |
+
|
20 |
+
Trained from [OPI-PG/Qra-1b](https://huggingface.co/OPI-PG/Qra-1b)
|
21 |
+
|
22 |
+
## Intended uses & limitations
|
23 |
+
|
24 |
+
This model has been fine-tuned for question-answering task. It is possible to use it as a chat, but it doesn't work well because the dataset did not contain conversations.
|
25 |
+
|
26 |
+
```py
|
27 |
+
import torch
|
28 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
29 |
+
|
30 |
+
model_id = "nie3e/Qra-1b-dolly-instruction-0.1"
|
31 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
32 |
+
|
33 |
+
model = AutoModelForCausalLM.from_pretrained(
|
34 |
+
model_id,
|
35 |
+
torch_dtype=torch.bfloat16,
|
36 |
+
)
|
37 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
38 |
+
pipe = pipeline(
|
39 |
+
"text-generation", model=model, tokenizer=tokenizer, device=device
|
40 |
+
)
|
41 |
+
|
42 |
+
def get_answer(system_prompt: str, user_prompt: str) -> str:
|
43 |
+
input_msg = [
|
44 |
+
{"role": "system", "content": system_prompt},
|
45 |
+
{"role": "user", "content": user_prompt}
|
46 |
+
]
|
47 |
+
prompt = pipe.tokenizer.apply_chat_template(
|
48 |
+
input_msg, tokenize=False,
|
49 |
+
add_generation_prompt=True
|
50 |
+
)
|
51 |
+
outputs = pipe(
|
52 |
+
prompt, max_new_tokens=512, do_sample=False, temperature=0.1, top_k=50,
|
53 |
+
top_p=0.1, eos_token_id=pipe.tokenizer.eos_token_id,
|
54 |
+
pad_token_id=pipe.tokenizer.pad_token_id
|
55 |
+
)
|
56 |
+
return outputs[0]['generated_text'][len(prompt):].strip()
|
57 |
+
|
58 |
+
print(
|
59 |
+
get_answer(
|
60 |
+
system_prompt="Jesteś przyjaznym chatbotem",
|
61 |
+
user_prompt="Napisz czym jest dokument architectural decision record."
|
62 |
+
)
|
63 |
+
)
|
64 |
+
```
|
65 |
+
|
66 |
+
## Training and evaluation data
|
67 |
+
|
68 |
+
Dataset: [s3nh/alpaca-dolly-instruction-only-polish](https://huggingface.co/datasets/s3nh/alpaca-dolly-instruction-only-polish)
|
69 |
+
|
70 |
+
Each row has been converted into conversation using this function:
|
71 |
+
```py
|
72 |
+
system_message = """Jesteś przyjaznym chatbotem"""
|
73 |
+
|
74 |
+
def create_conversation(sample) -> dict:
|
75 |
+
strip_characters = "\"'"
|
76 |
+
return {
|
77 |
+
"messages": [
|
78 |
+
{"role": "system", "content": system_message},
|
79 |
+
{"role": "user",
|
80 |
+
"content": f"{sample['instruction'].strip(strip_characters)} "
|
81 |
+
f"{sample['input'].strip(strip_characters)}"},
|
82 |
+
{"role": "assistant",
|
83 |
+
"content": f"{sample['output'].strip(strip_characters)}"}
|
84 |
+
]
|
85 |
+
}
|
86 |
+
```
|
87 |
+
|
88 |
+
Train/test split: 90%/10%
|
89 |
+
|
90 |
+
## Training procedure
|
91 |
+
|
92 |
+
GPU: 2x RTX 4060Ti 16GB
|
93 |
+
Training time: ~1 hour
|
94 |
+
|
95 |
+
Using accelerate + deepspeed with config:
|
96 |
+
```yml
|
97 |
+
compute_environment: LOCAL_MACHINE
|
98 |
+
debug: false
|
99 |
+
deepspeed_config:
|
100 |
+
gradient_accumulation_steps: 2
|
101 |
+
zero3_init_flag: false
|
102 |
+
zero_stage: 1
|
103 |
+
distributed_type: DEEPSPEED
|
104 |
+
downcast_bf16: 'no'
|
105 |
+
machine_rank: 0
|
106 |
+
main_training_function: main
|
107 |
+
mixed_precision: bf16
|
108 |
+
num_machines: 1
|
109 |
+
num_processes: 2
|
110 |
+
rdzv_backend: static
|
111 |
+
same_network: true
|
112 |
+
tpu_env: []
|
113 |
+
tpu_use_cluster: false
|
114 |
+
tpu_use_sudo: false
|
115 |
+
use_cpu: false
|
116 |
+
```
|
117 |
+
|
118 |
+
### Training hyperparameters
|
119 |
+
|
120 |
+
Lora config:
|
121 |
+
```py
|
122 |
+
peft_config = LoraConfig(
|
123 |
+
lora_alpha=128,
|
124 |
+
lora_dropout=0.05,
|
125 |
+
r=256,
|
126 |
+
bias="none",
|
127 |
+
target_modules="all-linear",
|
128 |
+
task_type="CAUSAL_LM"
|
129 |
+
)
|
130 |
+
```
|
131 |
+
|
132 |
+
Training arguments:
|
133 |
+
```py
|
134 |
+
args = TrainingArguments(
|
135 |
+
output_dir="Qra-1b-dolly-instruction-0.1",
|
136 |
+
num_train_epochs=3,
|
137 |
+
per_device_train_batch_size=3,
|
138 |
+
gradient_accumulation_steps=2,
|
139 |
+
gradient_checkpointing=True,
|
140 |
+
optim="adamw_torch_fused",
|
141 |
+
logging_steps=10,
|
142 |
+
save_strategy="epoch",
|
143 |
+
learning_rate=2e-4,
|
144 |
+
bf16=True,
|
145 |
+
tf32=True,
|
146 |
+
max_grad_norm=0.3,
|
147 |
+
warmup_ratio=0.03,
|
148 |
+
lr_scheduler_type="constant",
|
149 |
+
push_to_hub=False,
|
150 |
+
report_to=["tensorboard"],
|
151 |
+
)
|
152 |
+
```
|
153 |
+
|
154 |
+
|
155 |
+
### Framework versions
|
156 |
+
|
157 |
+
- PEFT 0.10.0
|
158 |
+
- Transformers 4.39.2
|
159 |
+
- Pytorch 2.2.2+cu121
|
160 |
+
- Datasets 2.18.0
|
161 |
+
- Tokenizers 0.15.2
|