Skip to content

Fix backward_adagrad unit test#5397

Closed
spcyppt wants to merge 1 commit into
pytorch:mainfrom
spcyppt:export-D92668399
Closed

Fix backward_adagrad unit test#5397
spcyppt wants to merge 1 commit into
pytorch:mainfrom
spcyppt:export-D92668399

Conversation

@spcyppt

@spcyppt spcyppt commented Feb 10, 2026

Copy link
Copy Markdown
Contributor

Summary:
X-link: https://github.com/facebookresearch/FBGEMM/pull/2372

Three fixes to the backward_adagrad test:

  1. Fix bs_features construction: The previous logic for building bs_features from feature_table_map was incorrect when tables were replicated across multiple features. It used manual insertion logic that was fragile and produced wrong mappings. Replaced with a direct list comprehension [bs[t] for t in feature_table_map] which correctly maps each feature to its corresponding table's embedding module.

  2. Fix OOM in gradcheck: When tbe_op is provided, the test was proceeding into torch gradcheck which allocates significant additional GPU memory, causing OOM. Added an early return when tbe_op is set, and explicitly freed large tensors (bs, bs_features, fs, gos, cc, etc.) before gradcheck to reduce GPU memory pressure.

  3. Add TBE_CONFIG_INDEX env var: Added support for a TBE_CONFIG_INDEX environment variable to select a single TBE config to test, allowing targeted debugging of individual configurations without running all configs.

  4. Fix T_ calculation: Changed T_ = len(xws) to T_ = num_features for the feature_requires_grad tensor size, since its length should match the number of features, not the number of input tensors.

Differential Revision: D92668399

@meta-codesync

meta-codesync Bot commented Feb 10, 2026

Copy link
Copy Markdown
Contributor

@spcyppt has exported this pull request. If you are a Meta employee, you can view the originating Diff in D92668399.

Summary:
Three fixes to the backward_adagrad test:

1. **Fix bs_features construction**: The previous logic for building `bs_features` from `feature_table_map` was incorrect when tables were replicated across multiple features. It used manual insertion logic that was fragile and produced wrong mappings. Replaced with a direct list comprehension `[bs[t] for t in feature_table_map]` which correctly maps each feature to its corresponding table's embedding module.

2. **Fix OOM in gradcheck**: When `tbe_op` is provided, the test was proceeding into torch gradcheck which allocates significant additional GPU memory, causing OOM. Added an early return when `tbe_op` is set, and explicitly freed large tensors (`bs`, `bs_features`, `fs`, `gos`, `cc`, etc.) before gradcheck to reduce GPU memory pressure.

3. **Add TBE_CONFIG_INDEX env var**: Added support for a `TBE_CONFIG_INDEX` environment variable to select a single TBE config to test, allowing targeted debugging of individual configurations without running all configs.

4. **Fix T_ calculation**: Changed `T_ = len(xws)` to `T_ = num_features` for the `feature_requires_grad` tensor size, since its length should match the number of features, not the number of input tensors.

Reviewed By: q10

Differential Revision: D92668399
@meta-codesync

meta-codesync Bot commented Feb 10, 2026

Copy link
Copy Markdown
Contributor

This pull request has been merged in d49fc97.

zpao pushed a commit that referenced this pull request Feb 28, 2026
Summary:
X-link: https://github.com/facebookresearch/FBGEMM/pull/2372

Pull Request resolved: #5397

Three fixes to the backward_adagrad test:

1. **Fix bs_features construction**: The previous logic for building `bs_features` from `feature_table_map` was incorrect when tables were replicated across multiple features. It used manual insertion logic that was fragile and produced wrong mappings. Replaced with a direct list comprehension `[bs[t] for t in feature_table_map]` which correctly maps each feature to its corresponding table's embedding module.

2. **Fix OOM in gradcheck**: When `tbe_op` is provided, the test was proceeding into torch gradcheck which allocates significant additional GPU memory, causing OOM. Added an early return when `tbe_op` is set, and explicitly freed large tensors (`bs`, `bs_features`, `fs`, `gos`, `cc`, etc.) before gradcheck to reduce GPU memory pressure.

3. **Add TBE_CONFIG_INDEX env var**: Added support for a `TBE_CONFIG_INDEX` environment variable to select a single TBE config to test, allowing targeted debugging of individual configurations without running all configs.

4. **Fix T_ calculation**: Changed `T_ = len(xws)` to `T_ = num_features` for the `feature_requires_grad` tensor size, since its length should match the number of features, not the number of input tensors.

Reviewed By: q10

Differential Revision: D92668399

fbshipit-source-id: 0956adf01c2291fcba7b05fe39b70f669a408156
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants