LLaVA multimodal image understanding model – visual semantic parsing and natural language description generation
URL, Base64 encoding, and binary streamprompt parameterInput column name | Note |
|---|---|
images | An array containing image data; element type is string or binary. |
user_prompts | The prompt for image understanding; defaults to None. If not provided, the prompt parameter will be used by default. |
The processed array, with each element representing the visual understanding result for each image.
If a parameter does not have a default value, it is required
Parameter name | Type | Default value | Description |
|---|---|---|---|
image_src_type | str | image_url | Input image format type. Supported options: - 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 | Absolute path for storing local model files; defaults to the preset path inside the container. When using a custom model, this path must be modified. Default value: "/opt/las/models" |
model_name | str | LLaVA-OneVision-1.5-8B-Instruct | Supported visual-language model versions. Currently, only the LLaVA One Vision series models are supported. Optional values: ["LLaVA-OneVision-1.5-8B-Instruct", "LLaVA-OneVision-1.5-4B-Instruct"] Default value: "LLaVA-OneVision-1.5-8B-Instruct" |
prompt | str | Please provide a detailed description of this image. | The prompt for users to understand 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 | Number of samples processed per inference. A larger batch_size can improve throughput but increases VRAM consumption; it is recommended to adjust according to GPU VRAM. 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 only 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 generations may include more details but increase computation time Default value: 256 |
resized_height | int or None | None | Uniformly scale image height during preprocessing (in pixels); None retains original size. Increasing the size preserves details but significantly increases memory usage Default value: None |
resized_width | int or None | None | Uniformly scale image width during preprocessing (in pixels); None retains original size. Recommended to use together with resized_height Default value: None |
do_sample | bool | False | Whether to enable sampling generation. When True, the model samples the next token probabilistically, resulting in more diverse outputs; when 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 generation; the lower the value, the more conservative the generation. 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 relevance of generated content, 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 is less than or equal to top_p, controlling the diversity of generated content. The smaller the value, the more conservative the generation; the larger the value, the more diverse the generation. Default value: 1.0 |
rank | int or None | None | Specifies the GPU device number to use (effective in multi-GPU environments). For example: 0 indicates the first GPU, 1 indicates the second GPU Default value: None |
The following code demonstrates how to use daft to run the operator for image content understanding and generate descriptions according to instructions.
from __future__ import annotations import os import daft from daft import col from daft.las.functions.multimodal.llava_one_vision_image_understanding import LlavaOneVisionImageUnderstanding 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", "LLaVA-OneVision-1.5-8B-Instruct") dtype = "bfloat16" use_flash_attention_2 = True 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( LlavaOneVisionImageUnderstanding, 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": 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 specify the type of the image. ┆ This image belongs to the animation category, specifically CGI (computer-generated imagery) animation… │ # ╰────────────────────────────────┴────────────────────┴──────────────────────────────────────────────────────────╯