Qwen变体新成员加一,英伟达训练 NVLM-D-72B 视觉大模型

news2024/10/8 15:30:09

在这里插入图片描述
今天(2024 年 9 月 17 日),我们推出了前沿级多模态大语言模型(LLM)系列 NVLM 1.0,它在视觉语言任务上取得了最先进的结果,可与领先的专有模型(如 GPT-4o)和开放存取模型(如 Llama 3-V 405B 和 InternVL 2)相媲美。值得注意的是,NVLM 1.0 在多模态训练后的纯文本性能比其 LLM 骨干模型有所提高。

在此版本库中,我们将向社区开源 NVLM-1.0-D-72B(纯解码器架构)、纯解码器模型权重和代码。

我们使用传统的 Megatron-LM 训练我们的模型,并将代码库调整为 Huggingface,以实现模型托管、可重现性和推理。我们观察到 Megatron 代码库和 Huggingface 代码库之间存在数值差异,这些差异在预期的变化范围之内。我们提供 Huggingface 代码库和 Megatron 代码库的结果,以便与其他模型进行重现和比较。

视觉语言基准

BenchmarkMMMU (val / test)MathVistaOCRBenchAI2DChartQADocVQATextVQARealWorldQAVQAv2
NVLM-D 1.0 72B (Huggingface)58.7 / 54.965.285294.286.092.682.669.585.4
NVLM-D 1.0 72B (Megatron)59.7 / 54.665.285394.286.092.682.169.785.4
Llama 3.2 90B60.3 / -57.3-92.385.590.1--78.1
Llama 3-V 70B60.6 / ---93.083.292.283.4-79.1
Llama 3-V 405B64.5 / ---94.185.892.684.8-80.2
InternVL2-Llama3-76B55.2 / -65.583994.888.494.184.472.2-
GPT-4V56.8 / 55.749.964578.278.588.478.061.477.2
GPT-4o69.1 / -63.873694.285.792.8---
Claude 3.5 Sonnet68.3 / -67.778894.790.895.2---
Gemini 1.5 Pro (Aug 2024)62.2 / -63.975494.487.293.178.770.480.2

纯文字基准

TasksBackbone LLMMMLUGSM8KMATHHumanEvalAvg. Accuracy
Proprietary
GPT-4.0N/A88.7-76.690.2-
Gemini Pro 1.5 (Aug 2024)N/A85.990.867.784.182.1
Claude 3.5 SonnetN/A88.796.471.192.087.0
Open LLM
(a) Nous-Hermes-2-Yi-34BN/A75.578.621.843.354.8
(b) Qwen-72B-InstructN/A82.391.159.786.079.8
(c) Llama-3-70B-InstructN/A82.093.051.081.776.6
(d) Llama-3.1-70B-InstructN/A83.695.168.080.581.8
(e) Llama-3.1-405B-InstructN/A87.396.873.889.086.7
Open Multimodal LLM
VILA-1.5 40B(a)73.367.516.834.1🥶 47.9 (-6.9)
LLaVA-OneVision 72B(b)80.689.949.274.4🥶 73.5 (-6.3)
InternVL-2-Llama3-76B(c)78.587.142.571.3🥶 69.9 (-6.7)
*Llama 3-V 70B(d)83.695.168.080.5🙂 81.8 (0)
*Llama 3-V 405B(e)87.396.873.889.0🙂 86.7 (0)
NVLM-D 1.0 72B (Megatron)(b)82.092.973.188.4🥳 84.1 (+4.3)
NVLM-D 1.0 72B (Huggingface)(b)81.793.273.189.0🥳 84.3 (+4.5)

在将 Megatron checkpoint 转换为 Huggingface 时,我们调整了 InternVL 代码库,以支持 HF 中的模型加载和多 GPU 推理。在将 Qwen2.5-72B-Instruct 中的标记符转换为 Huggingface 时,我们还使用了 Qwen2.5-72B-Instruct 中的标记符,因为它包含用于视觉任务的额外特殊标记符,例如 <|vision_pad|>。我们在 Qwen2-72B-Instruct 纯文本模型和 InternViT-6B-448px-V1-5 ViT 模型的基础上,利用大规模高质量多模态数据集训练 NVLM-1.0-D-72B。有关训练代码,请参阅 Megatron-LM(即将发布)。

准备环境

我们在 Dockerfile 中提供了一个用于复制的 docker 生成文件。

该 docker 映像基于 nvcr.io/nvidia/pytorch:23.09-py3。

注:我们注意到,不同的转换器版本/CUDA 版本/docker 版本会导致基准数略有不同。我们建议使用上述 Dockerfile 进行精确还原。

模型加载

import torch
from transformers import AutoModel

path = "nvidia/NVLM-D-72B"
model = AutoModel.from_pretrained(
    path,
    torch_dtype=torch.bfloat16,
    low_cpu_mem_usage=True,
    use_flash_attn=False,
    trust_remote_code=True).eval()

多显卡

import torch
import math
from transformers import AutoModel

def split_model():
    device_map = {}
    world_size = torch.cuda.device_count()
    num_layers = 80
    # Since the first GPU will be used for ViT, treat it as half a GPU.
    num_layers_per_gpu = math.ceil(num_layers / (world_size - 0.5))
    num_layers_per_gpu = [num_layers_per_gpu] * world_size
    num_layers_per_gpu[0] = math.ceil(num_layers_per_gpu[0] * 0.5)
    layer_cnt = 0
    for i, num_layer in enumerate(num_layers_per_gpu):
        for j in range(num_layer):
            device_map[f'language_model.model.layers.{layer_cnt}'] = i
            layer_cnt += 1
    device_map['vision_model'] = 0
    device_map['mlp1'] = 0
    device_map['language_model.model.tok_embeddings'] = 0
    device_map['language_model.model.embed_tokens'] = 0
    device_map['language_model.output'] = 0
    device_map['language_model.model.norm'] = 0
    device_map['language_model.lm_head'] = 0
    device_map[f'language_model.model.layers.{num_layers - 1}'] = 0

    return device_map

path = "nvidia/NVLM-D-72B"
device_map = split_model()
model = AutoModel.from_pretrained(
    path,
    torch_dtype=torch.bfloat16,
    low_cpu_mem_usage=True,
    use_flash_attn=False,
    trust_remote_code=True,
    device_map=device_map).eval()

推理

import torch
from transformers import AutoTokenizer, AutoModel
import math
from PIL import Image
import torchvision.transforms as T
from torchvision.transforms.functional import InterpolationMode


def split_model():
    device_map = {}
    world_size = torch.cuda.device_count()
    num_layers = 80
    # Since the first GPU will be used for ViT, treat it as half a GPU.
    num_layers_per_gpu = math.ceil(num_layers / (world_size - 0.5))
    num_layers_per_gpu = [num_layers_per_gpu] * world_size
    num_layers_per_gpu[0] = math.ceil(num_layers_per_gpu[0] * 0.5)
    layer_cnt = 0
    for i, num_layer in enumerate(num_layers_per_gpu):
        for j in range(num_layer):
            device_map[f'language_model.model.layers.{layer_cnt}'] = i
            layer_cnt += 1
    device_map['vision_model'] = 0
    device_map['mlp1'] = 0
    device_map['language_model.model.tok_embeddings'] = 0
    device_map['language_model.model.embed_tokens'] = 0
    device_map['language_model.output'] = 0
    device_map['language_model.model.norm'] = 0
    device_map['language_model.lm_head'] = 0
    device_map[f'language_model.model.layers.{num_layers - 1}'] = 0

    return device_map


IMAGENET_MEAN = (0.485, 0.456, 0.406)
IMAGENET_STD = (0.229, 0.224, 0.225)


def build_transform(input_size):
    MEAN, STD = IMAGENET_MEAN, IMAGENET_STD
    transform = T.Compose([
        T.Lambda(lambda img: img.convert('RGB') if img.mode != 'RGB' else img),
        T.Resize((input_size, input_size), interpolation=InterpolationMode.BICUBIC),
        T.ToTensor(),
        T.Normalize(mean=MEAN, std=STD)
    ])
    return transform


def find_closest_aspect_ratio(aspect_ratio, target_ratios, width, height, image_size):
    best_ratio_diff = float('inf')
    best_ratio = (1, 1)
    area = width * height
    for ratio in target_ratios:
        target_aspect_ratio = ratio[0] / ratio[1]
        ratio_diff = abs(aspect_ratio - target_aspect_ratio)
        if ratio_diff < best_ratio_diff:
            best_ratio_diff = ratio_diff
            best_ratio = ratio
        elif ratio_diff == best_ratio_diff:
            if area > 0.5 * image_size * image_size * ratio[0] * ratio[1]:
                best_ratio = ratio
    return best_ratio


def dynamic_preprocess(image, min_num=1, max_num=12, image_size=448, use_thumbnail=False):
    orig_width, orig_height = image.size
    aspect_ratio = orig_width / orig_height

    # calculate the existing image aspect ratio
    target_ratios = set(
        (i, j) for n in range(min_num, max_num + 1) for i in range(1, n + 1) for j in range(1, n + 1) if
        i * j <= max_num and i * j >= min_num)
    target_ratios = sorted(target_ratios, key=lambda x: x[0] * x[1])

    # find the closest aspect ratio to the target
    target_aspect_ratio = find_closest_aspect_ratio(
        aspect_ratio, target_ratios, orig_width, orig_height, image_size)

    # calculate the target width and height
    target_width = image_size * target_aspect_ratio[0]
    target_height = image_size * target_aspect_ratio[1]
    blocks = target_aspect_ratio[0] * target_aspect_ratio[1]

    # resize the image
    resized_img = image.resize((target_width, target_height))
    processed_images = []
    for i in range(blocks):
        box = (
            (i % (target_width // image_size)) * image_size,
            (i // (target_width // image_size)) * image_size,
            ((i % (target_width // image_size)) + 1) * image_size,
            ((i // (target_width // image_size)) + 1) * image_size
        )
        # split the image
        split_img = resized_img.crop(box)
        processed_images.append(split_img)
    assert len(processed_images) == blocks
    if use_thumbnail and len(processed_images) != 1:
        thumbnail_img = image.resize((image_size, image_size))
        processed_images.append(thumbnail_img)
    return processed_images


def load_image(image_file, input_size=448, max_num=12):
    image = Image.open(image_file).convert('RGB')
    transform = build_transform(input_size=input_size)
    images = dynamic_preprocess(image, image_size=input_size, use_thumbnail=True, max_num=max_num)
    pixel_values = [transform(image) for image in images]
    pixel_values = torch.stack(pixel_values)
    return pixel_values

path = "nvidia/NVLM-D-72B"
device_map = split_model()
model = AutoModel.from_pretrained(
    path,
    torch_dtype=torch.bfloat16,
    low_cpu_mem_usage=True,
    use_flash_attn=False,
    trust_remote_code=True,
    device_map=device_map).eval()

print(model)

tokenizer = AutoTokenizer.from_pretrained(path, trust_remote_code=True, use_fast=False)
generation_config = dict(max_new_tokens=1024, do_sample=False)

# pure-text conversation
question = 'Hello, who are you?'
response, history = model.chat(tokenizer, None, question, generation_config, history=None, return_history=True)
print(f'User: {question}\nAssistant: {response}')

# single-image single-round conversation
pixel_values = load_image('path/to/your/example/image.jpg', max_num=6).to(
    torch.bfloat16)
question = '<image>\nPlease describe the image shortly.'
response = model.chat(tokenizer, pixel_values, question, generation_config)
print(f'User: {question}\nAssistant: {response}')

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2196659.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

2024高校网络安全管理运维赛 wp

0x00 前言 本文是关于“2024高校网络安全管理运维赛”的详细题解&#xff0c;主要针对Web、Pwn、Re、Misc以及Algorithm等多方向题目的解题过程&#xff0c;包含但不限于钓鱼邮件识别、流量分析、SQLite文件解析、ssrf、xxe等等。如有错误&#xff0c;欢迎指正。 0x01 Misc 签到…

纯干货!一个白帽子挖漏洞经验细致分享_白帽子找漏洞一天能多少

不知道是不是很多人和我一样&#xff0c;每天刷着漏洞&#xff0c;看着自己的排名一位一位的往上提升&#xff0c;但是&#xff0c;但是。总感觉怪怪的&#xff0c;为什么别人刷的漏洞都是现金&#xff0c;而自己刷的漏洞都是给库币。别人一天为什么提交那么多漏洞&#xff0c;…

winform appconfig

文章目录 添加一个appconfig配置文件的结构读取写入 这是wiform自带的配置文件&#xff0c;格式为xml 其位置在程序根目录下 添加一个appconfig 首先默认情况下&#xff0c;winform会自动创建一个名叫appconfig的配置文件&#xff0c;位于程序根目录下 如果需要手动创建更多…

【路径规划】基于球面向量的粒子群优化算法(SPSO)

摘要 本文提出了一种基于球面向量的粒子群优化算法&#xff08;Spherical Vector-based Particle Swarm Optimization, SPSO&#xff09;用于解决路径规划问题。该算法通过球面坐标系表示粒子的位置更新&#xff0c;增强了搜索空间的探索能力和全局优化性能。通过与遗传算法&a…

浅析基于双碳目标的光储充一体化电站状态评估技术

摘要&#xff1a;全国碳市场拉开了我国能源结构加速转型的大幕&#xff0c;催生了光伏、储能和新能源汽车等一批绿色产业的兴起&#xff0c;同时随着利好政策扶植和消费者的青睐&#xff0c;光伏、储能和新能源汽车市场均加快发展。但传统的充电桩和光伏电站都是分开建设&#…

基于SSM的家庭理财系统的设计与实现

文未可获取一份本项目的java源码和数据库参考。 选题目的: 随着社会的进步&#xff0c;我国经济的快速发展&#xff0c;人们的生活水平提高了&#xff0c;现在人们已经不仅仅满足于能够吃得饱穿得好&#xff0c;现在的人们在想着如何丰富自己的精神世界&#xff0c;想着如何去…

Win11环境下 DELPHI 12.2 安装全过程

背景描述 DELPHI作为曾经的Windows原生开发的王者&#xff0c;DELPHI12.2可以实现Windows、Android、IOS、macOS、Linux的应用开发&#xff0c;现在还有少数企业使用&#xff0c;大多数用户是从传统D3/4/5/6/7坚持下来的爱好者&#xff0c;2ccc.com里有相关内容&#xff0c;但…

基于方块编码的图像压缩matlab仿真,带GUI界面

目录 1.算法运行效果图预览 2.算法运行软件版本 3.部分核心程序 4.算法理论概述 4.1 编码单元的表示 4.2编码单元的编码 5.算法完整程序工程 1.算法运行效果图预览 (完整程序运行后无水印) 下图是随着方块大小的变化&#xff0c;图像的压缩率以及对应的图像质量指标PSN…

QT使用websocket实现语音对讲

简介&#xff1a; 本文所描述的功能和代码&#xff0c;是基于QT的开发环境。在QT上使用websocket&#xff0c;接受和发送pcm音频&#xff0c;实现了语音对讲功能。经自测&#xff0c;该功能可以正常使用&#xff0c;以下是相关代码的分享。 void MainWindow::on_pushButton_Ope…

Linux学习笔记(七):磁盘的挂载与扩展

Linux学习笔记&#xff08;七&#xff09;&#xff1a;磁盘的挂载与扩展 在虚拟机环境中&#xff0c;当我们的存储空间不足时&#xff0c;添加一块新的硬盘显得尤为重要。 1. 新增磁盘 首先&#xff0c;你需要确保有一块物理磁盘或虚拟磁盘。在虚拟机管理器中&#xff0c;你可以…

1.4TB! 全台湾2024年三维建筑模型3DTiles数据

在今年1月13日&#xff0c;我写了一篇文章&#xff0c;详细介绍了了全台湾2023年三维建筑模型数据以及数据背景。隔了8个月之后&#xff0c;我对全岛建筑模型数据进行了更新,不仅在数量上有增长&#xff0c;而且数据显示性能也进行了优化&#xff0c;下面我针对对2024年数据进行…

探索Python文本处理的新境界:textwrap库揭秘

文章目录 **探索Python文本处理的新境界&#xff1a;textwrap库揭秘**一、背景介绍二、textwrap库是什么&#xff1f;三、如何安装textwrap库&#xff1f;四、简单函数使用方法4.1 wrap()4.2 fill()4.3 shorten()4.4 dedent()4.5 indent() 五、实际应用场景5.1 格式化日志输出5…

黑龙江等保测评详细指南

一、什么是等保测评&#xff1f; 等保&#xff08;信息安全等级保护&#xff09;是指根据信息系统的重要性和安全需求&#xff0c;对其进行分级保护的制度。黑龙江省的等保测评旨在评估信息系统的安全性&#xff0c;确保其符合国家和地方的安全标准。 二、等保测评的必要性 1…

OpenAI重磅发布Canvas:跟ChatGPT一起写作编程

现在是大半夜1点56&#xff0c;国庆第三天&#xff0c;我想睡觉&#xff0c;真的。 但是&#xff0c;ChatGPT更新了&#xff0c;虽然不是那种王炸级的新模型模型更新&#xff0c;但是更新了一个极度优雅&#xff0c;对普通人极度友好的功能。 而且&#xff0c;顺带&#xff0…

ASB:LLM智能体应用攻防测试数据集

ABS&#xff1a;LLM智能体应用攻防测试数据集 Agent应用 Agent Security Bench (ASB): Formalizing and Benchmarking Attacks and Defenses in LLM-based Agents 尽管基于 LLM 的代理能够通过外部工具和记忆机制解决复杂任务&#xff0c;但也可能带来严重安全风险。现有文献对…

地图可视化的艺术:深入比较Mapbox、OpenLayers、Leaflet和Cesium,不同场景下应如何选择地图库

目录 地图可视化的艺术&#xff1a;深入比较Mapbox、OpenLayers、Leaflet和Cesium 一、总览 二、定制地图美学的先行者——Mapbox 1、主要功能特点 2、开源情况 3、市场与应用人群 4、安装与基础使用代码 三、开源GIS地图库的全能王——OpenLayers 1、主要功能特点 2…

重要的事情说两遍!Prompt「复读机」,显著提高LLM推理能力

【导读】 尽管大模型能力非凡&#xff0c;但干细活的时候还是比不上人类。为了提高LLM的理解和推理能力&#xff0c;Prompt「复读机」诞生了。 众所周知&#xff0c;人类的本质是复读机。 我们遵循复读机的自我修养&#xff1a;敲黑板&#xff0c;划重点&#xff0c;重要的事…

原生input实现时间选择器用法

2024.10.08今天我学习了如何用原生的input&#xff0c;实现时间选择器用法&#xff0c;效果如下&#xff1a; 代码如下&#xff1a; <div><input id"yf_start" type"text"> </div><script>$(#yf_start).datepicker({language: zh…

ELK中L的filebeat配置及使用(超详细)

上一次讲解了如何在linux服务器上使用docker配置ELK中的E和K&#xff0c;这期着重讲解一下L怎么配置。 首先L在elk中指的是一个数据处理管道&#xff0c;可以从多种来源收集数据&#xff0c;进行处理和转换&#xff0c;然后将数据发送到 Elasticsearch。L的全称就是&#xff1…

国外电商系统开发-运维系统文件下载

文件下载&#xff0c;作者设计的比较先进&#xff0c;如果下载顺利&#xff0c;真的还需要点两次鼠标&#xff0c;所有的远程文件就自动的下载到了您的PC电脑上了。 现在&#xff0c;请您首选选择要在哪些服务器上下载文件&#xff1a; 选择好了服务器以后&#xff0c;现在选择…