PyTorch-Ignite is a lightweight and user-friendly library designed to simplify training and evaluating neural networks with PyTorch. It provides a high-level API for setting up training loops, handling events, and integrating various experiment tracking tools. Currently at version 0.5.4, it maintains an active release cadence with frequent bug fixes and feature enhancements.
pip install pytorch-igniteVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates setting up a basic training loop with PyTorch-Ignite. It defines a simple PyTorch model, creates a trainer and evaluator using `create_supervised_trainer` and `create_supervised_evaluator`, attaches a handler to log results after each epoch, and runs the training process. The example includes dummy data for immediate execution.
Update all `from ignite.contrib.metrics import ...` to `from ignite.metrics import ...` and `from ignite.contrib.handlers import ...` to `from ignite.handlers import ...`.
Review the official documentation for `ignite.handlers.LRScheduler` to adapt to the new API. Instead of calling it, attach it to the `trainer` engine with the optimizer, e.g., `LRScheduler(optimizer, CosineAnnealingScheduler(lr_values=[1e-1, 1e-3], cycle_size=100)).attach(trainer, Events.ITERATION_STARTED)`.
Before any `idist` calls, ensure `from ignite.distributed import auto_model_and_optimizer_distributed, init_distributed, ...` and call `init_distributed()` or similar initialization routines appropriate for your distributed setup.
Always test event handler logic with simple examples. Refer to the official documentation on 'Event Filtering' for detailed explanations and examples of how `Events.X(every=N, once=M, before=Y, after=Z)` combinations work.
Change import statements. For example, `from ignite.contrib.metrics import Accuracy` should become `from ignite.metrics import Accuracy`.
Instead of calling, attach the `LRScheduler` instance to the trainer. Example: `LRScheduler(optimizer, lr_scheduler_function).attach(trainer, Events.ITERATION_STARTED)`.
Call `ignite.distributed.init_distributed()` or similar initialization function relevant to your setup (e.g., `torch.distributed.init_process_group` if managing manually) at the start of your script before any distributed operations.
Ensure your model and input data are consistently on the same device. Use `.to(device)` on models, tensors, and data loaders (via custom collate_fn) where `device = 'cuda' if torch.cuda.is_available() else 'cpu'`.