Views
No views yet
--tensor-type option in llama.cpp to manually "bump" important layers to higher precision. You can see the implementation here:
<think>…</think><answer>…</answer> structure, and also detects repeated content to avoid redundancy;
WritingBench (scale 1–10) & Arena-write (Elo) performance of different LLMs .

Donut charts showing win/tie/loss proportions against six baselines (left) and aggregated human evaluation (right).
1import re
2model_name = "THU-KEG/LongWriter-Zero-32B"
3
4model = AutoModelForCausalLM.from_pretrained(
5 model_name,
6 torch_dtype="auto",
7 device_map="auto"
8)
9tokenizer = AutoTokenizer.from_pretrained(model_name)
10def format_prompt_with_template(prompt):
11
12 base_format_zn = r"用户与助手之间的对话。用户提供一个写作/通用任务,助手完成它。助手首先在脑海中深入思考写作/回答过程,然后向用户提供最终的书面作品。助手应进行全面而深入的规划,确保写作/通用任务的每个方面都详细且结构合理。如果写作要求存在任何不确定性或歧义,助手应反思,向自己提出澄清性问题,并探索多种写作方式,以确保最终作品达到最高质量标准。由于写作是一个既富有创造性又需要结构性的任务,助手应从多个角度进行分析,考虑连贯性、清晰度、风格、语气、受众和目的,等等因素。此外,助手还应对作品进行审查和优化,以增强其表达效果。写作思考过程和最终的书面作品分别用 <think> </think> 和 <answer> </answer> 标签包裹,如下所示:<think>详细的写作规划和结构设计,可能包括头脑风暴、大纲制定、风格选择、受众适配、反思以及质量检查等等。</think> <answer>经过充分优化和润色的最终书面作品。</answer> <|用户|>: {question} <|助手|>:"
13 base_format_en = r"A conversation between the user and the assistant. The user provides a writing/general task, and the assistant completes it. The assistant first deeply thinks through the writing/answering process in their mind before providing the final written work to the user. The assistant should engage in comprehensive and in-depth planning to ensure that every aspect of the writing/general task is detailed and well-structured. If there is any uncertainty or ambiguity in the writing request, the assistant should reflect, ask themselves clarifying questions, and explore multiple writing approaches to ensure the final output meets the highest quality standards. Since writing is both a creative and structured task, the assistant should analyze it from multiple perspectives, considering coherence, clarity, style, tone, audience, purpose, etc.. Additionally, the assistant should review and refine the work to enhance its expressiveness. The writing thought process and the final written work should be enclosed within <think> </think> and <answer> </answer> tags, respectively, as shown below: <think>A comprehensive strategy for writing that encompasses detailed planning and structural design—including brainstorming, outlining, style selection, audience adaptation, self-reflection, quality assurance, etc..</think> <answer>The final written work after thorough optimization and refinement.</answer> <|user|>: {question} <|assistant|>:"
14 base_format = base_format_zn if re.search(r'[\u4e00-\u9fff]', prompt) else base_format_en
15 formatted_prompt = base_format.format(question=prompt)
16 return formatted_prompt
17
18prompt = "Write a 500-word story."
19messages = [
20 {"role": "user", "content": format_prompt_with_template(prompt)}
21]
22text = tokenizer.apply_chat_template(
23 messages,
24 tokenize=False,
25 add_generation_prompt=True
26)
27
28model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
29
30generated_ids = model.generate(
31 **model_inputs,
32 max_new_tokens=2048,
33 temperature=0.6,
34 do_sample=True,
35 stop_strings=["<|user|>", "<|endoftext|>", "</answer>"],
36 tokenizer=tokenizer
37)
38generated_ids = [
39 output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
40]
41
42response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
43
44print(response)<think> … </think><answer> … </answer> protocol and call the model through an SGlang-powered endpoint supporting streaming responses.1import json, requests, re
2
3def format_prompt_with_template(prompt):
4
5 base_format_zn = r"用户与助手之间的对话。用户提供一个写作/通用任务,助手完成它。助手首先在脑海中深入思考写作/回答过程,然后向用户提供最终的书面作品。助手应进行全面而深入的规划,确保写作/通用任务的每个方面都详细且结构合理。如果写作要求存在任何不确定性或歧义,助手应反思,向自己提出澄清性问题,并探索多种写作方式,以确保最终作品达到最高质量标准。由于写作是一个既富有创造性又需要结构性的任务,助手应从多个角度进行分析,考虑连贯性、清晰度、风格、语气、受众和目的,等等因素。此外,助手还应对作品进行审查和优化,以增强其表达效果。写作思考过程和最终的书面作品分别用 <think> </think> 和 <answer> </answer> 标签包裹,如下所示:<think>详细的写作规划和结构设计,可能包括头脑风暴、大纲制定、风格选择、受众适配、反思以及质量检查等等。</think> <answer>经过充分优化和润色的最终书面作品。</answer> <|用户|>: {question} <|助手|>:"
6 base_format_en = r"A conversation between the user and the assistant. The user provides a writing/general task, and the assistant completes it. The assistant first deeply thinks through the writing/answering process in their mind before providing the final written work to the user. The assistant should engage in comprehensive and in-depth planning to ensure that every aspect of the writing/general task is detailed and well-structured. If there is any uncertainty or ambiguity in the writing request, the assistant should reflect, ask themselves clarifying questions, and explore multiple writing approaches to ensure the final output meets the highest quality standards. Since writing is both a creative and structured task, the assistant should analyze it from multiple perspectives, considering coherence, clarity, style, tone, audience, purpose, etc.. Additionally, the assistant should review and refine the work to enhance its expressiveness. The writing thought process and the final written work should be enclosed within <think> </think> and <answer> </answer> tags, respectively, as shown below: <think>A comprehensive strategy for writing that encompasses detailed planning and structural design—including brainstorming, outlining, style selection, audience adaptation, self-reflection, quality assurance, etc..</think> <answer>The final written work after thorough optimization and refinement.</answer> <|user|>: {question} <|assistant|>:"
7 base_format = base_format_zn if re.search(r'[\u4e00-\u9fff]', prompt) else base_format_en
8 formatted_prompt = base_format.format(question=prompt)
9 return formatted_prompt
10
11
12
13prompt = "XXXX" # ← replace with your writing task
14data = {
15 "model": "LongWriter-Zero-32B",
16 "prompt": format_prompt_with_template(prompt),
17 "temperature": 0.6,
18 "top_p": 0.95,
19 "max_tokens": 15500,
20 "stop": ["<|user|>", "<|endoftext|>", "</answer>"],
21 "stream": True,
22}
23
24# SGlang Gateway (example)
25response = requests.post(
26 "http://XXXX:9999/v1/completions", # ← replace with your IP
27 json=data,
28 headers={"Content-Type": "application/json"},
29 timeout=1200,
30 stream=True,
31)
32
33for chunk in response.iter_lines():
34 if chunk and chunk.startswith(b"data:"):
35 if chunk == b"data: [DONE]":
36 break
37 payload = json.loads(chunk[5:])
38 print(payload["choices"][0]["text"], end="", flush=True)1@misc{wu2025longwriterzeromasteringultralongtext,
2 title={LongWriter-Zero: Mastering Ultra-Long Text Generation via Reinforcement Learning},
3 author={Yuhao Wu and Yushi Bai and Zhiqiang Hu and Roy Ka-Wei Lee and Juanzi Li},
4 year={2025},
5 eprint={2506.18841},
6 archivePrefix={arXiv},
7 primaryClass={cs.CL},
8 url={https://arxiv.org/abs/2506.18841},
9}
10
11<!--End Original Model Card-->
12
13---
14
15# <span id="testllm" style="color: #7F7FFF;">🚀 If you find these models useful</span>
16
17Help me test my **AI-Powered Quantum Network Monitor Assistant** with **quantum-ready security checks**:
18
19👉 [Quantum Network Monitor](https://readyforquantum.com/?assistant=open&utm_source=huggingface&utm_medium=referral&utm_campaign=huggingface_repo_readme)
20
21
22The full Open Source Code for the Quantum Network Monitor Service available at my github repos ( repos with NetworkMonitor in the name) : [Source Code Quantum Network Monitor](https://github.com/Mungert69). You will also find the code I use to quantize the models if you want to do it yourself [GGUFModelBuilder](https://github.com/Mungert69/GGUFModelBuilder)
23
24💬 **How to test**:
25 Choose an **AI assistant type**:
26 - `TurboLLM` (GPT-4.1-mini)
27 - `HugLLM` (Hugginface Open-source models)
28 - `TestLLM` (Experimental CPU-only)
29
30### **What I’m Testing**
31I’m pushing the limits of **small open-source models for AI network monitoring**, specifically:
32- **Function calling** against live network services
33- **How small can a model go** while still handling:
34 - Automated **Nmap security scans**
35 - **Quantum-readiness checks**
36 - **Network Monitoring tasks**
37
38🟡 **TestLLM** – Current experimental model (llama.cpp on 2 CPU threads on huggingface docker space):
39- ✅ **Zero-configuration setup**
40- ⏳ 30s load time (slow inference but **no API costs**) . No token limited as the cost is low.
41- 🔧 **Help wanted!** If you’re into **edge-device AI**, let’s collaborate!
42
43### **Other Assistants**
44🟢 **TurboLLM** – Uses **gpt-4.1-mini** :
45- **It performs very well but unfortunatly OpenAI charges per token. For this reason tokens usage is limited.
46- **Create custom cmd processors to run .net code on Quantum Network Monitor Agents**
47- **Real-time network diagnostics and monitoring**
48- **Security Audits**
49- **Penetration testing** (Nmap/Metasploit)
50
51🔵 **HugLLM** – Latest Open-source models:
52- 🌐 Runs on Hugging Face Inference API. Performs pretty well using the lastest models hosted on Novita.
53
54### 💡 **Example commands you could test**:
551. `"Give me info on my websites SSL certificate"`
562. `"Check if my server is using quantum safe encyption for communication"`
573. `"Run a comprehensive security audit on my server"`
584. '"Create a cmd processor to .. (what ever you want)" Note you need to install a [Quantum Network Monitor Agent](https://readyforquantum.com/Download/?utm_source=huggingface&utm_medium=referral&utm_campaign=huggingface_repo_readme) to run the .net code on. This is a very flexible and powerful feature. Use with caution!
59
60### Final Word
61
62I fund the servers used to create these model files, run the Quantum Network Monitor service, and pay for inference from Novita and OpenAI—all out of my own pocket. All the code behind the model creation and the Quantum Network Monitor project is [open source](https://github.com/Mungert69). Feel free to use whatever you find helpful.
63
64If you appreciate the work, please consider [buying me a coffee](https://www.buymeacoffee.com/mahadeva) ☕. Your support helps cover service costs and allows me to raise token limits for everyone.
65
66I'm also open to job opportunities or sponsorship.
67
68Thank you! 😊