Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jun 14, 2025

The aten.embedding_bag.padding_idx function was failing when padding_idx is None, which is a valid value in PyTorch indicating that no padding index should be ignored. This was causing DLRM model exports to fail with the error:

padding_idx must not be None. This is likely a dispatcher error

Changes Made

  1. Updated function signature: Changed padding_idx: int = -1 to padding_idx: Optional[int] = None
  2. Removed problematic assertion: Eliminated the assertion that was throwing the error when padding_idx is None
  3. Added conditional logic:
    • When padding_idx is None: delegate to _aten_embedding_bag_onnx() (regular embedding_bag without padding filtering)
    • When padding_idx is not None: use existing _aten_embedding_bag_1d_padding_idx_onnx() implementation

Behavior

# This now works correctly (previously threw assertion error)
result = aten_embedding_bag_padding_idx(
    weight, indices, offsets, 
    padding_idx=None  # No padding index to ignore
)

# This continues to work as before
result = aten_embedding_bag_padding_idx(
    weight, indices, offsets, 
    padding_idx=2  # Filter out index 2
)

The fix maintains full backward compatibility while correctly handling the None case as expected by PyTorch's behavior.

Fixes #2219.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: justinchuby <11205048+justinchuby@users.noreply.github.com>
Copilot AI changed the title [WIP] [torchlib] Implement aten.embedding_bag.padding_idx [torchlib] Fix aten.embedding_bag.padding_idx to support None values Jun 14, 2025
Copilot AI requested a review from justinchuby June 14, 2025 15:43
@justinchuby justinchuby marked this pull request as ready for review June 14, 2025 16:05
@codecov
Copy link

codecov bot commented Jun 14, 2025

Codecov Report

❌ Patch coverage is 60.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.36%. Comparing base (b76e1b3) to head (a69a674).
⚠️ Report is 243 commits behind head on main.

Files with missing lines Patch % Lines
onnxscript/function_libs/torch_lib/ops/core.py 60.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2384      +/-   ##
==========================================
- Coverage   70.37%   70.36%   -0.01%     
==========================================
  Files         199      199              
  Lines       25206    25207       +1     
  Branches     2685     2686       +1     
==========================================
- Hits        17739    17738       -1     
- Misses       6537     6538       +1     
- Partials      930      931       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

[torchlib] Implement aten.embedding_bag.padding_idx

2 participants