Update README.md
Browse files
README.md
CHANGED
@@ -34,3 +34,31 @@ The following `bitsandbytes` quantization config was used during training:
|
|
34 |
|
35 |
|
36 |
- PEFT 0.6.2.dev0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
|
35 |
|
36 |
- PEFT 0.6.2.dev0
|
37 |
+
|
38 |
+
## Code to call this mnodel
|
39 |
+
|
40 |
+
import torch
|
41 |
+
from peft import PeftModel, PeftConfig
|
42 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
43 |
+
from transformers import BitsAndBytesConfig
|
44 |
+
|
45 |
+
peft_model_id = "meetrais/finetuned_mistral_7b"
|
46 |
+
config = PeftConfig.from_pretrained(peft_model_id)
|
47 |
+
bnb_config = BitsAndBytesConfig(
|
48 |
+
load_in_4bit=True,
|
49 |
+
bnb_4bit_use_double_quant=True,
|
50 |
+
bnb_4bit_quant_type="nf4",
|
51 |
+
bnb_4bit_compute_dtype=torch.bfloat16
|
52 |
+
)
|
53 |
+
model = AutoModelForCausalLM.from_pretrained(peft_model_id, quantization_config=bnb_config, device_map='auto')
|
54 |
+
tokenizer = AutoTokenizer.from_pretrained(config.base_model_name_or_path)
|
55 |
+
|
56 |
+
if tokenizer.pad_token is None:
|
57 |
+
tokenizer.add_special_tokens({'pad_token': '[PAD]'})
|
58 |
+
text = "Capital of USA is"
|
59 |
+
device = "cuda:0"
|
60 |
+
|
61 |
+
inputs = tokenizer(text, return_tensors="pt").to(device)
|
62 |
+
|
63 |
+
outputs = model.generate(**inputs, pad_token_id= tokenizer.eos_token_id, max_new_tokens=20)
|
64 |
+
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
|