超越GPT-4,斯坦福團(tuán)隊手機(jī)可跑的大模型火了,一夜下載量超2k
在大模型落地應(yīng)用的過程中,端側(cè) AI 是非常重要的一個方向。
近日,斯坦福大學(xué)研究人員推出的 Octopus v2 火了,受到了開發(fā)者社區(qū)的極大關(guān)注,模型一夜下載量超 2k。
20 億參數(shù)的 Octopus v2 可以在智能手機(jī)、汽車、個人電腦等端側(cè)運行,在準(zhǔn)確性和延遲方面超越了 GPT-4,并將上下文長度減少了 95%。此外,Octopus v2 比 Llama7B + RAG 方案快 36 倍。
不少網(wǎng)友感嘆:設(shè)備端 AI 智能體的時代到來了!
- 論文:Octopus v2: On-device language model for super agent
- 論文地址:https://arxiv.org/abs/2404.01744
- 模型主頁:https://huggingface.co/NexaAIDev/Octopus-v2
模型概述
Octopus-V2-2B 是一個擁有 20 億參數(shù)的開源語言模型,專為 Android API 量身定制,旨在在 Android 設(shè)備上無縫運行,并將實用性擴(kuò)展到從 Android 系統(tǒng)管理到多個設(shè)備的編排等各種應(yīng)用程序。
通常,檢索增強(qiáng)生成 (RAG) 方法需要對潛在函數(shù)參數(shù)進(jìn)行詳細(xì)描述(有時需要多達(dá)數(shù)萬個輸入 token)?;诖耍琌ctopus-V2-2B 在訓(xùn)練和推理階段引入了獨特的函數(shù) token 策略,不僅使其能夠達(dá)到與 GPT-4 相當(dāng)?shù)男阅芩剑疫€顯著提高了推理速度,超越了基于 RAG 的方法,這使得它對邊緣計算設(shè)備特別有利。
Octopus-V2-2B 能夠在各種復(fù)雜場景中生成單獨的、嵌套的和并行的函數(shù)調(diào)用。
數(shù)據(jù)集
為了訓(xùn)練、驗證和測試階段采用高質(zhì)量數(shù)據(jù)集,特別是實現(xiàn)高效訓(xùn)練,研究團(tuán)隊用三個關(guān)鍵階段創(chuàng)建數(shù)據(jù)集:
- 生成相關(guān)的查詢及其關(guān)聯(lián)的函數(shù)調(diào)用參數(shù);
- 由適當(dāng)?shù)暮瘮?shù)組件生成不相關(guān)的查詢;
- 通過 Google Gemini 實現(xiàn)二進(jìn)制驗證支持。
研究團(tuán)隊編寫了 20 個 Android API 描述,用于訓(xùn)練模型。下面是一個 Android API 描述示例:
def get_trending_news (category=None, reginotallow='US', language='en', max_results=5):
"""
Fetches trending news articles based on category, region, and language.
Parameters:
- category (str, optional): News category to filter by, by default use None for all categories. Optional to provide.
- region (str, optional): ISO 3166-1 alpha-2 country code for region-specific news, by default, uses 'US'. Optional to provide.
- language (str, optional): ISO 639-1 language code for article language, by default uses 'en'. Optional to provide.
- max_results (int, optional): Maximum number of articles to return, by default, uses 5. Optional to provide.
Returns:
- list [str]: A list of strings, each representing an article. Each string contains the article's heading and URL.
"""
模型開發(fā)與訓(xùn)練
該研究采用 Google Gemma-2B 模型作為框架中的預(yù)訓(xùn)練模型,并采用兩種不同的訓(xùn)練方法:完整模型訓(xùn)練和 LoRA 模型訓(xùn)練。
在完整模型訓(xùn)練中,該研究使用 AdamW 優(yōu)化器,學(xué)習(xí)率設(shè)置為 5e-5,warm-up 的 step 數(shù)設(shè)置為 10,采用線性學(xué)習(xí)率調(diào)度器。
LoRA 模型訓(xùn)練采用與完整模型訓(xùn)練相同的優(yōu)化器和學(xué)習(xí)率配置,LoRA rank 設(shè)置為 16,并將 LoRA 應(yīng)用于以下模塊:q_proj、k_proj、v_proj、o_proj、up_proj、down_proj。其中,LoRA alpha 參數(shù)設(shè)置為 32。
對于兩種訓(xùn)練方法,epoch 數(shù)均設(shè)置為 3。
使用以下代碼,就可以在單個 GPU 上運行 Octopus-V2-2B 模型。
from transformers import AutoTokenizer, GemmaForCausalLMimport torchimport time
def inference (input_text):
start_time = time.time ()
input_ids = tokenizer (input_text, return_tensors="pt").to (model.device)
input_length = input_ids ["input_ids"].shape [1]
outputs = model.generate (
input_ids=input_ids ["input_ids"],
max_length=1024,
do_sample=False)
generated_sequence = outputs [:, input_length:].tolist ()
res = tokenizer.decode (generated_sequence [0])
end_time = time.time ()
return {"output": res, "latency": end_time - start_time}
model_id = "NexaAIDev/Octopus-v2"
tokenizer = AutoTokenizer.from_pretrained (model_id)
model = GemmaForCausalLM.from_pretrained (
model_id, torch_dtype=torch.bfloat16, device_map="auto"
)
input_text = "Take a selfie for me with front camera"
nexa_query = f"Below is the query from the users, please call the correct function and generate the parameters to call the function.\n\nQuery: {input_text} \n\nResponse:"
start_time = time.time () print ("nexa model result:\n", inference (nexa_query)) print ("latency:", time.time () - start_time,"s")
評估
Octopus-V2-2B 在基準(zhǔn)測試中表現(xiàn)出卓越的推理速度,在單個 A100 GPU 上比「Llama7B + RAG 解決方案」快 36 倍。此外,與依賴集群 A100/H100 GPU 的 GPT-4-turbo 相比,Octopus-V2-2B 速度提高了 168%。這種效率突破歸功于 Octopus-V2-2B 的函數(shù)性 token 設(shè)計。
Octopus-V2-2B 不僅在速度上表現(xiàn)出色,在準(zhǔn)確率上也表現(xiàn)出色,在函數(shù)調(diào)用準(zhǔn)確率上超越「Llama7B + RAG 方案」31%。Octopus-V2-2B 實現(xiàn)了與 GPT-4 和 RAG + GPT-3.5 相當(dāng)?shù)暮瘮?shù)調(diào)用準(zhǔn)確率。
感興趣的讀者可以閱讀論文原文,了解更多研究內(nèi)容。
本文轉(zhuǎn)自 機(jī)器之心 ,作者:機(jī)器之心
原文鏈接:??https://mp.weixin.qq.com/s/qnFZOPLpdRxW42_cLUcImA??
