Conversation
Co-authored-by: justinchuby <11205048+justinchuby@users.noreply.github.com>
| random_vals = op.RandomUniformLike( | ||
| op.ConstantOfShape(mask_shape, value=0.0), | ||
| dtype=1, # float32 | ||
| low=0.0, | ||
| high=1.0 | ||
| ) |
There was a problem hiding this comment.
Use op.Dropout for it?
There was a problem hiding this comment.
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
|
|
||
| # 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) |
There was a problem hiding this comment.
Do
if p == 0 or not train:
return input
# Do this other thing
There was a problem hiding this comment.
Added early return conditions as requested. The function now returns input directly when p == 0 or not train, avoiding unnecessary computations. Commit: af8d622
…ation Co-authored-by: justinchuby <11205048+justinchuby@users.noreply.github.com>
Co-authored-by: justinchuby <11205048+justinchuby@users.noreply.github.com>
| batch_size = op.Gather(input_shape, [0]) | ||
| channel_size = op.Gather(input_shape, [1]) |
There was a problem hiding this comment.
| 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.
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
…stead of op.Gather Co-authored-by: justinchuby <11205048+justinchuby@users.noreply.github.com>
This PR implements the missing
aten::feature_dropoutoperation inonnxscript/function_libs/torch_lib/ops/core.py.What is feature dropout?
Feature dropout (also known as channel dropout or spatial dropout) is a regularization technique that differs from regular dropout by dropping entire feature maps/channels rather than individual elements:
ppThis is particularly useful in convolutional neural networks as it encourages the network not to rely too heavily on specific feature detectors while maintaining spatial correlations within each feature map.
Implementation Details
The implementation:
@torch_op("aten::feature_dropout", trace_only=True)[N, C]: creates mask of shape[N, C][N, C, H, W, ...]: creates mask of shape[N, C, 1, 1, ...]for broadcastingtrain=False): returns input unchangedp=0): returns input unchanged1/(1-p)Key ONNX Operations Used
RandomUniformLikefor generating random valuesWherefor conditional logicConstantOfShapefor creating appropriately shaped tensorsShape,Size,Gather,Concatfor dynamic shape handlingValidation
torch.ops.aten.feature_dropoutreference implementationFixes #2403.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.