detrium.tasks.detect.grad_statistics

CUDA Graph execution of the native adaptive-distillation gradient statistic. The caller supplies the native statistic as ``reference`` and retains its position relative to unscale, clipping and optimizer updates. The graph only contains the same per-gradient abs/sum and grouped stack operations. Gradients are copied into independent buffers; reductions, dtypes and Python addition order are unchanged. This component is not an nn.Module and registers no model state. Create a fresh instance, or clear it, after loading a checkpoint. New capture is disabled by default. Enable it explicitly during a safe warmup at an epoch/step boundary, then disable it for normal execution. Existing graphs continue to replay while new schemas use the native reference. CUDA errors, including allocation/capture failures, propagate to the caller.

class GradGraphPercentage

Bounded, opt-in runtime cache for the native gradient percentage. ``reference`` must be the native encoder-transformer gradient-percentage callable. Capture is validated only for PyTorch 2.5.1, CUDA 12.1 and A800 (sm80); other environments use that reference and record a fallback reason. No CUDA error is caught and retried as native execution. Model identity, parameter names/order/identity, participating gradients, layout/dtype/device, current stream and autocast context define each schema. Gradient storage can change without recapture. A fifth schema falls back; ``clear(model)`` allows a later epoch to build a fresh bounded cache after freezing/unfreezing parameters. Call lifecycle methods between steps; one instance is intended for one trainer thread.

名称类型默认值
reference——
enabled—True
capture_allowed—False
max_schemas—4
warmup—3