AMP, backward under ``autocast(bf16)``), and a null context would let that
ambient state leak into the replay, changing recomputed tensor dtypes.
"""
if kwargs is None:
return contextlib.nullcontext()
if not kwargs.get("enabled", False) and not torch.is_autocast_enabled(device_type):
# Saved and ambient state are both "disabled": entering autocast here
# would only trigger needless device backend setup.
return contextlib.nullcontext()