Views
No views yet
### Question ...
### Explanation ...
### Answer:1from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
2
3model_id = "ShAIkespear/Phi-2_DPO_M3_Quantized_Alt"
4
5bnb_cfg = BitsAndBytesConfig(
6 load_in_4bit=True,
7 bnb_4bit_quant_type="nf4",
8 bnb_4bit_use_double_quant=True, # often improves stability
9 bnb_4bit_compute_dtype="bfloat16" # or "float16" depending on your GPU
10)
11
12tok = AutoTokenizer.from_pretrained(model_id, use_fast=True)
13model = AutoModelForCausalLM.from_pretrained(
14 model_id, device_map="auto", quantization_config=bnb_cfg
15)
16
17prompt = "### Question: Which planet is known as the Red Planet?\n### Explanation: Identify the planet with the reddish appearance.\n### Answer:"
18inputs = tok(prompt, return_tensors="pt").to(model.device)
19out = model.generate(**inputs, max_new_tokens=15)
20print(tok.decode(out[0], skip_special_tokens=True))