Views
No views yet


| Task | Result |
|---|---|
| Basic Communication | Improved |
| Translation | Improved |
| Mathematics | Improved |
| Physics | Improved |
| Biology | Improved |
| Medicine | Improved |
| Coding | Improved |
| Agent Functions | Improved |
1from transformers
2import AutoModelForCausalLM, AutoTokenizer
3
4model_name = "fluently/FluentlyQwen3-4B"
5
6# load the tokenizer and the model
7tokenizer = AutoTokenizer.from_pretrained(model_name)
8model = AutoModelForCausalLM.from_pretrained(
9 model_name,
10 torch_dtype="auto",
11 device_map="auto"
12)
13
14# prepare the model input
15prompt = "Give me a short introduction to large language model."
16messages = [
17 {"role": "user", "content": prompt}
18]
19text = tokenizer.apply_chat_template(
20 messages,
21 tokenize=False,
22 add_generation_prompt=True,
23 enable_thinking=True # Switches between thinking and non-thinking modes. Default is True.
24)
25model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
26
27# conduct text completion
28generated_ids = model.generate(
29 **model_inputs,
30 max_new_tokens=32768
31)
32output_ids = generated_ids[0][len(model_inputs.input_ids[0]):].tolist()
33
34# parsing thinking content
35try:
36 # rindex finding 151668 (</think>)
37 index = len(output_ids) - output_ids[::-1].index(151668)
38except ValueError:
39 index = 0
40
41thinking_content = tokenizer.decode(output_ids[:index], skip_special_tokens=True).strip("\n")
42content = tokenizer.decode(output_ids[index:], skip_special_tokens=True).strip("\n")
43
44print("thinking content:", thinking_content)
45print("content:", content)[!TIP] Theenable_thinkingswitch is also available in APIs created by SGLang and vLLM.
enable_thinking=Trueenable_thinking=True or leaving it as the default value in tokenizer.apply_chat_template, the model will engage its thinking mode.1text = tokenizer.apply_chat_template(
2 messages,
3 tokenize=False,
4 add_generation_prompt=True,
5 enable_thinking=True # True is the default value for enable_thinking
6)<think>...</think> block, followed by the final response.[!NOTE] For thinking mode, useTemperature=0.6,TopP=0.95,TopK=20andMinP=0(the default setting ingeneration_config.json). DO NOT use greedy decoding, as it can lead to performance degradation and endless repetitions.
enable_thinking=False1text = tokenizer.apply_chat_template(
2 messages,
3 tokenize=False,
4 add_generation_prompt=True,
5 enable_thinking=False # Setting enable_thinking=False disables thinking mode
6)<think>...</think> block.[!NOTE] For non-thinking mode, we suggest usingTemperature=0.7,TopP=0.8,TopK=20, andMinP=0.