lens.strategies
Export strategy registry: maps strategy names to per-rank decision callables.
A strategy is a callable taking (config, rank, world_size) and returning
True if this rank should export telemetry data. Lens ships four built-ins
and lets users register their own under a chosen name; the chosen name is
selected via NemoLensConfig.export_strategy or the
NEMO_LENS_EXPORT_STRATEGY env var.
Module Contents
Functions
Data
API
Built-in: every rank exports.
Built-in: the first local rank on each node exports.
Reads LOCAL_RANK (set by torchrun, deepspeed, etc.). Treats a missing
LOCAL_RANK as "0", which gives the expected single-node behaviour.
Built-in: deterministic hash-based sampling. Same rank + same rate → same outcome.
Built-in: only config.export_rank exports (-1 means last rank).
Look up a registered strategy by name.
Raises:
ValueError: Ifnameis not registered. Error message lists the currently registered names.
Register a custom export strategy under name.
Once registered, the strategy is selectable via
NemoLensConfig(export_strategy=name) or
NEMO_LENS_EXPORT_STRATEGY=<name>.
Parameters:
Strategy identifier. Must be a non-empty string.
Callable (config, rank, world_size) -> bool.
If False (default), raises ValueError when
name is already registered. Built-in names are protected
and additionally require allow_override=True to replace.
Raises:
ValueError: Ifnameis empty, or already registered withoutallow_override=True.
Return a sorted list of registered strategy names (built-ins + custom).
Remove a strategy from the registry.
Raises:
ValueError: Ifnamerefers to a built-in strategy, or is unknown.