摘要:大型推理模型(LRMs)通过强化学习(RL)展现出强大的推理能力,但局限于短上下文推理任务,这个 QwenLong-L1 框架,通过渐进式上下文扩展将短上下文 LRMs 适配至长上下文场景。
大家好,我是Ai学习的老章
阿里又开源新模型了,这次是通义千问文档团队带来的QwenLong-L1-32B——首个通过强化学习训练、专为长上下文推理设计的大语言模型。解决的问题是:
大型推理模型(LRMs)通过强化学习(RL)展现出强大的推理能力,但局限于短上下文推理任务,这个 QwenLong-L1 框架,通过渐进式上下文扩展将短上下文 LRMs 适配至长上下文场景。
框架通过强化学习训练中的渐进式上下文扩展,增强了短上下文语言推理模型的能力。
该框架包含三个核心组件:用于初始化稳健策略的预热监督微调(SFT)阶段、通过课程引导实现从短上下文到长上下文稳定适应的强化学习阶段,以及可调整各阶段训练复杂度的难度感知回溯采样机制,以此激励策略探索。借助包括 GRPO 和 DAPO 在内的最新强化学习算法,框架整合了结合基于规则和基于模型的二元结果奖励的混合奖励函数,以平衡精确率与召回率。通过在策略优化中策略性地利用群体相对优势,它引导语言推理模型学习对实现稳健长上下文理解及卓越推理能力至关重要的有效推理模式。
该框架由多个具有渐进式上下文扩展的训练阶段组成。每个阶段都针对越来越长的上下文长度,允许模型从短文本熟练度逐渐适应到长文本专业知识。 实际应用
QWENLONG-L1 出自通义千问文档团队,感觉最适合的场景还是对上下文要求比较高的几个场景:
研究和科学发现:处理大量的文献和数据集
文档分析:自动分析法律文件、研究论文和报告
知识检索:跨大型知识库进行复杂的问题回答
安装
# Create the conda environment conda create -n qwenlongl1 python==3.10 conda activate qwenlongl1 # clone repo git clone https://github.com/Tongyi-Zhiwen/QwenLong-L1 cd QwenLong-L1 # Install requirements pip3 install -r requirements.txt # Install verl cd verl pip3 install -e . # Install vLLM pip3 install vllm==0.7.3 # Install flash-attn pip3 install flash-attn --no-build-isolation使用这个新模型还没有适配VLLM和SGLang,只能通过transformers运行
from transformers import AutoModelForCausalLM, AutoTokenizer model_name = "Tongyi-Zhiwen/QwenLong-L1-32B" # load the tokenizer and the model tokenizer = AutoTokenizer.from_pretrained(model_name) model = AutoModelForCausalLM.from_pretrained( model_name, torch_dtype="auto", device_map="auto" ) # prepare the model input template = """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 completion generated_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 content try: # rindex finding 151649 index = len(output_ids) - output_ids[::-1].index except ValueError: index = 0 thinking_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,感兴趣可以深入看看
方法如下:
制作不易,如果这篇文章觉得对你有用,可否点个关注。给我个三连击:点赞、转发和在看。若可以再给我加个,谢谢你看我的文章,我们下篇再见!
来源:科技虫祥