Skip to content

[PyTorch] Add ops for dropout and constant scale #1995

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

Merged
merged 4 commits into from
Jul 25, 2025

Conversation

timmoon10
Copy link
Collaborator

Description

This PR adds fusible ops for dropout (heavily based on torch.nn.Dropout) and multiplying by a constant scalar. These are not performant, but they provide an API for future custom implementations or fusions.

Type of change

  • Documentation change (change only to the documentation, either a fix or a new content)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Infra/Build change
  • Code refactoring

Changes

  • Add fusible ops for dropout and constant scale

Checklist:

  • I have read and followed the contributing guidelines
  • The functionality is complete
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@timmoon10 timmoon10 requested a review from negvet July 25, 2025 05:10
@timmoon10
Copy link
Collaborator Author

/te-ci pytorch

Copy link
Collaborator

@negvet negvet left a comment

Choose a reason for hiding this comment

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

LGTM

is_training = self.training
mask = None
if is_training:
keep_prob = 1 - self.dropout_probability
Copy link
Collaborator

@negvet negvet Jul 25, 2025

Choose a reason for hiding this comment

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

Handing this case similar to torch.nn.Dropout:

Suggested change
keep_prob = 1 - self.dropout_probability
if self.dropout_probability == 1:
mask = torch.zeros_like(input_)
out = mask
else:
keep_prob = 1 - self.dropout_probability

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The existing impl should handle this case correctly. We will also replace this mask-based impl soon, so no need to optimize aggressively.

@timmoon10 timmoon10 merged commit c6c1f50 into NVIDIA:main Jul 25, 2025
11 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants