Skip to content

Commit 8e2dfc5

Browse files
committed
simplify aut-fwd/bwd registration
Signed-off-by: Masaki Kozuki <mkozuki@nvidia.com>
1 parent d7242bf commit 8e2dfc5

1 file changed

Lines changed: 2 additions & 13 deletions

File tree

‎thunder/core/transforms.py‎

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1659,6 +1659,7 @@ def zeros_like(x):
16591659
prims.PrimIDs.FMOD: lambda x, y: (prims.fmod(x, y), (x, y)),
16601660
prims.PrimIDs.COPY_: lambda x, y, grad_enabled: (prims.copy_(x, y, grad_enabled=grad_enabled), tuple()),
16611661
prims.PrimIDs.CLONE: lambda x: (prims.clone(x), tuple()),
1662+
prims.PrimIDs.BITCAST: lambda x, dtype: (prims.bitcast(x, dtype), (x.dtype,)),
16621663
}
16631664

16641665

@@ -1689,6 +1690,7 @@ def zeros_like(x):
16891690
prims.PrimIDs.FMOD: lambda x, y, g: (g, -g * prims.trunc(x / y)),
16901691
prims.PrimIDs.COPY_: lambda g: (g, None),
16911692
prims.PrimIDs.CLONE: lambda g: g,
1693+
prims.PrimIDs.BITCAST: lambda x_dtype, g: (prims.bitcast(g, x_dtype), None),
16921694
}
16931695

16941696

@@ -2552,19 +2554,6 @@ def index_put_backward(indices: Sequence[TensorProxy], values: TensorProxy, accu
25522554
return clang.index_put(g, indices, ltorch.zeros_like(values), False), g_values
25532555

25542556

2555-
def _bitcast_prim_grad(src: TensorProxy, dtype: dtypes.dtype) -> TensorProxy:
2556-
fwd = prims.bitcast(src, dtype)
2557-
2558-
g = get_grad(fwd)
2559-
src_grad = prims.bitcast(g, src.dtype)
2560-
put_grad(src, src_grad)
2561-
2562-
return fwd
2563-
2564-
2565-
register_grad(pids.BITCAST, _bitcast_prim_grad)
2566-
2567-
25682557
def uniform_aug_fwd(shape, minval, maxval, *, device, dtype):
25692558
primal = prims.uniform(shape, minval, maxval, device=device, dtype=dtype)
25702559
return VJPDual(primal, (primal, minval, maxval))

0 commit comments

Comments
 (0)