NVIDIA DALI Documentation

repository·main·Indexed 26 days ago

https://github.com/nvidia/dali

A GPU-accelerated library for high-performance data loading and pre-processing in deep learning pipelines. Documentation covers performance tuning (memory allocators, buffer growth, thread affinity, and prefetching), pipeline checkpointing, and setup for AFL fuzzing.

Tokens
33.4K
Snippets
60
Records
164
Agent score
90%

What's inside NVIDIA DALI

  1. Overview of NVIDIA DALI

    main

    NVIDIA DALI (Data Loading Library) is a GPU-accelerated library designed to accelerate deep learning applications by offloading data loading and pre-processing (loading, decoding, cropping, resizing, etc.) from the CPU to the GPU.

    Key features include:

    • High Performance: Uses a custom execution engine with prefetching, parallel execution, and batch processing.
    • Portability: Pipelines can be retargeted across TensorFlow, PyTorch, PaddlePaddle, and JAX.
    • Format Support: Supports LMDB, RecordIO, TFRecord, COCO, JPEG, JPEG 2000, WAV, FLAC, OGG, H.264, VP9, and HEVC.
    • Scalability: Supports CPU/GPU execution and scales across multiple GPUs.
    • Advanced Integration: Supports GPUDirect Storage and NVIDIA Triton Inference Server via the DALI TRITON Backend.
  2. Overview of DALI Dynamic API

    main

    DALI Dynamic is an experimental feature that introduces an imperative execution model with lazy evaluation to NVIDIA DALI. It is designed to complement the existing graph-based pipeline execution by enabling seamless integration into Python workflows, making it easier to debug and prototype pre-processing pipelines.

    Key advantages include:

    • Direct control of operator execution within iterative workflows.
    • Simplified integration with existing Python code and libraries.
    • Incremental writing and debugging of pipelines.
    • Asynchronous operator evaluation for improved performance.

    Note: DALI Dynamic does not replace the graph-based Pipeline API; it serves as an alternative interface for a better Python experience. You can transition between the two modes easily as they use the same operators.

  3. Thread safety in nvidia.dali.experimental.dynamic

    main

    Dynamic mode in nvidia.dali.experimental.dynamic is generally thread-safe and supports free-threaded Python. Operators can be called concurrently from multiple threads, and Tensor and Batch objects can be safely passed between threads.

    Constraint: A single EvalContext instance must not be active in multiple threads simultaneously. While the default evaluation context is thread-local, manually created EvalContext objects shared across threads will cause exceptions.

  4. Compare Pipeline API vs. Dynamic API

    main

    DALI provides two distinct API modes:

    • DALI Pipeline API: Uses a fixed graph of operations defined upfront. It is optimized for performance and uses the Pipeline class, nvidia.dali.fn operations, and nvidia.dali.math expressions.
    • DALI Dynamic API: Allows running operators in an imperative manner without defining the data processing graph upfront. This offers more flexibility but incurs a small performance overhead.
  5. Run DALI on CPU without a GPU

    main
    DALI can operate without a GPU because most operators have both CPU and GPU variants. A pipeline consisting entirely of CPU operators will run on machines without a GPU. This is useful for developing pipelines on laptops before deploying them to GPU-enabled clusters. Note that CPU operators are not as thoroughly optimized as their GPU counterparts.
  6. Understand the difference between Functional and Legacy Operator APIs

    main

    DALI provides two ways to define operations: the recommended functional API (dali.fn) and the legacy operator object API (dali.ops).

    • Functional API (dali.fn): Uses snake_case names. Operations are typically called directly within a pipeline context. This is the current recommended approach.
    • Legacy Operator API (dali.ops): Uses camelCase names. This API separates the definition of an operator (where static arguments are set during instantiation) from its use in a pipeline.

    Example mapping: dali.fn.crop_mirror_normalize is the functional counterpart to the legacy dali.ops.CropMirrorNormalize.

    You can mix both APIs within a single pipeline.

  7. Automatic Augmentation Library Concepts

    main

    The nvidia.dali.auto_aug library is structured around three core concepts:

    • augmentation: An image processing operation. DALI provides common augmentations and allows you to implement new ones using the @augmentation decorator from nvidia.dali.auto_aug.core.augmentation.
    • policy: A collection of augmentations and parameters (probability and strength) that define how to apply transformations to input images.
    • apply operation: A function that invokes a specific policy on a batch of images within a DALI pipeline.
  8. Choose between DALI and RAPIDS

    main
    Use RAPIDS for general-purpose machine learning and data analytics. Use DALI for specialized Deep Learning workflows, specifically to accelerate dense data processing (images, video, audio) and to overlap preprocessing with network forward/backward passes.
  9. Integrate DALI Dynamic with TorchData

    main
    DALI Dynamic (nvidia.dali.experimental.dynamic.pytorch.nodes) provides integration with torchdata.nodes to build composable data loading pipelines. You can compose DALI Dynamic nodes with standard torchdata.nodes building blocks like torchdata.nodes.Prefetcher and torchdata.nodes.Loader to create complex data loading graphs.
  10. Prerequisites for DALI installation

    main

    Before installing DALI, ensure your environment meets the following requirements:

    1. OS: Linux x64.
    2. NVIDIA Driver: Must support CUDA 12.0 or later (e.g., driver version 525.60 or later).
    3. CUDA Toolkit: Must be installed as it is linked dynamically.
    4. Deep Learning Frameworks (Optional): PyTorch, TensorFlow, JAX, or PaddlePaddle.
  11. Broadcasting and shape extension in DALI

    main

    DALI uses broadcasting to handle operations between tensors of different shapes.

    Broadcasting Rules:

    • A scalar is broadcast to all output values.
    • If one operand has size 1 in a dimension, it is broadcast along that dimension to match the other operand.
    • Shape Extension: If tensors have a different number of dimensions, DALI pads the shapes with outer unit dimensions (e.g., a shape (3,) is treated as (1, 1, 3) when operating with a (480, 640, 3) tensor).

    Limitations: Broadcasting complexity is limited to a maximum of six alternating broadcast/non-broadcast groups.