Views
No views yet


1from transformers import AutoModelForCausalLM, AutoTokenizer
2from transformers.generation import GenerationConfig
3
4MODEL_NAME = "Zhihu-ai/Zhi-Create-Qwen3-32B"
5tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME, trust_remote_code=True)
6
7# use bf16
8# model = AutoModelForCausalLM.from_pretrained(MODEL_NAME, device_map="auto", trust_remote_code=True, bf16=True).eval()
9# use fp16
10# model = AutoModelForCausalLM.from_pretrained(MODEL_NAME, device_map="auto", trust_remote_code=True, fp16=True).eval()
11# use cpu only
12# model = AutoModelForCausalLM.from_pretrained(MODEL_NAME, device_map="cpu", trust_remote_code=True).eval()
13# use auto mode, automatically select precision based on the device.
14model = AutoModelForCausalLM.from_pretrained(
15 MODEL_NAME,
16 device_map="auto",
17 trust_remote_code=True
18).eval()
19
20# Specify hyperparameters for generation. But if you use transformers>=4.32.0, there is no need to do this.
21# model.generation_config = GenerationConfig.from_pretrained(MODEL_NAME, trust_remote_code=True)
22
23generate_configs = {
24 "temperature": 0.6,
25 "do_sample": True,
26 "top_p": 0.95,
27 "max_new_tokens": 4096
28}
29
30prompt = "请你以鲁迅的口吻,写一篇介绍西湖醋鱼的文章"
31messages = [
32 {"role": "user", "content": prompt}
33]
34text = tokenizer.apply_chat_template(
35 messages,
36 tokenize=False,
37 add_generation_prompt=True
38)
39
40model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
41
42generated_ids = model.generate(
43 **model_inputs,
44 **generate_configs
45)
46generated_ids = [
47 output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
48]
49
50response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
51print(response)1docker run -it --net=host --gpus='"device=0"' -v /path/to/model:/mnt/models --entrypoints="" ghcr.io/zhihu/zhilight/zhilight:0.4.21-cu124 python -m zhilight.server.openai.entrypoints.api_server --model-path /mnt/models --port 8000 --enable-reasoning --reasoning-parser deepseek-r1 --served-model-name Zhi-Create-Qwen3-32B
2
3curl http://localhost:8000/v1/completions \
4 -H "Content-Type: application/json" \
5 -d '{
6 "model": "Zhi-Create-Qwen3-32B",
7 "prompt": "请你以鲁迅的口吻,写一篇介绍西湖醋鱼的文章",
8 "max_tokens": 4096,
9 "temperature": 0.6,
10 "top_p": 0.95
11 }'1# install vllm
2pip install vllm>=0.6.4.post1
3
4# huggingface model id
5vllm serve Zhihu-ai/Zhi-Create-Qwen3-32B --served-model-name Zhi-Create-Qwen3-32B --port 8000
6
7# local path
8vllm serve /path/to/model --served-model-name Zhi-Create-Qwen3-32B --port 8000
9
10curl http://localhost:8000/v1/completions \
11 -H "Content-Type: application/json" \
12 -d '{
13 "model": "Zhi-Create-Qwen3-32B",
14 "prompt": "请你以鲁迅的口吻,写一篇介绍西湖醋鱼的文章",
15 "max_tokens": 4096,
16 "temperature": 0.6,
17 "top_p": 0.95
18 }'1# install SGLang
2pip install "sglang[all]>=0.4.5" --find-links https://flashinfer.ai/whl/cu124/torch2.5/flashinfer-python
3
4# huggingface model id
5python -m sglang.launch_server --model-path Zhihu-ai/Zhi-Create-Qwen3-32B --served-model-name Zhi-Create-Qwen3-32B --port 8000
6
7# local path
8python -m sglang.launch_server --model-path /path/to/model --served-model-name Zhi-Create-Qwen3-32B --port 8000
9
10# send request
11curl http://localhost:8000/v1/completions \
12 -H "Content-Type: application/json" \
13 -d '{
14 "model": "Zhi-Create-Qwen3-32B",
15 "prompt": "请你以鲁迅的口吻,写一篇介绍西湖醋鱼的文章",
16 "max_tokens": 4096,
17 "temperature": 0.6,
18 "top_p": 0.95
19 }'
20
21# Alternative: Using OpenAI API
22from openai import OpenAI
23openai_api_key = "empty"
24openai_api_base = "http://127.0.0.1:8000/v1"
25
26client = OpenAI(
27 api_key=openai_api_key,
28 base_url=openai_api_base
29)
30
31def get_answer(messages):
32 response = client.chat.completions.create(
33 messages=messages,
34 model="Zhi-Create-Qwen3-32B",
35 max_tokens=4096,
36 temperature=0.3,
37 top_p=0.95,
38 stream=True,
39 extra_body = {"chat_template_kwargs": {"enable_thinking": True}}
40 )
41 answer = ""
42 reasoning_content_all = ""
43 for each in response:
44 each_content = each.choices[0].delta.content
45 if hasattr(each.choices[0].delta, "content"):
46 each_content = each.choices[0].delta.content
47 else:
48 each_content = None
49 if hasattr(each.choices[0].delta, "reasoning_content"):
50 reasoning_content = each.choices[0].delta.reasoning_content
51 else:
52 reasoning_content = None
53 if each_content is not None:
54 answer += each_content
55 print(each_content, end="", flush=True)
56 if reasoning_content is not None:
57 reasoning_content_all += reasoning_content
58 print(reasoning_content, end="", flush=True)
59 return answer, reasoning_content_all
60
61prompt = "请你以鲁迅的口吻,写一篇介绍西湖醋鱼的文章"
62messages = [
63 {"role": "user", "content": prompt}
64]
65
66answer, reasoning_content_all = get_answer(messages)ollama run zhihu/zhi-create-qwen3-32bollama run zhihu/zhi-create-qwen3-32b:bf161@misc{Zhi-Create-Qwen3-32B,
2 title={Zhi-Create-Qwen3-32B: RAFT-Enhanced Direct Preference Optimization and Curriculum Learning for Robust Creative Writing in LLMs},
3 author={Jiewu Wang, Xu Chen, Wenyuan Su, Chao Huang, Hongkui Gao, Lin Feng, Shan Wang, Jingjing Wang, Zebin Ou},
4 year={2025},
5 eprint={},
6 archivePrefix={},
7 url={https://huggingface.co/Zhihu-ai/Zhi-Create-Qwen3-32B},
8}