返回顶部
热门问答 更多热门问答
技术文章 更多技术文章

Qwen3 重磅开源!

[复制链接]
链载Ai 显示全部楼层 发表于 昨天 18:10 |阅读模式 打印 上一主题 下一主题

性能卓越

灵活适配多场景需求


ingFang SC", system-ui, -apple-system, "system-ui", "Helvetica Neue", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;font-size: 17px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0.544px;orphans: 2;text-align: justify;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;">

ingFang SC", system-ui, -apple-system, "system-ui", "Helvetica Neue", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;font-size: 17px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0.544px;orphans: 2;text-align: justify;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;visibility: visible;box-sizing: border-box !important;overflow-wrap: break-word !important;">作为Qwen系列全新一代的混合推理模型,Qwen3在 GPQA、AIME24/25、LiveCodeBench 等多个权威评测中表现出极具竞争力的结果。

ingFang SC", system-ui, -apple-system, "system-ui", "Helvetica Neue", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;font-size: 17px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0.544px;orphans: 2;text-align: justify;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;visibility: visible;">

ingFang SC", system-ui, -apple-system, "system-ui", "Helvetica Neue", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;font-size: 17px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0.544px;orphans: 2;text-align: center;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;visibility: visible;box-sizing: border-box !important;overflow-wrap: break-word !important;">

ingFang SC", system-ui, -apple-system, "system-ui", "Helvetica Neue", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;font-size: 17px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0.544px;orphans: 2;text-align: justify;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;visibility: visible;box-sizing: border-box !important;overflow-wrap: break-word !important;">在相同计算资源下,Qwen3 模型以更小的规模实现了对更大体量上一代模型的超越,真正做到了“小而强大”。通过引入创新的MOE(混合专家)架构,Qwen3 在效果上媲美上一代超大规模 Dense 模型的同时,效率显著提升,使复杂任务处理更加轻松高效。

ingFang SC", system-ui, -apple-system, "system-ui", "Helvetica Neue", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;font-size: 17px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0.544px;orphans: 2;text-align: justify;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;visibility: visible;box-sizing: border-box !important;overflow-wrap: break-word !important;">

此外,Qwen3 融合了推理与非推理能力,在逻辑分析和创意生成等任务中表现卓越。预训练数据量达到月36万亿tokens,并通过多轮大规模强化学习与精细优化,在推理、工具调用、指令遵循及多语言能力等方面显著提升。

其中,Qwen3-235B-A22B 表现尤为突出,刷新了开源模型的智能水平新高,显存占用仅为性能相近模型的三分之一。无论是数学推理、代码生成还是综合逻辑分析, Qwen3 均展现出卓越能力,稳居全球开源模型前列。在工具调用方面表现优异,大幅降低了复杂任务的实现门槛,同时还支持119种语言,覆盖全球主要语种,满足多样化需求。


思考与非思考模式

灵活应对不同场景


ingFang SC", system-ui, -apple-system, "system-ui", "Helvetica Neue", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;font-size: 17px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0.544px;orphans: 2;text-align: justify;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;">

Qwen3 引入了“思考模式”和“非思考模式”,使模型能够在不同场景下表现出最佳性能。在思考模式模式下,模型会进行多步推理和深度分析,类似于人类在解决复杂问题时的“深思熟虑”。(eg:在回答数学题或编写复杂代码时,模型会反复验证逻辑并优化输出结果。)


在非思考模式模式下,模型优先追求响应速度和效率,适用于简单任务或实时交互。(eg:在日常对话或快速问答中,模型会跳过复杂的推理步骤,直接给出答案。)


你可以通过简单的指令或配置文件在两种模式之间切换。


启用思考模式:默认情况下,Qwen3 启用了思考能力enable_thinking=True。在此模式下,模型会在生成响应前进行深度分析,并输出包裹在<think>...</think>块中的思考过程。


关闭思考模式:如果需要禁用思考行为,可以设置 enable_thinking=False,使模型功能与 Qwen2.5-Instruct 保持一致。此模式适合对响应速度要求较高的场景。


软开关机制:Qwen3 支持动态切换思考模式,你可通过ingFang SC", system-ui, -apple-system, "system-ui", "Helvetica Neue", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;font-size: 17px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;orphans: 2;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;visibility: visible;background-color: rgb(236 236 236 / var(--tw-bg-opacity, 1));color: rgb(235, 87, 87);letter-spacing: 0.12pt;box-sizing: border-box !important;overflow-wrap: break-word !important;">/think启用深度推理或ingFang SC", system-ui, -apple-system, "system-ui", "Helvetica Neue", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;font-size: 17px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;orphans: 2;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;visibility: visible;background-color: rgb(236 236 236 / var(--tw-bg-opacity, 1));color: rgb(235, 87, 87);letter-spacing: 0.12pt;box-sizing: border-box !important;overflow-wrap: break-word !important;">/no_think快速关闭。模型会根据最新指令调整行为,灵活适应不同需求。以下是一个多轮对话示例:


fromtransformersimportAutoModelForCausalLM,AutoTokenizerclassQwenChatbot:def__init__(self,model_name="Qwen3-30B-A3B/Qwen3-30B-A3B"):self.tokenizer=AutoTokenizer.from_pretrained(model_name)self.model=AutoModelForCausalLM.from_pretrained(model_name)self.history=[]defgenerate_response(self,user_input):messages=self.history+[{"role":"user","content":user_input}]text=self.tokenizer.apply_chat_template(messages,tokenize=False,add_generation_prompt=True)inputs=self.tokenizer(text,return_tensors="pt")response_ids=self.model.generate(**inputs,max_new_tokens=32768)[0][len(inputs.input_ids[0]):].tolist()response=self.tokenizer.decode(response_ids,skip_special_tokens=True)#Updatehistoryself.history.append({"role":"user","content":user_input})self.history.append({"role":"assistant","content":response})returnresponse#ExampleUsageif__name__=="__main__":chatbot=QwenChatbot()#Firstinput(without/thinkor/no_thinktags,thinkingmodeisenabledbydefault)user_input_1="Howmanyr'sinstrawberries?"print(f"User:{user_input_1}")response_1=chatbot.generate_response(user_input_1)print(f"Bot:{response_1}")print("----------------------")#Secondinputwith/no_thinkuser_input_2="Then,howmanyr'sinblueberries?/no_think"print(f"User:{user_input_2}")response_2=chatbot.generate_response(user_input_2)print(f"Bot:{response_2}")print("----------------------")#Thirdinputwith/thinkuser_input_3="Really?/think"print(f"User:{user_input_3}")response_3=chatbot.generate_response(user_input_3)print(f"Bot:{response_3}")


如何在不同框架中使用 Qwen3 ?我们提供了一个在 Hugging Face transformers 中使用 Qwen3-30B-A3B 的标准示例:


frommodelscopeimportAutoModelForCausalLM,AutoTokenizermodel_name="Qwen/Qwen3-30B-A3B"#loadthetokenizerandthemodeltokenizer=AutoTokenizer.from_pretrained(model_name)model=AutoModelForCausalLM.from_pretrained(model_name,torch_dtype="auto",device_map="auto")#preparethemodelinputprompt="Givemeashortintroductiontolargelanguagemodel."messages=[{"role":"user","content":prompt}]text=tokenizer.apply_chat_template(messages,tokenize=False,add_generation_prompt=True,enable_thinking=True#Switchbetweenthinkingandnon-thinkingmodes.DefaultisTrue.)model_inputs=tokenizer([text],return_tensors="pt").to(model.device)#conducttextcompletiongenerated_ids=model.generate(**model_inputs,max_new_tokens=32768)output_ids=generated_ids[0][len(model_inputs.input_ids[0]):].tolist()#parsingthinkingcontenttry:#rindexfinding151668(</think>)index=len(output_ids)-output_ids[::-1].index(151668)exceptValueError:index=0thinking_content=tokenizer.decode(output_ids[:index],skip_special_tokens=True).strip("\n")content=tokenizer.decode(output_ids[index:],skip_special_tokens=True).strip("\n")print("thinkingcontent:",thinking_content)print("content:",content)

要禁用思考模式,只需对参数 enable_thinking 进行如下修改:

text=tokenizer.apply_chat_template(messages,tokenize=False,add_generation_prompt=True,enable_thinking=False#Trueisthedefaultvalueforenable_thinking.)


对于部署,您可以使用 sglang>=0.4.6.post1 或 vllm>=0.8.4来创建一个与 OpenAI API 兼容的 API endpoint:


SGLang:

python-msglang.launch_server--model-pathQwen/Qwen3-30B-A3B--reasoning-parserqwen3


vLLM:

vllmserveQwen/Qwen3-30B-A3B--enable-reasoning--reasoning-parserDeepSeek_r1


要禁用思考模式,您可以移除参数 --reasoning-parser(以及 --enable-reasoning)。


如果用于本地开发,您可以通过运行简单的命令 Ollama run qwen3:30b-a3b 来使用 ollama 与模型进行交互。您也可以使用 LMStudio 或者 llama.cpp 以及 ktransformers 等代码库进行本地开发。


Agent示例


你还可以使用Qwen-Agent 来充分发挥 Qwen3 的 Agent 能力。Qwen-Agent 内部封装了工具调用模板和工具调用解析器,大大降低了代码复杂性。


要定义可用的工具,您可以使用 MCP 配置文件,使用 Qwen-Agent 内置的工具,或者自行集成其他工具。


fromqwen_agent.agentsimportAssistant#DefineLLMllm_cfg={'model':'Qwen3-30B-A3B',#UsetheendpointprovidedbyAlibabaModelStudio:#'model_type':'qwen_dashscope',#'api_key's.getenv('DASHSCOPE_API_KEY'),#UseacustomendpointcompatiblewithOpenAIAPI:'model_server':'http://localhost:8000/v1',#api_base'api_key':'EMPTY',#Otherparameters:#'generate_cfg':{##Add:Whentheresponsecontentis`<think>thisisthethought</think>thisistheanswer;##Donotadd:Whentheresponsehasbeenseparatedbyreasoning_contentandcontent.#'thought_in_content':True,#},}#DefineToolstools=[{'mcpServers':{#YoucanspecifytheMCPconfigurationfile'time':{'command':'uvx','args':['mcp-server-time','--local-timezone=Asia/Shanghai']},"fetch":{"command":"uvx","args":["mcp-server-fetch"]}}},'code_interpreter',#Built-intools]#DefineAgentbot=Assistant(llm=llm_cfg,function_list=tools)#Streaminggenerationmessages=[{'role':'user','content':'https://qwenlm.github.io/blog/IntroducethelatestdevelopmentsofQwen'}]forresponsesinbot.run(messages=messages):passprint(responses)

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

链载AI是专业的生成式人工智能教程平台。提供Stable Diffusion、Midjourney AI绘画教程,Suno AI音乐生成指南,以及Runway、Pika等AI视频制作与动画生成实战案例。从提示词编写到参数调整,手把手助您从入门到精通。
  • 官方手机版

  • 微信公众号

  • 商务合作

  • Powered by Discuz! X3.5 | Copyright © 2025-2025. | 链载Ai
  • 桂ICP备2024021734号 | 营业执照 | |广西笔趣文化传媒有限公司|| QQ