MIR.utils.precisionΒΆ
Mixed-precision helpers: one precision switch for training and inference.
MIR models run in float32 (default), float16 or bfloat16 mixed precision (torch.autocast) and in pure float16
inference (model.half()). Losses and regularizers always compute in float32 and return a float32 value; spatial
transformers, integrators and Fourier kernels compute their geometry in float32 and return the input dtype.
Example:
from MIR.utils.precision import autocast, grad_scaler
scaler = grad_scaler(precision) # active only for fp16 on CUDA
with autocast(precision):
flow = model((mov, fix))
loss = sim(warped, fix) + reg(flow)
scaler.scale(loss).backward()
scaler.step(optimizer)
scaler.update()
Functions
|
Context manager for the requested precision (a no-op for |
|
Raise a clear error when |
|
Gradient scaler for the requested precision. |
|
Return the torch dtype for |