Implementation:NVIDIA DALI Paddle Training Config
| Knowledge Sources | |
|---|---|
| Domains | Vision, Training |
| Last Updated | 2026-02-08 16:00 GMT |
Overview
Provides a comprehensive argument parser and configuration processor for the PaddlePaddle ResNet-50 training pipeline with DALI integration.
Description
This module defines the full command-line interface for configuring the PaddlePaddle ResNet-50 training example. It uses Python's argparse to organize arguments into logical groups: Global settings (output directory, run scope, epochs, checkpointing), Dataset settings (image root, shape, batch size, DALI configuration), Data Augmentation (crop, normalization, resize), Model settings (architecture, number of classes, BN weight decay), Training settings (optimizer, learning rate, label smoothing), Advanced Training (AMP, FP16, ASP sparsity, ResUnit fusion), and Paddle-TRT inference settings.
The check_and_process_args function performs post-parse validation and transformation, including converting the run scope string to an enum, reordering image shape for NHWC layout, scaling the learning rate by the number of trainers for distributed training, resolving checkpoint and pretrained parameter paths, and enforcing benchmark mode constraints. Helper functions _get_full_path_of_ckpt and _get_full_path_of_pretrained_params handle automatic checkpoint discovery with support for an "auto" mode that finds the latest epoch checkpoint by scanning folders.
The module also includes a str2bool utility for parsing boolean command-line arguments from various string representations, and a print_args function that logs all configuration parameters via dllogger for reproducibility.
Usage
Use this module as the configuration entry point for the PaddlePaddle ResNet-50 DALI training example. Call parse_args() at the start of the training script to obtain a fully validated and processed argument namespace. Pass including_trt=True when running TensorRT inference.
Code Reference
Source Location
- Repository: NVIDIA_DALI
- File: docs/examples/use_cases/paddle/resnet50/utils/config.py
- Lines: 1-608
Signature
def str2bool(value, raise_exc=False): ...
def check_and_process_args(args): ...
def add_global_args(parser): ...
def add_advance_args(parser): ...
def add_dataset_args(parser): ...
def add_model_args(parser): ...
def add_training_args(parser): ...
def add_trt_args(parser): ...
def parse_args(including_trt=False): ...
def print_args(args): ...
Import
from utils.config import parse_args, print_args
I/O Contract
Inputs (parse_args)
| Name | Type | Required | Description |
|---|---|---|---|
| including_trt | bool | No | Whether to include Paddle-TRT inference arguments. Default: False. |
Outputs (parse_args)
| Name | Type | Description |
|---|---|---|
| args | argparse.Namespace | Fully parsed and validated configuration namespace with all training, model, dataset, and optional TRT parameters. |
Key Configuration Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| --output-dir | str | ./output/ | Path to store trained model checkpoints. |
| --run-scope | str | train_eval | One of train_eval, train_only, eval_only. |
| --epochs | int | 90 | Number of training epochs. |
| --batch-size | int | 256 | Batch size for training and evaluation. |
| --lr | float | 0.256 | Initial learning rate (scaled by number of trainers). |
| --amp | flag | False | Enable automatic mixed precision training. |
| --use-pure-fp16 | flag | False | Enable pure FP16 training (requires --amp). |
| --asp | flag | False | Enable automatic sparsity training. |
| --dali-num-threads | int | 4 | Number of threads for DALI data loader. |
| --dali-random-seed | int | 42 | Random seed for DALI data loader reproducibility. |
| --data-layout | str | NCHW | Data format, NCHW or NHWC. |
Usage Examples
Basic training configuration
from utils.config import parse_args, print_args
# Parse command-line arguments
args = parse_args()
# Log configuration
print_args(args)
# Access configuration values
print(f"Training for {args.epochs} epochs with batch size {args.batch_size}")
print(f"Learning rate: {args.lr}, AMP enabled: {args.amp}")
print(f"DALI threads: {args.dali_num_threads}")
Parsing with TRT inference options
from utils.config import parse_args
# Include TensorRT inference arguments
args = parse_args(including_trt=True)
print(f"TRT precision: {args.trt_precision}")
print(f"TRT workspace: {args.trt_workspace_size}")