fix the path change in torch v2.10 for spec dec#863
Conversation
Signed-off-by: Ye Yu <yeyu@nvidia.com>
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughA single import path update for the Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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 | 🔴 CriticalVersion 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.1and< 2.9.0). When running on torch v2.10 (the version this PR targets), this raises aRuntimeErrorbefore reaching line 710 where_SDPAMergeris 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 |
There was a problem hiding this comment.
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 _SDPAMergerNote: 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 Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
|
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 |
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. |
|
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 |
There was a problem hiding this comment.
We can remove this import for torch<2.10 compatibility
There was a problem hiding this comment.
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>
|
Could you also update the test container version to 2.10 for test coverage on cp=2 Model-Optimizer/.github/workflows/example_tests.yml Lines 89 to 109 in ac30686 |
Signed-off-by: Ye Yu <yeyu@nvidia.com>
**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>
## 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>
## 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>
## 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>
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 thisTesting
Before your PR is "Ready for review"
Additional Information
Summary by CodeRabbit