Update README.md
Browse files
README.md
CHANGED
|
@@ -59,31 +59,35 @@ To verify results locally using the transformers and peft libraries:
|
|
| 59 |
```
|
| 60 |
|
| 61 |
from peft import PeftModel
|
| 62 |
-
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 63 |
import torch
|
| 64 |
|
| 65 |
-
# 1.
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
device_map="auto"
|
| 72 |
)
|
| 73 |
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
model = PeftModel.from_pretrained(model, adapter_path)
|
| 77 |
-
tokenizer = AutoTokenizer.from_pretrained(adapter_path)
|
| 78 |
-
tokenizer.pad_token = tokenizer.eos_token
|
| 79 |
|
| 80 |
-
# 3.
|
| 81 |
ticket = "### Instruction:\nTicket: 'VPN access denied for user in Mangalore office.'\n\n### Response:\n"
|
| 82 |
inputs = tokenizer(ticket, return_tensors="pt").to("cuda")
|
| 83 |
|
| 84 |
-
# Generate response
|
| 85 |
with torch.no_grad():
|
| 86 |
-
outputs = model.generate(**inputs, max_new_tokens=64
|
| 87 |
|
| 88 |
print(tokenizer.decode(outputs[0], skip_special_tokens=True).split("### Response:\n")[-1])
|
| 89 |
|
|
|
|
| 59 |
```
|
| 60 |
|
| 61 |
from peft import PeftModel
|
| 62 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
|
| 63 |
import torch
|
| 64 |
|
| 65 |
+
# 1. Setup 4-bit configuration
|
| 66 |
+
quantization_config = BitsAndBytesConfig(
|
| 67 |
+
load_in_4bit=True,
|
| 68 |
+
bnb_4bit_compute_dtype=torch.float16,
|
| 69 |
+
bnb_4bit_quant_type="nf4"
|
| 70 |
+
)
|
| 71 |
+
|
| 72 |
+
# 2. Load Base Model and Adapter
|
| 73 |
+
base_model_id = "mistralai/Mistral-7B-v0.3"
|
| 74 |
+
adapter_id = "rakshath1/it-support-mistral-7b-expert"
|
| 75 |
+
|
| 76 |
+
base_model = AutoModelForCausalLM.from_pretrained(
|
| 77 |
+
base_model_id,
|
| 78 |
+
quantization_config=quantization_config,
|
| 79 |
device_map="auto"
|
| 80 |
)
|
| 81 |
|
| 82 |
+
model = PeftModel.from_pretrained(base_model, adapter_id)
|
| 83 |
+
tokenizer = AutoTokenizer.from_pretrained(base_model_id)
|
|
|
|
|
|
|
|
|
|
| 84 |
|
| 85 |
+
# 3. Inference
|
| 86 |
ticket = "### Instruction:\nTicket: 'VPN access denied for user in Mangalore office.'\n\n### Response:\n"
|
| 87 |
inputs = tokenizer(ticket, return_tensors="pt").to("cuda")
|
| 88 |
|
|
|
|
| 89 |
with torch.no_grad():
|
| 90 |
+
outputs = model.generate(**inputs, max_new_tokens=64)
|
| 91 |
|
| 92 |
print(tokenizer.decode(outputs[0], skip_special_tokens=True).split("### Response:\n")[-1])
|
| 93 |
|