阿里又开源了,超长上下文大模型

360影视 国产动漫 2025-05-27 21:29 3

摘要:大型推理模型(LRMs)通过强化学习(RL)展现出强大的推理能力,但局限于短上下文推理任务,这个 QwenLong-L1 框架,通过渐进式上下文扩展将短上下文 LRMs 适配至长上下文场景。

大家好,我是 Ai 学习的老章

阿里又开源新模型了,这次是通义千问文档团队带来的 QwenLong-L1-32B——首个通过强化学习训练、专为长上下文推理设计的大语言模型。

解决的问题是:

大型推理模型(LRMs)通过强化学习(RL)展现出强大的推理能力,但局限于短上下文推理任务,这个 QwenLong-L1 框架,通过渐进式上下文扩展将短上下文 LRMs 适配至长上下文场景。

在七个长上下文文档问答基准测试上的实验表明,QwenLong - L1 - 32B 优于 OpenAI - o3 - mini 和 Qwen3 - 235B - A22B 等旗舰大推理模型,性能与 Claude - 3.7 - Sonnet - Thinking 相当,在当前最先进的大推理模型中表现领先。

框架通过强化学习训练中的渐进式上下文扩展,增强了短上下文语言推理模型的能力。

该框架包含三个核心组件:用于初始化稳健策略的预热监督微调(SFT)阶段、通过课程引导实现从短上下文到长上下文稳定适应的强化学习阶段,以及可调整各阶段训练复杂度的难度感知回溯采样机制,以此激励策略探索。借助包括 GRPO 和 DAPO 在内的最新强化学习算法,框架整合了结合基于规则和基于模型的二元结果奖励的混合奖励函数,以平衡精确率与召回率。通过在策略优化中策略性地利用群体相对优势,它引导语言推理模型学习对实现稳健长上下文理解及卓越推理能力至关重要的有效推理模式。

该框架由多个具有渐进式上下文扩展的训练阶段组成。每个阶段都针对越来越长的上下文长度,允许模型从短文本熟练度逐渐适应到长文本专业知识。

QWENLONG-L1 出自通义千问文档团队,感觉最适合的场景还是对上下文要求比较高的几个场景:

研究和科学发现:处理大量的文献和数据集• 文档分析:自动分析法律文件、研究论文和报告• 知识检索:跨大型知识库进行复杂的问题回答# Create the conda environmentconda create -n qwenlongl1 python==3.10conda activate qwenlongl1# clone repogit clone https://github.com/Tongyi-Zhiwen/QwenLong-L1cd QwenLong-L1# Install requirementspip3 install -r requirements.txt# Install verlcd verlpip3 install -e .# Install vLLMpip3 install vllm==0.7.3 # Install flash-attnpip3 install flash-attn --no-build-isolation

这个新模型还没有适配 VLLM 和 SGLang,只能通过 transformers 运行

from transformers import AutoModelForCausalLM, AutoTokenizermodel_name = "Tongyi-Zhiwen/QwenLong-L1-32B"# load the tokenizer and the modeltokenizer = AutoTokenizer.from_pretrained(model_name)model = AutoModelForCausalLM.from_pretrained(model_name,torch_dtype="auto",device_map="auto")# prepare the model inputtemplate = """Please read the following text and answer the question below.$DOC$$Q$Format your response as follows: "Therefore, the answer is (insert answer here)"."""context = "" question = ""prompt = template.replace('$DOC$', context.strip).replace('$Q$', question.strip)messages = [{"role": "user", "content": prompt}]text = tokenizer.apply_chat_template(messages,tokenize=False,add_generation_prompt=True)model_inputs = tokenizer([text], return_tensors="pt").to(model.device)# conduct text completiongenerated_ids = model.generate(**model_inputs,max_new_tokens=10000,temperature=0.7,top_p=0.95)output_ids = generated_ids[0][len(model_inputs.input_ids[0]):].tolist # parsing thinking contenttry:# rindex finding 151649 ()index = len(output_ids) - output_ids[::-1].indexexcept ValueError: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("thinking content:", thinking_content)print("content:", content)

借助大模型,我把这篇文论转成了 PPT,感兴趣可以深入看看

GitHub: https://github.com/Tongyi-Zhiwen/QwenLong-L1
HuggingFace: https://huggingface.co/Tongyi-Zhiwen/QwenLong-L1-32B
ModelScope: https://modelscope.cn/models/iic/QwenLong-L1-32B

制作不易,如果这篇文章觉得对你有用,可否点个关注。给我个三连击:点赞、转发和在看。若可以再给我加个,谢谢你看我的文章,我们下篇再见!

搭建完美的写作环境:工具篇(12 章)
图解机器学习 - 中文版(72 张 PNG)
ChatGPT、大模型系列研究报告(50 个 PDF)
108 页 PDF 小册子:搭建机器学习开发环境及 Python 基础
116 页 PDF 小册子:机器学习中的概率论、统计学、线性代数
史上最全!371 张速查表,涵盖 AI、ChatGPT、Python、R、深度学习、机器学习等

来源:章北海一点号1

相关推荐