2021-12-21 04:19:52 +00:00
|
|
|
import torch
|
|
|
|
|
|
|
|
|
|
|
|
def bias_dropout_add(x, bias, residual, prob, training):
|
|
|
|
# type: (Tensor, Tensor, Tensor, float, bool) -> Tensor
|
|
|
|
out = torch.nn.functional.dropout(x + bias, p=prob, training=training)
|
|
|
|
out = residual + out
|
|
|
|
return out
|
|
|
|
|
|
|
|
|
|
|
|
@torch.jit.script
|
2023-09-19 06:20:26 +00:00
|
|
|
def bias_dropout_add_fused_train(
|
|
|
|
x: torch.Tensor, bias: torch.Tensor, residual: torch.Tensor, prob: float
|
|
|
|
) -> torch.Tensor:
|
2021-12-21 04:19:52 +00:00
|
|
|
return bias_dropout_add(x, bias, residual, prob, True)
|
|
|
|
|
|
|
|
|
|
|
|
@torch.jit.script
|
2023-09-19 06:20:26 +00:00
|
|
|
def bias_dropout_add_fused_inference(
|
|
|
|
x: torch.Tensor, bias: torch.Tensor, residual: torch.Tensor, prob: float
|
|
|
|
) -> torch.Tensor:
|
2021-12-21 04:19:52 +00:00
|
|
|
return bias_dropout_add(x, bias, residual, prob, False)
|