超越GPT-4,斯坦福團(tuán)隊(duì)手機(jī)可跑的大模型火了,一夜下載量超2k
想了解更多AIGC的內(nèi)容,請(qǐng)?jiān)L問(wèn):
在大模型落地應(yīng)用的過(guò)程中,端側(cè) AI 是非常重要的一個(gè)方向。
近日,斯坦福大學(xué)研究人員推出的 Octopus v2 火了,受到了開發(fā)者社區(qū)的極大關(guān)注,模型一夜下載量超 2k。
20 億參數(shù)的 Octopus v2 可以在智能手機(jī)、汽車、個(gè)人電腦等端側(cè)運(yùn)行,在準(zhǔn)確性和延遲方面超越了 GPT-4,并將上下文長(zhǎng)度減少了 95%。此外,Octopus v2 比 Llama7B + RAG 方案快 36 倍。
不少網(wǎng)友感嘆:設(shè)備端 AI 智能體的時(shí)代到來(lái)了!
- 論文:Octopus v2: On-device language model for super agent
- 論文地址:https://arxiv.org/abs/2404.01744
- 模型主頁(yè):https://huggingface.co/NexaAIDev/Octopus-v2
模型概述
Octopus-V2-2B 是一個(gè)擁有 20 億參數(shù)的開源語(yǔ)言模型,專為 Android API 量身定制,旨在在 Android 設(shè)備上無(wú)縫運(yùn)行,并將實(shí)用性擴(kuò)展到從 Android 系統(tǒng)管理到多個(gè)設(shè)備的編排等各種應(yīng)用程序。
通常,檢索增強(qiáng)生成 (RAG) 方法需要對(duì)潛在函數(shù)參數(shù)進(jìn)行詳細(xì)描述(有時(shí)需要多達(dá)數(shù)萬(wàn)個(gè)輸入 token)。基于此,Octopus-V2-2B 在訓(xùn)練和推理階段引入了獨(dú)特的函數(shù) token 策略,不僅使其能夠達(dá)到與 GPT-4 相當(dāng)?shù)男阅芩剑疫€顯著提高了推理速度,超越了基于 RAG 的方法,這使得它對(duì)邊緣計(jì)算設(shè)備特別有利。
Octopus-V2-2B 能夠在各種復(fù)雜場(chǎng)景中生成單獨(dú)的、嵌套的和并行的函數(shù)調(diào)用。
數(shù)據(jù)集
為了訓(xùn)練、驗(yàn)證和測(cè)試階段采用高質(zhì)量數(shù)據(jù)集,特別是實(shí)現(xiàn)高效訓(xùn)練,研究團(tuán)隊(duì)用三個(gè)關(guān)鍵階段創(chuàng)建數(shù)據(jù)集:
- 生成相關(guān)的查詢及其關(guān)聯(lián)的函數(shù)調(diào)用參數(shù);
- 由適當(dāng)?shù)暮瘮?shù)組件生成不相關(guān)的查詢;
- 通過(guò) Google Gemini 實(shí)現(xiàn)二進(jìn)制驗(yàn)證支持。
研究團(tuán)隊(duì)編寫了 20 個(gè) Android API 描述,用于訓(xùn)練模型。下面是一個(gè) 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。
對(duì)于兩種訓(xùn)練方法,epoch 數(shù)均設(shè)置為 3。
使用以下代碼,就可以在單個(gè) GPU 上運(yùn)行 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")
評(píng)估
Octopus-V2-2B 在基準(zhǔn)測(cè)試中表現(xiàn)出卓越的推理速度,在單個(gè) A100 GPU 上比「Llama7B + RAG 解決方案」快 36 倍。此外,與依賴集群 A100/H100 GPU 的 GPT-4-turbo 相比,Octopus-V2-2B 速度提高了 168%。這種效率突破歸功于 Octopus-V2-2B 的函數(shù)性 token 設(shè)計(jì)。
Octopus-V2-2B 不僅在速度上表現(xiàn)出色,在準(zhǔn)確率上也表現(xiàn)出色,在函數(shù)調(diào)用準(zhǔn)確率上超越「Llama7B + RAG 方案」31%。Octopus-V2-2B 實(shí)現(xiàn)了與 GPT-4 和 RAG + GPT-3.5 相當(dāng)?shù)暮瘮?shù)調(diào)用準(zhǔn)確率。
感興趣的讀者可以閱讀論文原文,了解更多研究?jī)?nèi)容。