# 热门搜索 #
搜索
超越GPT-4,斯坦福团队手机可跑的大模型火了,一夜下载量超2k
6793点击    2024-04-07 17:44

在大模型落地应用的过程中,端侧 AI 是非常重要的一个方向。


近日,斯坦福大学研究人员推出的 Octopus v2 火了,受到了开发者社区的极大关注,模型一夜下载量超 2k。


20 亿参数的 Octopus v2 可以在智能手机、汽车、个人电脑等端侧运行,在准确性和延迟方面超越了 GPT-4,并将上下文长度减少了 95%。此外,Octopus v2 比 Llama7B + RAG 方案快 36 倍。


00:58

不少网友感叹:设备端 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 亿参数的开源语言模型,专为 Android API 量身定制,旨在在 Android 设备上无缝运行,并将实用性扩展到从 Android 系统管理到多个设备的编排等各种应用程序。



通常,检索增强生成 (RAG) 方法需要对潜在函数参数进行详细描述(有时需要多达数万个输入 token)。基于此,Octopus-V2-2B 在训练和推理阶段引入了独特的函数 token 策略,不仅使其能够达到与 GPT-4 相当的性能水平,而且还显著提高了推理速度,超越了基于 RAG 的方法,这使得它对边缘计算设备特别有利。



Octopus-V2-2B 能够在各种复杂场景中生成单独的、嵌套的和并行的函数调用。


数据集


为了训练、验证和测试阶段采用高质量数据集,特别是实现高效训练,研究团队用三个关键阶段创建数据集:


  • 生成相关的查询及其关联的函数调用参数;
  • 由适当的函数组件生成不相关的查询; 
  • 通过 Google Gemini 实现二进制验证支持。



研究团队编写了 20 个 Android API 描述,用于训练模型。下面是一个 Android API 描述示例:



def get_trending_news (category=None, region='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.

"""


模型开发与训练


该研究采用 Google Gemma-2B 模型作为框架中的预训练模型,并采用两种不同的训练方法:完整模型训练和 LoRA 模型训练。


在完整模型训练中,该研究使用 AdamW 优化器,学习率设置为 5e-5,warm-up 的 step 数设置为 10,采用线性学习率调度器。


LoRA 模型训练采用与完整模型训练相同的优化器和学习率配置,LoRA rank 设置为 16,并将 LoRA 应用于以下模块:q_proj、k_proj、v_proj、o_proj、up_proj、down_proj。其中,LoRA alpha 参数设置为 32。


对于两种训练方法,epoch 数均设置为 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 在基准测试中表现出卓越的推理速度,在单个 A100 GPU 上比「Llama7B + RAG 解决方案」快 36 倍。此外,与依赖集群 A100/H100 GPU 的 GPT-4-turbo 相比,Octopus-V2-2B 速度提高了 168%。这种效率突破归功于 Octopus-V2-2B 的函数性 token 设计。



Octopus-V2-2B 不仅在速度上表现出色,在准确率上也表现出色,在函数调用准确率上超越「Llama7B + RAG 方案」31%。Octopus-V2-2B 实现了与 GPT-4 和 RAG + GPT-3.5 相当的函数调用准确率。



感兴趣的读者可以阅读论文原文,了解更多研究内容


文章来自微信公众号“机器之心”,作者:机器之心




关键词: GPT-4 , Octopus v2 , Llama7B , RAG
AITNT资源拓展
根据文章内容,系统为您匹配了更有价值的资源信息。内容由AI生成,仅供参考
1
智能体

【开源免费】AutoGPT是一个允许用户创建和运行智能体的(AI Agents)项目。用户创建的智能体能够自动执行各种任务,从而让AI有步骤的去解决实际问题。

项目地址:https://github.com/Significant-Gravitas/AutoGPT


【开源免费】MetaGPT是一个“软件开发公司”的智能体项目,只需要输入一句话的老板需求,MetaGPT即可输出用户故事 / 竞品分析 / 需求 / 数据结构 / APIs / 文件等软件开发的相关内容。MetaGPT内置了各种AI角色,包括产品经理 / 架构师 / 项目经理 / 工程师,MetaGPT提供了一个精心调配的软件公司研发全过程的SOP。

项目地址:https://github.com/geekan/MetaGPT/blob/main/docs/README_CN.md

2
RAG

【开源免费】graphrag是微软推出的RAG项目,与传统的通过 RAG 方法使用向量相似性作为搜索技术不同,GraphRAG是使用知识图谱在推理复杂信息时大幅提高问答性能。

项目地址:https://github.com/microsoft/graphrag

【开源免费】Dify是最早一批实现RAG,Agent,模型管理等一站式AI开发的工具平台,并且项目方一直持续维护。其中在任务编排方面相对领先对手,可以帮助研发实现像字节扣子那样的功能。

项目地址:https://github.com/langgenius/dify


【开源免费】RAGFlow是和Dify类似的开源项目,该项目在大文件解析方面做的更出色,拓展编排方面相对弱一些。

项目地址:https://github.com/infiniflow/ragflow/tree/main


【开源免费】phidata是一个可以实现将数据转化成向量存储,并通过AI实现RAG功能的项目

项目地址:https://github.com/phidatahq/phidata


【开源免费】TaskingAI 是一个提供RAG,Agent,大模型管理等AI项目开发的工具平台,比LangChain更强大的中间件AI平台工具。

项目地址:https://github.com/TaskingAI/TaskingAI