You need to enable JavaScript to run this app.
Lake AI Service

Lake AI Service

Copy page
Download PDF
Image understanding
Image content understanding (Qwen VL series models)
Copy page
Download PDF
Image content understanding (Qwen VL series models)

Operator introduction

Description

Qwen2.5-VL multimodal image understanding model – visual-semantic parsing and natural language description generation

Key features

  • Multimodal input processing
  • Supports three image formats: URL, Base64 encoding, and binary stream
  • Vision-language joint modeling
  • Accurately maps image content to semantic space
  • Conversational prompt support
  • Guides generation direction through the prompt parameter
  • Resource usage
  • It is recommended to use a GPU with 48 GB or more of GPU memory

Scenario optimization

  • Chinese-English mixed scenario optimization: specifically enhances Chinese semantics
  • Supports unifying image sizes first; it is recommended to set the image size according to the image and GPU specifications

Daft invocation

Operator parameters

Input

Input column name

Note

images

An array containing image data, element type is string or binary.

user_prompts

The prompt corresponding to image understanding; defaults to None. If not provided, the prompt parameter will be used by default.

Output

The processed array, where each element is the visual understanding result for each image.

Parameters

If a parameter does not have a default value, it is required

Parameter name

Type

Default value

Description

image_src_type

str

image_url

The format type of the input image. Supported: - tos/http address (image_url) - base64 encoding (image_base64) - binary stream (image_binary) Optional values: ["image_url", "image_base64", "image_binary"] Default value: "image_url"

model_path

str

/opt/las/models

The absolute path for storing local model files; defaults to the preset path inside the container. This path must be modified when using a custom model. Default value: "/opt/las/models"

model_name

str

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

Supported vision-language model versions. Currently, only Qwen2.5-VL series models are supported. Optional values: ["Qwen/Qwen2.5-VL-7B-Instruct"] Default value: "Qwen/Qwen2.5-VL-7B-Instruct"

prompt

str

Please provide a detailed description of this image.

The prompt for the user to understand the image content. The model will generate an image description based on the prompt. Default value: "Please provide a detailed description of this image."

batch_size

int

4

The number of samples processed per inference. A larger batch_size can improve throughput but increases GPU memory consumption. It is recommended to adjust according to GPU memory. Default value: 4

dtype

str

bfloat16

Model inference precision selection: - bfloat16: balances precision and speed - float16: faster inference speed - float32: highest precision but maximum memory consumption Optional values: ["bfloat16", "float16", "float32"] Default value: "bfloat16"

use_flash_attention_2

bool

True

Whether to use Flash Attention 2 to optimize attention computation (effective when CUDA-compatible and dtype is 16-bit floating point) Default value: True

max_caption_length

int

256

Maximum number of tokens for model-generated descriptions. Longer outputs may contain more details but increase computation time. Default value: 256

resized_height

int or None

None

Uniformly scale the image height (in pixels) during preprocessing; a null value retains the original size. Increasing the size can preserve details but significantly increases memory usage. Default value: None

resized_width

int or None

None

Uniformly scale the image width (in pixels) during preprocessing; a null value retains the original size. Recommended to use together with resized_height. Default value: None

do_sample

bool

False

Whether to enable sampling-based generation. When set to True, the model samples the next token probabilistically, resulting in more diverse outputs; when set to False, greedy or beam search is used, resulting in more deterministic outputs. Default value: False

temperature

float

1.0

Sampling temperature, controls the randomness of generated content. The higher the value, the more diverse the output; the lower the value, the more conservative the output. Default value: 1.0

top_k

int

50

During sampling, only the next token is selected from the top k tokens with the highest probability. Smaller k values improve output relevance, while larger k values increase diversity. Default value: 50

top_p

float

1.0

Cumulative probability threshold for nucleus sampling. Sampling is performed only from the set of tokens whose cumulative probability exceeds top_p, controlling output diversity. Smaller values result in more conservative outputs, while larger values increase diversity. Default value: 1.0

rank

int or None

None

Specifies the GPU device ID to use (effective in multi-GPU environments). For example: 0 indicates the first GPU, 1 indicates the second GPU. Default value: None

Examples

The following code demonstrates how to use daft to run the operator for image content understanding and generate descriptions as instructed.

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.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… ┆ Please provide a detailed description of the image. ┆ This image shows an anthropomorphic cat dressed in a vintage-style outfit, …           │
    # ╰────────────────────────────────┴────────────────────┴─────────────────────────────────────────────────────────────╯
Last updated: 2026.05.12 19:06:31