Views
No views yet
Note: DIFL is still in testing, so this model may not be great.
1from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
2from peft import PeftModel
3
4base = "Qwen/Qwen2.5-3B-Instruct"
5adapter = "oscar128372/difl-qwen2.5-3b-math"
6
7# Optional: 4-bit inference for low memory
8bnb_config = BitsAndBytesConfig(
9 load_in_4bit=True,
10 bnb_4bit_use_double_quant=True,
11 bnb_4bit_quant_type="nf4",
12 bnb_4bit_compute_dtype="float16",
13)
14
15tok = AutoTokenizer.from_pretrained(base, trust_remote_code=True)
16if tok.pad_token is None:
17 tok.pad_token = tok.eos_token
18
19model = AutoModelForCausalLM.from_pretrained(
20 base,
21 trust_remote_code=True,
22 quantization_config=bnb_config, # or remove for full-precision
23 device_map="auto",
24)
25model = PeftModel.from_pretrained(model, adapter)
26
27messages = [
28 {"role": "system", "content": "You are a helpful math assistant."},
29 {"role": "user", "content": "Find the derivative of f(x) = x^3 - 5x + 2."}
30]
31
32inputs = tok.apply_chat_template(
33 messages, add_generation_prompt=True, return_tensors="pt"
34).to(model.device)
35
36outputs = model.generate(
37 inputs,
38 max_new_tokens=256,
39 temperature=0.8,
40 top_p=0.9,
41 do_sample=True,
42 pad_token_id=tok.pad_token_id,
43 eos_token_id=tok.eos_token_id,
44)
45print(tok.decode(outputs[0], skip_special_tokens=True))