Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enabling bias_dropout_add_fused with no bias term #9676

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also update bias_dropout_add_fused_inference_ to check if bias exists? otherwise it seems the type would mismatch when doing x + bias

Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,23 @@ def bias_dropout_add_fused_train_(
return bias_dropout_add(x, bias, residual, prob, True)


@torch.jit.script
def dropout_add_fused_train_(x: torch.Tensor, bias: torch.Tensor, residual: torch.Tensor, prob: float) -> torch.Tensor:
# type: (Tensor, None, Tensor, float) -> Tensor
return dropout_add(x, bias, residual, prob, True)


def bias_dropout_add_fused_train(x, bias, residual, prob):
# re-enable torch grad to enable fused optimization.
with torch.enable_grad():
args = _cast_if_autocast_enabled(x, bias, residual, prob)
with torch.cuda.amp.autocast(enabled=False):
return bias_dropout_add_fused_train_(*args)
if bias:
args = _cast_if_autocast_enabled(x, bias, residual, prob)
with torch.cuda.amp.autocast(enabled=False):
return bias_dropout_add_fused_train_(*args)
else:
args = _cast_if_autocast_enabled(x, residual, prob)
with torch.cuda.amp.autocast(enabled=False):
return dropout_add_fused_train_(*args)


@torch.jit.script
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ def _get_bias_droput_add_func(self, transformer_block_type='pre_ln', position_af
if transformer_block_type == 'normformer' and position_after == 'attention':
bias_dropout_add_func = get_dropout_add(self.training)
# Bias dropout add fused kernel
elif self.bias and self.bias_dropout_add_fusion:
elif self.bias_dropout_add_fusion:
if self.training:
bias_dropout_add_func = bias_dropout_add_fused_train
else:
Expand Down
Loading