Update README.md
Browse files
README.md
CHANGED
@@ -34,6 +34,7 @@ Versions:
|
|
34 |
- Hardware: 1x RTX 3090
|
35 |
|
36 |
```python
|
|
|
37 |
from peft import PeftModel, PeftConfig
|
38 |
from transformers import AutoModelForCausalLM, AutoTokenizer, GenerationConfig
|
39 |
|
@@ -43,10 +44,19 @@ config = PeftConfig.from_pretrained(MODEL_NAME)
|
|
43 |
model = AutoModelForCausalLM.from_pretrained(
|
44 |
config.base_model_name_or_path,
|
45 |
load_in_8bit=True,
|
|
|
46 |
device_map="auto"
|
47 |
)
|
48 |
-
model = PeftModel.from_pretrained(model, MODEL_NAME,
|
49 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
```
|
51 |
|
52 |
Examples:
|
|
|
34 |
- Hardware: 1x RTX 3090
|
35 |
|
36 |
```python
|
37 |
+
import torch
|
38 |
from peft import PeftModel, PeftConfig
|
39 |
from transformers import AutoModelForCausalLM, AutoTokenizer, GenerationConfig
|
40 |
|
|
|
44 |
model = AutoModelForCausalLM.from_pretrained(
|
45 |
config.base_model_name_or_path,
|
46 |
load_in_8bit=True,
|
47 |
+
torch_dtype=torch.float16,
|
48 |
device_map="auto"
|
49 |
)
|
50 |
+
model = PeftModel.from_pretrained(model, MODEL_NAME, torch_dtype=torch.float16)
|
51 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
|
52 |
+
model.eval()
|
53 |
+
|
54 |
+
generation_config = GenerationConfig.from_pretrained(MODEL_NAME)
|
55 |
+
data = tokenizer(["Вопрос: Почему трава зеленая?\n\nВыход:"], return_tensors="pt")
|
56 |
+
data = {k: v.to(model.device) for k, v in data.items() if k in ("input_ids", "attention_mask")}
|
57 |
+
output_ids = model.generate(**data, generation_config=generation_config)[0]
|
58 |
+
print(tokenizer.decode(output_ids, skip_special_tokens=True))
|
59 |
+
|
60 |
```
|
61 |
|
62 |
Examples:
|