Decorate a custom Function.backward to run in its forward's autocast state.
The decorated backward runs inside an autocast scope matching the one
custom_fwd recorded — on at the same dtype, or off — whatever
scope .backward() was called from, so the arithmetic on the gradient
and the tensors forward saved sees the dtypes it saw going forward.
Parameters
bwdcallable= NoneThe
backward to decorate; leave it out to get the decorator.device_ typestr"metal" or "cpu", the same as forward's. Keyword-only
and required.Returns
callableThe decorated backward (bwd given), or the decorator.
Raises
ValueErrorIf
device_type is neither "metal" nor "cpu".RuntimeErrorWhen the decorated
backward runs: if forward was not
decorated with custom_fwd, or was with another
device_type.See Also
custom_fwd—the matchingforwarddecorator, with a worked example.