Skip to content

fix the path change in torch v2.10 for spec dec#863

Merged
yeyu-nvidia merged 9 commits intomainfrom
yeyu/fix_bug_5875785
Feb 9, 2026
Merged

fix the path change in torch v2.10 for spec dec#863
yeyu-nvidia merged 9 commits intomainfrom
yeyu/fix_bug_5875785

Conversation

@yeyu-nvidia
Copy link
Copy Markdown
Contributor

@yeyu-nvidia yeyu-nvidia commented Feb 6, 2026

What does this PR do?

Type of change:
bug fix

Overview:
torch v2.10 changes the path for _SDPAMerger. will need to use the new path for import

Usage

# Add a code snippet demonstrating how to use this

Testing

Before your PR is "Ready for review"

  • Make sure you read and follow Contributor guidelines and your commits are signed.
  • Is this change backward compatible?: Yes/No
  • Did you write any new necessary tests?: Yes/No
  • Did you add or update any necessary documentation?: Yes/No
  • Did you update Changelog?: Yes/No

Additional Information

Summary by CodeRabbit

  • Chores
    • Updated internal import references to reflect organizational changes in dependencies.

Signed-off-by: Ye Yu <yeyu@nvidia.com>
@yeyu-nvidia yeyu-nvidia requested a review from a team as a code owner February 6, 2026 18:24
@yeyu-nvidia yeyu-nvidia requested a review from h-guo18 February 6, 2026 18:24
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Feb 6, 2026

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

A single import path update for the _SDPAMerger class in the eagle utilities module reflects a reorganization of torch's distributed tensor experimental modules, moving it under a new _context_parallel submodule.

Changes

Cohort / File(s) Summary
Import Path Update
examples/speculative_decoding/eagle_utils.py
Updated _SDPAMerger import from torch.distributed.tensor.experimental._attention to torch.distributed.tensor.experimental._context_parallel._attention due to module reorganization.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title 'fix the path change in torch v2.10 for spec dec' accurately summarizes the main change: updating an import path for speculative decoding due to torch v2.10 changes.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch yeyu/fix_bug_5875785

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
examples/speculative_decoding/eagle_utils.py (1)

681-689: ⚠️ Potential issue | 🔴 Critical

Version gate rejects torch v2.10, making the import fix unreachable.

The version check restricts patch_ring_attention_for_ttt() to torch 2.8.x only (> 2.7.1 and < 2.9.0). When running on torch v2.10 (the version this PR targets), this raises a RuntimeError before reaching line 710 where _SDPAMerger is used. If the intent is to also support torch v2.10, this version range needs to be expanded.

     if not (
         Version(torch.__version__) > Version("2.7.1")
-        and Version(torch.__version__) < Version("2.9.0")
+        and Version(torch.__version__) < Version("2.11.0")
     ):

The error message on lines 686–688 should also be updated to reflect the newly supported version range.

🤖 Fix all issues with AI agents
In `@examples/speculative_decoding/eagle_utils.py`:
- Line 34: The module currently does an unconditional top-level import of
_SDPAMerger from
torch.distributed.tensor.experimental._context_parallel._attention which raises
ImportError on torch < 2.10; instead gate the import by checking
torch.__version__ (using packaging.version.Version already imported) or wrap in
try/except ImportError and fall back to the older path
torch.distributed.tensor.experimental._attention._SDPAMerger, assigning the
available class to the same symbol name _SDPAMerger so downstream code using
_SDPAMerger continues to work.

from PIL import Image
from scripts.ar_validate import validate_ar
from torch.distributed.tensor.experimental._attention import _SDPAMerger
from torch.distributed.tensor.experimental._context_parallel._attention import _SDPAMerger
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Unconditional import breaks backward compatibility with torch < 2.10.

This top-level import executes at module load time. For torch versions before 2.10, torch.distributed.tensor.experimental._context_parallel._attention likely doesn't exist, so this will raise an ImportError and prevent the entire module from loading. Since the old path was torch.distributed.tensor.experimental._attention._SDPAMerger, you need a version-gated or fallback import.

Proposed fix: conditional import
-from torch.distributed.tensor.experimental._context_parallel._attention import _SDPAMerger
+from packaging.version import Version as _Version
+
+if _Version(torch.__version__) >= _Version("2.10.0"):
+    from torch.distributed.tensor.experimental._context_parallel._attention import _SDPAMerger
+else:
+    from torch.distributed.tensor.experimental._attention import _SDPAMerger

Note: torch is already imported on line 28, and packaging.version.Version is imported on line 31, but the torch import must appear before this conditional. Alternatively, use a try/except ImportError fallback:

-from torch.distributed.tensor.experimental._context_parallel._attention import _SDPAMerger
+try:
+    from torch.distributed.tensor.experimental._context_parallel._attention import _SDPAMerger
+except ImportError:
+    from torch.distributed.tensor.experimental._attention import _SDPAMerger
🤖 Prompt for AI Agents
In `@examples/speculative_decoding/eagle_utils.py` at line 34, The module
currently does an unconditional top-level import of _SDPAMerger from
torch.distributed.tensor.experimental._context_parallel._attention which raises
ImportError on torch < 2.10; instead gate the import by checking
torch.__version__ (using packaging.version.Version already imported) or wrap in
try/except ImportError and fall back to the older path
torch.distributed.tensor.experimental._attention._SDPAMerger, assigning the
available class to the same symbol name _SDPAMerger so downstream code using
_SDPAMerger continues to work.

@codecov
Copy link
Copy Markdown

codecov bot commented Feb 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 73.44%. Comparing base (24e3587) to head (e9ec9ee).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #863   +/-   ##
=======================================
  Coverage   73.44%   73.44%           
=======================================
  Files         197      197           
  Lines       20657    20657           
=======================================
  Hits        15172    15172           
  Misses       5485     5485           

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@h-guo18
Copy link
Copy Markdown
Contributor

h-guo18 commented Feb 6, 2026

Current CP patch depend on exactly torch2.8.0 and will raise error if torch version doesn't match:https://github.com/NVIDIA/Model-Optimizer/blob/main/examples/speculative_decoding/eagle_utils.py#L685

If there's an import error, I think it's better to add a try-except logic, such that: cp=1 work on all torch version, and cp>1 raise error with torch!=2.8

@yeyu-nvidia
Copy link
Copy Markdown
Contributor Author

Current CP patch depend on exactly torch2.8.0 and will raise error if torch version doesn't match:https://github.com/NVIDIA/Model-Optimizer/blob/main/examples/speculative_decoding/eagle_utils.py#L685

If there's an import error, I think it's better to add a try-except logic, such that: cp=1 work on all torch version, and cp>2 raise error with torch!=2.8

Does CP patch not work for torch.2.10.0? Forcing user to torch2.8.0 is not a good idea and may not be maintainable.

@yeyu-nvidia
Copy link
Copy Markdown
Contributor Author

I see this function needs to adapt to torch.2.10 https://github.com/NVIDIA/Model-Optimizer/blob/main/examples/speculative_decoding/eagle_utils.py#L677. Is there anything else blocking?

Signed-off-by: Ye Yu <yeyu@nvidia.com>
Signed-off-by: Ye Yu <yeyu@nvidia.com>
Signed-off-by: Ye Yu <yeyu@nvidia.com>
from PIL import Image
from scripts.ar_validate import validate_ar
from torch.distributed.tensor.experimental._attention import _SDPAMerger
from torch.distributed.tensor.experimental._context_parallel._attention import _SDPAMerger
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We can remove this import for torch<2.10 compatibility

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Instead of _SDPAMerger, we can use _attention._SDPAMerger here after version check for torch<2.10 compatibility

Signed-off-by: Ye Yu <yeyu@nvidia.com>
Signed-off-by: Ye Yu <yeyu@nvidia.com>
Signed-off-by: Ye Yu <yeyu@nvidia.com>
@h-guo18
Copy link
Copy Markdown
Contributor

h-guo18 commented Feb 6, 2026

Could you also update the test container version to 2.10 for test coverage on cp=2

##### Speculative Decoding Example Tests (requires 25.08 image) #####
speculative-decoding-pr:
needs: [check-file-changes, wait-checks]
if: startsWith(github.ref, 'refs/heads/pull-request/') && needs.check-file-changes.outputs.any_changed == 'true'
uses: ./.github/workflows/_example_tests_runner.yml
secrets: inherit
with:
docker_image: "nvcr.io/nvidia/pytorch:25.08-py3"
example: speculative_decoding
pip_install_extras: "[hf,dev-test]"
runner: linux-amd64-gpu-l4-latest-1
speculative-decoding-non-pr:
if: ${{ !startsWith(github.ref, 'refs/heads/pull-request/') }}
uses: ./.github/workflows/_example_tests_runner.yml
secrets: inherit
with:
docker_image: "nvcr.io/nvidia/pytorch:25.08-py3"
example: speculative_decoding
pip_install_extras: "[hf,dev-test]"
runner: linux-amd64-gpu-h100-latest-2

Signed-off-by: Ye Yu <yeyu@nvidia.com>
@yeyu-nvidia yeyu-nvidia requested a review from a team as a code owner February 6, 2026 22:36
@kevalmorabia97 kevalmorabia97 changed the title fix the path change in torch v2.10 fix the path change in torch v2.10 for spec dec Feb 6, 2026
@yeyu-nvidia yeyu-nvidia enabled auto-merge (squash) February 9, 2026 17:10
@yeyu-nvidia yeyu-nvidia merged commit a8f5314 into main Feb 9, 2026
46 of 52 checks passed
@yeyu-nvidia yeyu-nvidia deleted the yeyu/fix_bug_5875785 branch February 9, 2026 17:56
danielkorzekwa pushed a commit that referenced this pull request Feb 17, 2026
**Type of change:**
bug fix

**Overview:**
torch v2.10 changes the path for _SDPAMerger. will need to use the new
path for import

<!-- You can potentially add a usage example below. -->

```python
```

<!-- Mention how have you tested your change if applicable. -->

<!-- If you haven't finished some of the above items you can still open
`Draft` PR. -->

- **Make sure you read and follow [Contributor
guidelines](https://github.com/NVIDIA/Model-Optimizer/blob/main/CONTRIBUTING.md)**
and your commits are signed.
- **Is this change backward compatible?**: Yes/No <!--- If No, explain
why. -->
- **Did you write any new necessary tests?**: Yes/No
- **Did you add or update any necessary documentation?**: Yes/No
- **Did you update
[Changelog](https://github.com/NVIDIA/Model-Optimizer/blob/main/CHANGELOG.rst)?**:
Yes/No <!--- Only for new features, API changes, critical bug fixes or
bw breaking changes. -->

<!-- E.g. related issue. -->

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

* **Chores**
* Updated internal import references to reflect organizational changes
in dependencies.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: Ye Yu <yeyu@nvidia.com>
sugunav14 pushed a commit that referenced this pull request Feb 17, 2026
## What does this PR do?

**Type of change:** 
bug fix

**Overview:** 
torch v2.10 changes the path for _SDPAMerger. will need to use the new
path for import

## Usage
<!-- You can potentially add a usage example below. -->

```python
# Add a code snippet demonstrating how to use this
```

## Testing
<!-- Mention how have you tested your change if applicable. -->

## Before your PR is "*Ready for review*"
<!-- If you haven't finished some of the above items you can still open
`Draft` PR. -->

- **Make sure you read and follow [Contributor
guidelines](https://github.com/NVIDIA/Model-Optimizer/blob/main/CONTRIBUTING.md)**
and your commits are signed.
- **Is this change backward compatible?**: Yes/No <!--- If No, explain
why. -->
- **Did you write any new necessary tests?**: Yes/No
- **Did you add or update any necessary documentation?**: Yes/No
- **Did you update
[Changelog](https://github.com/NVIDIA/Model-Optimizer/blob/main/CHANGELOG.rst)?**:
Yes/No <!--- Only for new features, API changes, critical bug fixes or
bw breaking changes. -->

## Additional Information
<!-- E.g. related issue. -->


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Chores**
* Updated internal import references to reflect organizational changes
in dependencies.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: Ye Yu <yeyu@nvidia.com>
kevalmorabia97 pushed a commit that referenced this pull request Feb 20, 2026
## What does this PR do?

**Type of change:** 
bug fix

**Overview:** 
torch v2.10 changes the path for _SDPAMerger. will need to use the new
path for import

## Usage
<!-- You can potentially add a usage example below. -->

```python
# Add a code snippet demonstrating how to use this
```

## Testing
<!-- Mention how have you tested your change if applicable. -->

## Before your PR is "*Ready for review*"
<!-- If you haven't finished some of the above items you can still open
`Draft` PR. -->

- **Make sure you read and follow [Contributor
guidelines](https://github.com/NVIDIA/Model-Optimizer/blob/main/CONTRIBUTING.md)**
and your commits are signed.
- **Is this change backward compatible?**: Yes/No <!--- If No, explain
why. -->
- **Did you write any new necessary tests?**: Yes/No
- **Did you add or update any necessary documentation?**: Yes/No
- **Did you update
[Changelog](https://github.com/NVIDIA/Model-Optimizer/blob/main/CHANGELOG.rst)?**:
Yes/No <!--- Only for new features, API changes, critical bug fixes or
bw breaking changes. -->

## Additional Information
<!-- E.g. related issue. -->


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Chores**
* Updated internal import references to reflect organizational changes
in dependencies.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: Ye Yu <yeyu@nvidia.com>
danielkorzekwa pushed a commit that referenced this pull request Mar 4, 2026
## What does this PR do?

**Type of change:**
bug fix

**Overview:**
torch v2.10 changes the path for _SDPAMerger. will need to use the new
path for import

## Usage
<!-- You can potentially add a usage example below. -->

```python
# Add a code snippet demonstrating how to use this
```

## Testing
<!-- Mention how have you tested your change if applicable. -->

## Before your PR is "*Ready for review*"
<!-- If you haven't finished some of the above items you can still open
`Draft` PR. -->

- **Make sure you read and follow [Contributor
guidelines](https://github.com/NVIDIA/Model-Optimizer/blob/main/CONTRIBUTING.md)**
and your commits are signed.
- **Is this change backward compatible?**: Yes/No <!--- If No, explain
why. -->
- **Did you write any new necessary tests?**: Yes/No
- **Did you add or update any necessary documentation?**: Yes/No
- **Did you update
[Changelog](https://github.com/NVIDIA/Model-Optimizer/blob/main/CHANGELOG.rst)?**:
Yes/No <!--- Only for new features, API changes, critical bug fixes or
bw breaking changes. -->

## Additional Information
<!-- E.g. related issue. -->

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Chores**
* Updated internal import references to reflect organizational changes
in dependencies.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: Ye Yu <yeyu@nvidia.com>
Signed-off-by: Daniel Korzekwa <dkorzekwa@nvidia.com>
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.

3 participants