-
Notifications
You must be signed in to change notification settings - Fork 88
Implement aten::feature_dropout #2404
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
3b4c5a3
658f966
29f1968
af8d622
96f78cd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3538,10 +3538,67 @@ def aten_feature_alpha_dropout(input: TensorType, p: float, train: bool) -> Tens | |||||||||
| raise NotImplementedError() | ||||||||||
|
|
||||||||||
|
|
||||||||||
| def aten_feature_dropout(input: TensorType, p: float, train: bool) -> TensorType: | ||||||||||
| @torch_op("aten::feature_dropout", trace_only=True) | ||||||||||
| def aten_feature_dropout(input: TFloat, p: FLOAT, train: BOOL) -> TFloat: | ||||||||||
| """feature_dropout(Tensor input, float p, bool train) -> Tensor""" | ||||||||||
|
|
||||||||||
| raise NotImplementedError() | ||||||||||
| # Feature dropout applies dropout to entire feature maps/channels | ||||||||||
| # rather than individual elements | ||||||||||
|
|
||||||||||
| # Use ONNX operations to handle control flow | ||||||||||
| # In inference mode or when p=0, return input unchanged | ||||||||||
| should_dropout = op.And(train, p > 0.0) | ||||||||||
|
|
||||||||||
| # Get input shape | ||||||||||
| input_shape = op.Shape(input) | ||||||||||
| ndim = op.Size(input_shape) | ||||||||||
|
|
||||||||||
| # Create mask shape for feature dropout | ||||||||||
| # For 2D tensors [N, C]: mask shape is [N, C] | ||||||||||
| # For higher dim tensors [N, C, ...]: mask shape is [N, C, 1, 1, ...] | ||||||||||
| batch_size = op.Gather(input_shape, [0]) | ||||||||||
| channel_size = op.Gather(input_shape, [1]) | ||||||||||
|
||||||||||
| batch_size = op.Gather(input_shape, [0]) | |
| channel_size = op.Gather(input_shape, [1]) | |
| batch_size = op.Shape(input, start=0, end=0) | |
| batch_size = op.Shape(input, start=1, end=1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to use op.Shape with start/end parameters for more efficient shape extraction. Fixed the typo in the suggestion where both lines assigned to batch_size. Commit: 96f78cd
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use op.Dropout for it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great suggestion! I've refactored the implementation to use op.Dropout instead of manual random generation. The new approach creates a dummy tensor with the appropriate feature dropout shape [N, C, 1, 1, ...], applies op.Dropout to it to get the scaled mask, then multiplies with the input. This is much cleaner and leverages the existing ONNX Dropout operation for all the logic (training mode, scaling, random generation). Commit: 29f1968
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added early return conditions as requested. The function now returns input directly when p == 0 or not train, avoiding unnecessary computations. Commit: af8d622