Views
No views yet
1from transformers import AutoModelForCausalLM, AutoTokenizer
2
3model_name = "ertghiu256/Qwen3-4B-Thinking-2507-Hermes-3"
4
5# load the tokenizer and the model
6tokenizer = AutoTokenizer.from_pretrained(model_name)
7model = AutoModelForCausalLM.from_pretrained(
8 model_name,
9 torch_dtype="auto",
10 device_map="auto"
11)
12
13# prepare the model input
14prompt = "Give me a short introduction to large language model."
15messages = [
16 {"role": "user", "content": prompt}
17]
18text = tokenizer.apply_chat_template(
19 messages,
20 tokenize=False,
21 add_generation_prompt=True,
22)
23model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
24
25# conduct text completion
26generated_ids = model.generate(
27 **model_inputs,
28 max_new_tokens=32768
29)
30output_ids = generated_ids[0][len(model_inputs.input_ids[0]):].tolist()
31
32# parsing thinking content
33try:
34 # rindex finding 151668 (</think>)
35 index = len(output_ids) - output_ids[::-1].index(151668)
36except ValueError:
37 index = 0
38
39thinking_content = tokenizer.decode(output_ids[:index], skip_special_tokens=True).strip("\n")
40content = tokenizer.decode(output_ids[index:], skip_special_tokens=True).strip("\n")
41
42print("thinking content:", thinking_content) # no opening <think> tag
43print("content:", content)vllm serve ertghiu256/Qwen3-4B-Thinking-2507-Hermes-3 --max-model-len 262144 --enable-reasoning --reasoning-parser deepseek_r1python -m sglang.launch_server --model-path ertghiu256/Qwen3-4B-Thinking-2507-Hermes-3 --context-length 262144 --reasoning-parser deepseek-r1llama-server --hf-repo ertghiu256/Qwen3-4B-Thinking-2507-Hermes-3ollama run hf.co/ertghiu256/Qwen3-4B-Thinking-2507-Hermes-3:IQ4_NLollama run hf.co/ertghiu256/Qwen3-4B-Thinking-2507-Hermes-3:Q5_K_MTemp: 0.6
Top_P: 20
Top_K: 0.95Trained with Unsloth
Training parameters
- 60 steps
- 3-e5 Learning rate
- 28k samples from Hermes 3 dataset