ttnn.gelu_bw
- ttnn.gelu_bw(grad_tensor: ttnn.Tensor, input_tensor: ttnn.Tensor, *, variant: ttnn.GeluVariant = ``ttnn.GeluVariant.Accurate``, memory_config: ttnn.MemoryConfig = None, input_grad: ttnn.Tensor = None) List of ttnn.Tensor
-
Performs backward operations for GELU on
input_tensor, with givengrad_tensorandvariant.- Parameters:
-
grad_tensor (ttnn.Tensor)the input gradient tensor.
input_tensor (ttnn.Tensor)the input tensor.
- Keyword Arguments:
-
variant (ttnn.GeluVariant, optional)Select GELU implementation. Defaults to
ttnn.GeluVariant.Accurate.memory_config (ttnn.MemoryConfig, optional)memory configuration for the operation. Defaults to None.
input_grad (ttnn.Tensor, optional)preallocated output tensor. Defaults to None.
- Returns:
-
List of ttnn.Tensorthe output tensor.
Note
Supported dtypes and layouts:
Dtypes
Layouts
BFLOAT16, FLOAT32, BFLOAT8_B, BFLOAT4_B
TILE
For more details about BFLOAT8_B, refer to the BFLOAT8_B limitations.
Example
# Create sample tensors for backward GELU operation grad_tensor = ttnn.from_torch( torch.tensor([[1, 2], [3, 4]], dtype=torch.bfloat16), layout=ttnn.TILE_LAYOUT, device=device ) input_tensor = ttnn.from_torch( torch.tensor([[1, 2], [3, 4]], dtype=torch.bfloat16, requires_grad=True), layout=ttnn.TILE_LAYOUT, device=device ) # Call the gelu_bw function with approximation method output = ttnn.gelu_bw(grad_tensor, input_tensor, variant=ttnn.GeluVariant.Accurate) logger.info(f"GELU Backward: {output}")