Views
No views yet
unsloth (see Docs).1import torch
2from unsloth import FastLanguageModel
3
4model, tokenizer = FastLanguageModel.from_pretrained(
5 model_name="eurecom-ds/qwen3-4b-socratic",
6 dtype=torch.bfloat16,
7 max_seq_length=1024,
8 load_in_4bit=False,
9 load_in_8bit=False,
10)
11
12model = FastLanguageModel.for_inference(model)
13
14# ✅ Patch apply_chat_template to default enable_thinking=False
15if hasattr(tokenizer, "apply_chat_template"):
16 original_fn = tokenizer.apply_chat_template
17
18 def patched_apply_chat_template(conversation, **kwargs):
19 kwargs.setdefault("enable_thinking", False)
20 return original_fn(conversation, **kwargs)
21
22 tokenizer.apply_chat_template = patched_apply_chat_template
23
24messages = [
25 {"role": "user", "content": "why is the sky blue?"},
26]
27
28raw_prompt = tokenizer.apply_chat_template(
29 messages, tokenize=False, add_generation_prompt=True, enable_thinking=False
30)
31inputs = tokenizer([raw_prompt], return_tensors="pt").to("cuda")
32outputs = model.generate(
33 **inputs, max_new_tokens=128, do_sample=True, temperature=0.3
34)
35generation = outputs[0, len(inputs['input_ids'][0]):]
36decoded = tokenizer.decode(generation, skip_special_tokens=True)
37
38print(decoded)
39# Have you ever looked at the sky on a clear day and wondered why it appears blue? What do you think might be happening with the light from the sun that makes the sky look that way?