|
from transformers import AutoTokenizer, AutoModelForCausalLM |
|
import torch |
|
|
|
|
|
model_path = '/path/to/your/quantized_model_directory' |
|
|
|
|
|
tokenizer = AutoTokenizer.from_pretrained(model_name) |
|
|
|
|
|
quantized_model = AutoModelForCausalLM.from_pretrained(model_path) |
|
|
|
|
|
device = torch.device("cuda" if torch.cuda.is_available() else "cpu") |
|
quantized_model.to(device) |
|
|
|
|
|
text_input = "How did Tesla perform in Q1 2024?" |
|
|
|
|
|
inputs = tokenizer(text_input, return_tensors="pt").to(device) |
|
|
|
|
|
outputs = quantized_model.generate(**inputs, max_length=150, do_sample=False) |
|
|
|
|
|
response = tokenizer.decode(outputs[0], skip_special_tokens=True) |
|
|
|
|
|
print(f"Generated response: {response}") |