xnn.common.models.fast#
Fast paths: optimized kernels behind the same parameters as the reference code.
A module with a fast path keeps exactly the parameters, buffers and
state_dict of its reference implementation and adds a second way of
evaluating them (for example a fused GPU kernel). Checkpoints, the model hub and
the trainer never see the difference, and the reference stays the canonical
implementation: TorchScript export, CPU runs and anything the fast backend does
not support use it.
Every such module subclasses FastPathModule. A model owning them
chooses, once per evaluation, whether they run fast:
use_fast=Falsealways the reference code.
use_fast=Truethe fast path wherever it is available (the reference otherwise).
use_fast="auto"(the default)the fast path when it is available and measured to be faster for this input, i.e. on a GPU and above a size threshold per GPU model (see
AutoPolicy).
The fast kernels compute the same function with a different summation order,
so results agree with the reference to rounding: about 1e-6 relative in
float32 and 1e-14 in float64. A one-time FastPathPrecisionWarning
says so when a fast path first runs in float32.
Functions
|
Switch every fast path inside |
|
Every |
|
The fast-path modules of |
|
Validate a |
|
Set |
|
Set |
Issue the float32 precision warning, once per process. |
Classes
|
When |
Mixin of a module with a reference and a fast implementation. |
Exceptions
A fast path ran in float32: results differ from the reference at ~1e-6. |