You need to enable JavaScript to run this app.
AI 数据湖服务

AI 数据湖服务

复制全文
图片理解
图片内容理解(Qwen VL 系列模型)
复制全文
图片内容理解(Qwen VL 系列模型)

算子介绍

描述

Qwen2.5-VL 多模态图像理解模型 - 视觉语义解析与自然语言描述生成

核心功能

  • 多模态输入处理
  • 支持 URL/Base64编码/二进制流 三种图像格式
  • 视觉-语言联合建模
  • 实现图像内容到语义空间的精准映射
  • 对话式提示支持
  • 通过 prompt 参数引导生成方向
  • 资源使用
  • 推荐使用48G及以上显存的GPU

场景优化

  • 中英文混合场景优化:特别针对中文语义增强
  • 支持先将图像尺寸修正为一致,建议按照图像和GPU情况设置图像尺寸

Daft 调用

算子参数

输入

输入列名

说明

images

包含图像数据的数组,元素类型为 字符串 或者 二进制。

user_prompts

图片理解对应的prompt,默认为None。如果不传入,则默认使用参数中的prompt。

输出

处理后的数组,元素为每个图片的视觉理解结果。

参数

如参数没有默认值,则为必填参数

参数名称

类型

默认值

描述

image_src_type

str

image_url

输入图像的格式类型,支持: - tos/http 地址(image_url) - base64 编码(image_base64) - 二进制流(image_binary) 可选值:["image_url", "image_base64", "image_binary"] 默认值:"image_url"

model_path

str

/opt/las/models

本地模型文件存储的绝对路径,默认为容器内预置路径。当使用自定义模型时需修改此路径 默认值:"/opt/las/models"

model_name

str

Qwen/Qwen2.5-VL-7B-Instruct

支持的视觉语言模型版本,当前仅支持 Qwen2.5-VL系列模型 可选值:["Qwen/Qwen2.5-VL-7B-Instruct"] 默认值:"Qwen/Qwen2.5-VL-7B-Instruct"

prompt

str

请给出这张图片的详细描述。

用户理解图片内容的提示词,模型会根据提示词来生成图像的描述。 默认值:"请给出这张图片的详细描述。"

batch_size

int

4

单次推理处理的样本数量。较大的batch_size可提升吞吐但增加显存消耗,建议根据GPU显存调整。 默认值:4

dtype

str

bfloat16

模型推理精度选择: - bfloat16: 平衡精度与速度 - float16: 更快的推理速度 - float32: 最高精度但显存消耗最大 可选值:["bfloat16", "float16", "float32"] 默认值:"bfloat16"

use_flash_attention_2

bool

True

是否使用Flash Attention 2优化注意力计算(需CUDA兼容且dtype为16位浮点时生效) 默认值:True

max_caption_length

int

256

模型生成描述的最大token数。较长的生成可能包含更多细节但增加计算时间 默认值:256

resized_height

int or None

None

预处理时统一缩放图像的高度(像素单位),空值保留原始尺寸。增大尺寸可保留细节但显著增加显存占用 默认值:None

resized_width

int or None

None

预处理时统一缩放图像的宽度(像素单位),空值保留原始尺寸。建议与resized_height配合使用 默认值:None

do_sample

bool

False

是否启用采样生成。为True时,模型会以概率方式采样下一个token,生成结果更具多样性;为False时,采用贪心或束搜索,生成结果更确定。 默认值:False

temperature

float

1.0

采样温度,控制生成内容的随机性。值越高,生成越多样化;值越低,生成越保守。 默认值:1.0

top_k

int

50

采样时仅从概率最高的前k个token中选取下一个token。较小的k值可提升生成的相关性,较大的k值增加多样性。 默认值:50

top_p

float

1.0

nucleus采样的累计概率阈值。仅从累计概率大于top_p的token集合中采样,控制生成内容的多样性。值越小生成越保守,值越大生成越多样。 默认值:1.0

rank

int or None

None

指定使用的GPU设备编号(多卡环境有效)。例如:0表示第一张GPU,1表示第二张GPU 默认值:None

调用示例

下面的代码展示了如何使用 daft 运行算子理解图像内容,并按照指令生成描述。

from __future__ import annotations

import os

import daft
from daft import col
from daft.las.functions.multimodal.qwen_vl_image_understanding import QwenVLImageUnderstanding
from daft.las.functions.udf import las_udf

if __name__ == "__main__":
    if os.getenv("DAFT_RUNNER", "native") == "ray":
        import logging

        import ray

        def configure_logging():
            logging.basicConfig(
                level=logging.INFO,
                format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
                datefmt="%Y-%m-%d %H:%M:%S.%s".format(),
            )
            logging.getLogger("tracing.span").setLevel(logging.WARNING)
            logging.getLogger("daft_io.stats").setLevel(logging.WARNING)
            logging.getLogger("DaftStatisticsManager").setLevel(logging.WARNING)
            logging.getLogger("DaftFlotillaScheduler").setLevel(logging.WARNING)
            logging.getLogger("DaftFlotillaDispatcher").setLevel(logging.WARNING)

        ray.init(dashboard_host="0.0.0.0", runtime_env={"worker_process_setup_hook": configure_logging})
        daft.context.set_runner_ray()
    daft.set_execution_config(actor_udf_ready_timeout=600)
    daft.set_execution_config(min_cpu_per_task=0)

    tos_dir_url = os.getenv("TOS_DIR_URL", "las-cn-beijing-public-online.tos-cn-beijing.volces.com")
    samples = {
        "image_path": [
            f"https://{tos_dir_url}/public/shared_image_dataset/cat_ip_adapter.jpeg"
        ],
        "prompt": ["请给出图片的详细描述。"],
    }
    
    image_src_type = "image_url"
    model_path = os.getenv("MODEL_PATH", "/opt/las/models")
    model_name = os.getenv("MODEL_NAME", "Qwen/Qwen2.5-VL-7B-Instruct")
    dtype = "bfloat16"
    use_flash_attention_2 = True
    default_prompt = None
    max_caption_length = 256
    resized_height = None
    resized_width = None
    batch_size = 2
    rank = 0

    ds = daft.from_pydict(samples)
    ds = ds.with_column(
        "caption",
        las_udf(
            QwenVLImageUnderstanding,
            construct_args={
                "image_src_type": image_src_type,
                "model_path": model_path,
                "model_name": model_name,
                "dtype": dtype,
                "use_flash_attention_2": use_flash_attention_2,
                "prompt": default_prompt,
                "max_caption_length": max_caption_length,
                "resized_height": resized_height,
                "resized_width": resized_width,
                "batch_size": batch_size,
                "rank": rank,
            },
            num_gpus=1,
            batch_size=2,
            concurrency=1,
        )(col("image_path"), col("prompt")),
    )

    ds.show()

    # ╭────────────────────────────────┬────────────────────┬─────────────────────────────────────────────────────────────╮
    # │ image_path                     ┆ prompt             ┆ caption                                                     │
    # │ ---                            ┆ ---                ┆ ---                                                         │
    # │ Utf8                           ┆ Utf8               ┆ Utf8                                                        │
    # ╞════════════════════════════════╪════════════════════╪═════════════════════════════════════════════════════════════╡
    # │ tos://las-cn-beijing-public-o… ┆ 请给出图片的详细描述。 ┆ 这张图片展示了一只拟人化的猫,它穿着一套复古风格的服装, …           │
    # ╰────────────────────────────────┴────────────────────┴─────────────────────────────────────────────────────────────╯
最近更新时间:2026.01.08 19:15:09
这个页面对您有帮助吗?
有用
有用
无用
无用