ttnn.bias_gelu_bw

ttnn.bias_gelu_bw(grad_tensor: ttnn.Tensor, input_tensor_a: ttnn.Tensor, input_tensor_b: ttnn.Tensor, input_tensor: ttnn.Tensor, bias: float, *, variant: ttnn.GeluVariant = GeluVariant.Accurate, approximate: string, memory_config: ttnn.MemoryConfig = None) → List of ttnn.Tensor

Performs backward operations for bias GELU on input_tensor_a and input_tensor_b or input_tensor and bias, with given grad_tensor and variant.

Supported call forms:

  • ttnn.bias_gelu_bw(grad_tensor, input_tensor_a, input_tensor_b, ...)

  • ttnn.bias_gelu_bw(grad_tensor, input_tensor, bias, ...)

Parameters:
  • grad_tensor (ttnn.Tensor)the input gradient tensor.

  • input_tensor_a (ttnn.Tensor)the first input tensor for the tensor-bias overload.

  • input_tensor_b (ttnn.Tensor)the bias tensor for the tensor-bias overload.

  • input_tensor (ttnn.Tensor)the input tensor for the scalar-bias overload.

  • bias (float)the scalar bias for the scalar-bias overload.

Keyword Arguments:
  • variant (ttnn.GeluVariant, optional)Selects the GELU implementation. Defaults to GeluVariant.Accurate. - Accurate: piecewise-CDF (BF16) or FP32-erf derivative. - Tanh: derivative of the FP32 Hendrycks tanh approximation. - FastLut: not supported because no matching backward kernel is available.

  • approximate (string)Legacy approximation mode (“none” or “tanh”).

  • memory_config (ttnn.MemoryConfig, optional)Memory configuration for the 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 gradient and input tensors for bias GELU backward
grad_tensor = ttnn.from_torch(
    torch.tensor([[1, 2], [3, 4]], dtype=torch.bfloat16), layout=ttnn.TILE_LAYOUT, device=device
)
tensor1 = ttnn.from_torch(
    torch.tensor([[1, 2], [3, 4]], dtype=torch.bfloat16, requires_grad=True), layout=ttnn.TILE_LAYOUT, device=device
)
tensor2 = ttnn.from_torch(
    torch.tensor([[1, 2], [3, 4]], dtype=torch.bfloat16, requires_grad=True), layout=ttnn.TILE_LAYOUT, device=device
)
approximate = "none"

# Compute gradients for bias GELU operation
output = ttnn.bias_gelu_bw(grad_tensor, tensor1, tensor2, approximate=approximate)
logger.info(f"Bias GELU backward result: {output}")