nemo_automodel.components.distributed.blockdiag_cp.state
nemo_automodel.components.distributed.blockdiag_cp.state
Runtime knobs and activation-checkpoint-safe state for block-diagonal CP.
The knob normalization (synonym maps and defaults) lives here, in a
dependency-free leaf, so every consumer (the kernel-side
:func:configure_cp_varlen entry point and any policy-side config parser)
derives the accepted values from the same table and can never disagree on
synonyms or defaults.
Module Contents
Classes
Functions
Data
API
A contextvars.ContextVar-style get/set/reset holder visible ACROSS threads.
The block-diagonal CP state must be readable inside the autograd worker thread
that runs activation-checkpointing recompute during backward. A real
ContextVar is per-thread and reads its default (None) there, which would
silently drop the CP state mid-recompute — the softmax SDPA would fall back to
local-only attention. Training steps are sequential, so a single shared slot
with token-based restore (supporting nesting) is safe; backward only ever READS
the slot.
Return the current value (None when unset).
Restore the value captured by a previous :meth:set.
Set the value; returns a token (the previous value) for :meth:reset.
Configure the block-diagonal CP attention path from parsed runtime config.
Parameters:
Varlen kernel selection; any synonym accepted by
:func:normalize_attn_backend (default "flash").
K/V delivery mode; any synonym accepted by
:func:normalize_kv_exchange (default "allgather").
Number of block-diagonal CP attention calls since the last reset.
Return the currently configured block-diagonal CP runtime settings.
Returns: dict[str, str]
A dict with keys "attn_backend" and "kv_exchange" holding the
Canonicalize an attention-backend knob to one of ATTN_BACKEND_VALUES.
None/""/auto/default map to the default (flash).
Parameters:
The raw user-facing knob value (string-like or None).
Returns: str
The canonical backend name ("flash", "te", or "dense").
Raises:
ValueError: If the value is not a recognized backend or synonym.
Canonicalize a KV-exchange knob to one of KV_EXCHANGE_VALUES.
None/""/auto/default map to the default (allgather).
Parameters:
The raw user-facing knob value (string-like or None).
Returns: str
The canonical exchange name ("allgather", "halo", or "a2a").
Raises:
ValueError: If the value is not a recognized exchange mode or synonym.
Zero the CP-attention fire counter (call before each forward).