determinism#

Best-effort determinism for reproducible runs.

Functions

deterministic_attn_implementation

Return the attention implementation to load a model with for a reproducible run.

enable_determinism

Seed every random number generator and ask PyTorch for deterministic kernels.

deterministic_attn_implementation(requested=None)#

Return the attention implementation to load a model with for a reproducible run.

That is requested if it is one of DETERMINISTIC_ATTN_IMPLEMENTATIONS, else "eager", with a warning when something else was asked for. "modelopt_sdpa_efficient" is SDPA pinned to PyTorch’s memory-efficient kernel, with a mask for every batch: like eager it runs one kernel whatever the batch holds, and unlike eager it never builds the attention matrix. It is registered with transformers here, so call this before loading the model.

Parameters:

requested (str | None)

Return type:

str

enable_determinism(seed)#

Seed every random number generator and ask PyTorch for deterministic kernels.

An operation without a deterministic kernel only warns, so repeated runs on the same hardware, software and parallel layout agree as closely as the remaining kernels allow. Call this at startup, before the first CUDA matmul: cuBLAS reads CUBLAS_WORKSPACE_CONFIG when it creates its handle. A value of that variable that is already set is kept, with a warning if cuBLAS does not treat it as deterministic.

Parameters:

seed (int)

Return type:

None