全球首款开源!多模态 MoE 模型 Aria:64K 超长上下文,图像视频文档全能处理,支持全参数微调!

❤️ 如果你也关注大模型与 AI 的发展现状,且对大模型应用开发非常感兴趣,我会快速跟你分享最新的感兴趣的 AI 应用和热点信息,也会不定期分享自己的想法和开源实例,欢迎关注我哦!

微信订阅号|搜一搜:蚝油菜花

🚀 快速阅读

  1. Aria 是由 Rhymes AI 推出的全球首个开源多模态原生混合专家(MoE)模型,具备卓越的多模态理解能力。
  2. 拥有 64K tokens 的长上下文窗口,高效处理长视频和文档,同时在多模态任务上展现最佳性能。
  3. 提供 LoRA 和全参数微调,支持多种数据集类型,助力开发者快速上手和应用。

正文(附运行示例)

Aria 是什么

Aria 是由 Rhymes AI 团队开发的全球首个开源多模态原生混合专家(MoE)模型。它能理解和处理文本、代码、图像和视频等多种输入类型,在多模态和语言任务上表现出色,尤其擅长视频和文档理解。Aria 拥有长达 64K tokens 的多模态上下文窗口,每个 token 激活 3.9B 参数,实现快速推理和低微调成本,为开发者和研究者提供了强大的多模态 AI 工具。

Aria 的主要功能

  • 多模态理解:能同时处理和理解文本、代码、图像和视频等多种数据类型。
  • 高性能任务处理:在多模态任务、语言理解和编码任务中表现优异。
  • 长上下文处理能力:拥有 64K tokens 的长上下文窗口,有效处理长视频和长文档。
  • 开源可扩展性:模型权重和代码库开源,方便广泛采用和进一步开发。

如何运行 Aria

安装

首先,确保你已经安装了必要的依赖项:

bash 复制代码
pip install -e .
# 如果你想为项目贡献代码,可以安装开发依赖
pip install -e .[dev]

pip install flash-attn --no-build-isolation

推理

Aria 总共拥有 25.3B 参数,可以在一个 A100 (80GB) GPU 上以 bfloat16 精度加载。以下是一个使用 Hugging Face Transformers 进行推理的示例代码:

python 复制代码
import requests
import torch
from PIL import Image
from transformers import AutoModelForCausalLM, AutoProcessor

model_id_or_path = "rhymes-ai/Aria"

model = AutoModelForCausalLM.from_pretrained(model_id_or_path, device_map="auto", torch_dtype=torch.bfloat16, trust_remote_code=True)
processor = AutoProcessor.from_pretrained(model_id_or_path, trust_remote_code=True)

image_path = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/cat.png"
image = Image.open(requests.get(image_path, stream=True).raw)

messages = [
    {
        "role": "user",
        "content": [
            {"text": None, "type": "image"},
            {"text": "这是什么图片?", "type": "text"},
        ],
    }
]

text = processor.apply_chat_template(messages, add_generation_prompt=True)
inputs = processor(text=text, images=image, return_tensors="pt")
inputs["pixel_values"] = inputs["pixel_values"].to(model.dtype)
inputs = {k: v.to(model.device) for k, v in inputs.items()}

with torch.inference_mode(), torch.cuda.amp.autocast(dtype=torch.bfloat16):
    output = model.generate(
        **inputs,
        max_new_tokens=500,
        stop_strings=["<|im_end|>"],
        tokenizer=processor.tokenizer,
        do_sample=True,
        temperature=0.9,
    )
    output_ids = output[0][inputs["input_ids"].shape[1]:]
    result = processor.decode(output_ids, skip_special_tokens=True)

print(result)

微调

Aria 支持 LoRA 微调和全参数微调,以下是一个使用 LoRA 微调的示例步骤:

  1. 准备数据集 :参考custom_dataset.md准备你的数据集。

  2. 配置文件 :打开recipes/config_lora.yaml,更新dataset_mixer部分为你的数据集路径:

    yaml 复制代码
    dataset_mixer:
      "path/to/dataset1": 1
      "path/to/dataset2": 0.5
      "path/to/dataset3": 2
  3. 开始微调 :在 A100 (80GB)或 H100 (80GB) GPU 上运行以下命令:

    bash 复制代码
    python aria/train.py --config recipes/config_lora.yaml
  4. 多 GPU 训练 :使用accelerate库进行多 GPU 训练:

    bash 复制代码
    accelerate launch --config_file recipes/accelerate_configs/zero2.yaml aria/train.py --config recipes/config_lora.yaml --num_processes [number_of_gpus]

资源


❤️ 如果你也关注大模型与 AI 的发展现状,且对大模型应用开发非常感兴趣,我会快速跟你分享最新的感兴趣的 AI 应用和热点信息,也会不定期分享自己的想法和开源实例,欢迎关注我哦!

微信订阅号|搜一搜:蚝油菜花

相关推荐
倔强青铜三13 分钟前
苦练Python第25天:玩转字典
人工智能·python·面试
倔强青铜三26 分钟前
苦练Python第23天:元组秘籍与妙用
人工智能·python·面试
hayson29 分钟前
langchaingo用法详解及源码解析(一)
langchain·llm
AndrewHZ1 小时前
【图像处理基石】如何入门色彩评估?
图像处理·人工智能·深度学习·色彩科学·hvs·色彩评估·颜色工程
TomatoSCI1 小时前
聚类的可视化选择:PCA / t-SNE丨TomatoSCI分析日记
人工智能·机器学习
大咖分享课1 小时前
深度剖析:最新发布的ChatGPT Agent 技术架构与应用场景
人工智能·openai·智能助手·ai代理·chatgpt agent·自主任务执行
lucky_lyovo1 小时前
卷积神经网络--网络性能提升
人工智能·神经网络·cnn
liliangcsdn1 小时前
smolagents - 如何在mac用agents做简单算术题
人工智能·macos·prompt
nju_spy1 小时前
周志华《机器学习导论》第8章 集成学习 Ensemble Learning
人工智能·随机森林·机器学习·集成学习·boosting·bagging·南京大学
静心问道2 小时前
TrOCR: 基于Transformer的光学字符识别方法,使用预训练模型
人工智能·深度学习·transformer·多模态