Lightning Utilities
Lightning Utilities is a toolbox providing general Python utilities, reusable GitHub workflows, and shared GitHub actions for the broader Lightning ecosystem. It aims to offer common functionalities and development practices across Lightning-AI projects. The current version is 0.15.3, with frequent releases including patch and minor versions every few weeks.
Warnings
- breaking Dropped support for Python 3.9. Users must upgrade to Python 3.10 or newer.
- breaking The internal CLI backend switched from `fire` to `jsonargparse`.
- deprecated The `apply_to_collection` utility in `pytorch_lightning.utilities.apply_func` is deprecated.
- gotcha Using `apply_to_collection` on frozen dataclasses without explicitly setting `allow_frozen=True` can raise a `MisconfigurationException`.
- gotcha To use the `lightning_utilities.cli` module, you must install the library with the `[cli]` extra, i.e., `pip install 'lightning-utilities[cli]'`.
Install
-
pip install lightning-utilities -
pip install 'lightning-utilities[cli]'
Imports
- module_available
from lightning_utilities.core.imports import module_available
- apply_to_collection
from lightning_utilities.core.apply_func import apply_to_collection
- cli
import lightning_utilities.cli
Quickstart
from lightning_utilities.core.apply_func import apply_to_collection
def double(x):
return x * 2
data = [1, {'a': 2, 'b': [3, 4]}, (5, 6)]
result = apply_to_collection(data, int, double)
print(result)
# Expected output: [2, {'a': 4, 'b': [6, 8]}, (10, 12)]