Skip to content

Commit

Permalink
fix dropout scaling from p to 1/(1-p) (#816)
Browse files Browse the repository at this point in the history
Co-authored-by: Sukru Eryilmaz <[email protected]>
  • Loading branch information
seryilmaz and Sukru Eryilmaz authored Apr 30, 2020
1 parent 1f2aa91 commit aad9300
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion apex/contrib/multihead_attn/self_multihead_attn_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def backward(ctx, output_grads):
values_grads = torch.bmm(dropout_results.transpose(1,2), output_lin_grads, out=values_grads.transpose(0,1))

# Mask and Scaling for Dropout (not a publically documented op)
dropout_grads = torch._masked_scale(matmul2_dgrad1, dropout_mask, dropout_prob_t[0])
dropout_grads = torch._masked_scale(matmul2_dgrad1, dropout_mask, 1.0/(1.0-dropout_prob_t[0]))

# Softmax Grad (not a publically documented op)
softmax_grads = torch._softmax_backward_data(dropout_grads, softmax_results, -1, softmax_results)
Expand Down

0 comments on commit aad9300

Please sign in to comment.