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

AI 数据湖服务

复制全文
音频理解
音频内容理解(Qwen Omni 模型)
复制全文
音频内容理解(Qwen Omni 模型)

算子介绍

描述

Qwen2.5-Omni 多模态音频理解模型 - 音频内容解析与自然语言描述生成 核心功能

核心功能

  • 智能内容理解与描述生成
  • 基于音频信号自动生成详细准确的自然语言描述,支持通过 prompt 参数自定义提示词
  • 支持mp3、acc、m4a等音频格式
  • 高效模型加载与推理优化
  • 支持多种计算精度选择(bfloat16、float16、float32),适配不同性能需求
  • 集成FlashAttention2加速技术,显著提升推理效率
  • 支持自动或手动设备分配,完美适配单卡/多卡环境
  • 资源使用
  • 推荐使用48G及以上显存的GPU

场景优化

  • 广泛适用于音频内容分析、智能音频描述、多媒体内容理解等应用场景
  • 内置批处理机制,高效支持大规模音频数据并行推理
  • 灵活配置返回音频数据选项,满足多样化业务需求

Daft 调用

算子参数

输入

输入列名

说明

contents

包含音频数据的数组,元素类型为字符串(文件路径或URL)。

user_prompts

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

输出

处理后的数组,元素为每个音频的理解结果文本。对于处理失败的音频,返回空字符串。

参数

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

参数名称

类型

默认值

描述

model_path

str

/opt/las/models

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

model_name

str

Qwen/Qwen2.5-Omni-7B

支持的多模态模型版本,当前支持Qwen2.5-Omni系列模型 可选值:["Qwen/Qwen2.5-Omni-7B"] 默认值:"Qwen/Qwen2.5-Omni-7B"

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

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_omni_audio_understanding import QwenOmniAudioUnderstanding
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 = {
        "audio_path": [
            f"https://{tos_dir_url}/public/shared_audio_dataset/黑神话悟空对话.mp3"
        ],
        "prompt": ["请直接将这个音频转换成文字,不要做任何解释。"],

    }

    model_path = os.getenv("MODEL_PATH", "/opt/las/models")
    model_name = "Qwen/Qwen2.5-Omni-7B"
    dtype = "bfloat16"
    use_flash_attention_2 = True
    default_prompt = None
    max_caption_length = 256
    batch_size = 1
    rank = 0
    num_gpus = int(os.getenv("NUM_GPUS", 1))
    num_gpus = 1

    ds = daft.from_pydict(samples)
    ds = ds.with_column(
        "caption",
        las_udf(
            QwenOmniAudioUnderstanding,
            construct_args={
                "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,
                "batch_size": batch_size,
                "rank": rank,
            },
            num_gpus=num_gpus,
            batch_size=1,
            concurrency=1,
        )(col("audio_path"), col("prompt")),
    )
    print(ds.to_pandas()["caption"][0])

    ds.show()

    # ╭────────────────────────────────┬───────────────────────────────────────────────┬─────────────────────────────────────────────────────────────╮
    # │ audio_path                     ┆ prompt                                        ┆ caption                                                     │
    # │ ---                            ┆ ---                                           ┆ ---                                                         │
    # │ Utf8                           ┆ Utf8                                          ┆ Utf8                                                        │
    # ╞════════════════════════════════╪═══════════════════════════════════════════════╪═════════════════════════════════════════════════════════════╡
    # │ tos://las-cn-beijing-public-o… ┆ 请直接将这个音频转换成文字,不要做任何解释。…        ┆ 人我保住了,经我取到了。俺老孙啥功名不要,只求回到这花果山…           │
    # ╰────────────────────────────────┴───────────────────────────────────────────────┴─────────────────────────────────────────────────────────────╯
最近更新时间:2026.01.08 19:15:09
这个页面对您有帮助吗?
有用
有用
无用
无用