NVIDIA / DALI

A GPU-accelerated library containing highly optimized building blocks and an execution engine for data processing to accelerate deep learning training and inference applications.
https://docs.nvidia.com/deeplearning/dali/user-guide/docs/index.html
Apache License 2.0
5.09k stars 615 forks source link

How to pass parameters from Triton's config.pbtxt to model.dali #5537

Closed Bycqg closed 3 months ago

Bycqg commented 3 months ago

Describe the question.

# generate the model.dali file for Triton

import nvidia.dali as dali
import nvidia.dali.fn as fn
import nvidia.dali.types as types

@dali.pipeline_def
def pipeline(mean=[128.0, 128.0, 128.0]):
    images = fn.external_source(device='cpu', name='DALI_INPUT_0')
    images = fn.decoders.image(images, device="mixed", output_type=types.RGB)
    images = fn.resize(images, resize_x=299, resize_y=299)
    images = fn.crop_mirror_normalize(images, mean=mean, std=[1.0, 1.0, 1.0], output_layout="HWC")
    return images

pipeline().serialize(filename='./dali_preprocess/1/model.dali')

Can I set a parameter externally (e.g., in the config.pbtxt file) to replace the default values previously set in model.dali (i.e., [128.0, 128.0, 128.0] in the code) with a new value (e.g., mean=[115.0, 116.0, 118.0])?

If so, how can I do it? It would be best if you could provide an example or documentation.

Check for duplicates

banasraf commented 3 months ago

Hi @Bycqg There is no way to set operators' arguments through the config.pbtxt file. Could you tell me more about the context of what you want to achieve and why do you need a config at all, instead of relying on auto-configuration?

Bycqg commented 3 months ago

Hi @banasraf I have many classification models, but their preprocessing is almost the same. The only difference lies in the mean values used during normalization, such as mean_vals being [109.3, 108.2, 107.2], [111.3, 128.2, 137.2], etc. If parameters can be passed in the config.pbtxt, then I only need to configure one DALI model and pass in different mean_vals for different classification models.

banasraf commented 3 months ago

I see. Currently, there is no way to pass any arbitrary arguments from config to DALI models. The approach I would suggest is duplicating the model definition itself (as a Python file) and changing necessary values in each model. You don't have to serialize those models and usually you don't have to provide any configuration, so duplicating the code shouldn't impose too much of overhead.

Bycqg commented 3 months ago

thank you