大家好,我是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 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(151649) 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,感興趣可以深入看看
方法如下:
制作不易,如果這篇文章覺得對你有用,可否點個關注。給我個三連擊:點贊、轉發和在看。若可以再給我加個,謝謝你看我的文章,我們下篇再見!
特別聲明:以上內容(如有圖片或視頻亦包括在內)為自媒體平臺“網易號”用戶上傳并發布,本平臺僅提供信息存儲服務。
Notice: The content above (including the pictures and videos if any) is uploaded and posted by a user of NetEase Hao, which is a social media platform and only provides information storage services.