Views
No views yet
1from transformers import TextStreamer
2from unsloth import FastLanguageModel
3import torch
4max_seq_length = 2048 # Choose any! We auto support RoPE Scaling internally!
5dtype = 'Bfloat16' # None for auto detection. Float16 for Tesla T4, V100, Bfloat16 for Ampere+
6load_in_4bit = True
7model, tokenizer = FastLanguageModel.from_pretrained(
8 model_name ="alibidaran/Qwen3-instructive_reasoning",
9 max_seq_length = max_seq_length,
10 #dtype = dtype,
11 load_in_4bit = load_in_4bit,
12 #fast_inference = True, # Enable vLLM fast inference
13 max_lora_rank = 128,
14 gpu_memory_utilization = 0.6, # Reduce if out of memory
15 # token = "hf_...", # use one if using gated models like meta-llama/Llama-2-7b-hf
16)
17FastLanguageModel.for_inference(model) # Enable native 2x faster inference
18system_prompt="""
19 You are a reasonable expert who thinks and answer the users question.
20 Before respond first think and create a chain of thoughts in your mind.
21 Then respond to the client.
22 Your chain of thought and reflection must be in <thinking>..</thinking> format and your respond
23 should be in the <output>..</output> format.
24 """
25
26messages = [
27 {'role':'system','content':system_prompt},
28 {"role": "user", "content":'How many r has the word of strawberry?' },
29
30]
31inputs = tokenizer.apply_chat_template(
32 messages,
33 tokenize = True,
34 add_generation_prompt = True, # Must add for generation
35 return_tensors = "pt",
36).to("cuda")
37
38text_streamer = TextStreamer(tokenizer, skip_prompt = True)
39_ = model.generate(input_ids = inputs, streamer = text_streamer, max_new_tokens =2048,
40 use_cache = True, temperature = 0.7, min_p = 0.9)
41