Update README.md
Browse files
README.md
CHANGED
|
@@ -61,11 +61,20 @@ This is a work in progress. I plan to continue the fine-tuning process with bett
|
|
| 61 |
|
| 62 |
```python
|
| 63 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
|
|
|
| 64 |
|
| 65 |
-
|
| 66 |
|
| 67 |
-
|
| 68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
|
| 70 |
prompt = "Прывітанне! Распавядзі мне пра Беларусь."
|
| 71 |
messages = [
|
|
@@ -73,22 +82,11 @@ messages = [
|
|
| 73 |
{"role": "user", "content": prompt}
|
| 74 |
]
|
| 75 |
|
| 76 |
-
text = tokenizer.apply_chat_template(
|
| 77 |
-
messages,
|
| 78 |
-
tokenize=False,
|
| 79 |
-
add_generation_prompt=True
|
| 80 |
-
)
|
| 81 |
-
|
| 82 |
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
|
| 83 |
|
| 84 |
-
generated_ids = model.generate(
|
| 85 |
-
|
| 86 |
-
max_new_tokens=512
|
| 87 |
-
)
|
| 88 |
-
|
| 89 |
-
generated_ids = [
|
| 90 |
-
output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
|
| 91 |
-
]
|
| 92 |
|
| 93 |
response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
| 94 |
print(response)
|
|
|
|
| 61 |
|
| 62 |
```python
|
| 63 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 64 |
+
from peft import PeftModel, PeftConfig
|
| 65 |
|
| 66 |
+
peft_model_id = "Aleton/qwen3-belarusian"
|
| 67 |
|
| 68 |
+
config = PeftConfig.from_pretrained(peft_model_id)
|
| 69 |
+
|
| 70 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 71 |
+
config.base_model_name_or_path,
|
| 72 |
+
device_map="auto",
|
| 73 |
+
trust_remote_code=True
|
| 74 |
+
)
|
| 75 |
+
tokenizer = AutoTokenizer.from_pretrained(config.base_model_name_or_path)
|
| 76 |
+
|
| 77 |
+
model = PeftModel.from_pretrained(model, peft_model_id)
|
| 78 |
|
| 79 |
prompt = "Прывітанне! Распавядзі мне пра Беларусь."
|
| 80 |
messages = [
|
|
|
|
| 82 |
{"role": "user", "content": prompt}
|
| 83 |
]
|
| 84 |
|
| 85 |
+
text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
|
| 87 |
|
| 88 |
+
generated_ids = model.generate(model_inputs.input_ids, max_new_tokens=512)
|
| 89 |
+
generated_ids = [output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
|
| 91 |
response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
| 92 |
print(response)
|