Fix PyTorch 2.7+ and ROCm/AMD GPU Compatibility#67
Open
AKharytonchyk wants to merge 2 commits into
Open
Conversation
- Add getattr to PyTorch safe globals for PyTorch 2.6+ compatibility Fixes 'GLOBAL getattr was not an allowed global' error when loading YOLO models - Add automatic CUDA/ROCm device detection in inference functions Improves performance on AMD GPUs with ROCm support - Add comprehensive documentation and test script Resolves model loading issues on PyTorch 2.7.0+rocm6.3 with AMD Radeon GPUs Tested on AMD RX 7900 XTX with Python 3.12.3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request: Fix PyTorch 2.7+ and ROCm/AMD GPU Compatibility
Summary
This PR fixes critical compatibility issues with PyTorch 2.7+ and adds enhanced support for ROCm/AMD GPUs in ComfyUI Impact Subpack.
Problem Statement
When using PyTorch 2.7.0+rocm6.3 with AMD GPUs, the UltralyticsDetectorProvider node fails to load YOLO models with the following error:
Root Cause
PyTorch 2.6+ introduced enhanced security features where
weights_only=Truebecame the default fortorch.load(). YOLO models require thegetattrbuiltin function during deserialization, which is blocked by default for security reasons.Solution
1. PyTorch 2.7+ Compatibility Fix
getattrto PyTorch safe globals during module initializationtorch.serialization.add_safe_globals([getattr])as recommended by PyTorch documentation2. ROCm/AMD GPU Auto-Detection
inference_bbox()andinference_segm()functions with automatic device detection3. Comprehensive Documentation and Testing
ROCM_FIXES.mdwith detailed fix documentationtest_rocm_compatibility.pyfor validationCode Changes
modules/subcore.pyTesting Environment
Test Results
✅ All YOLO models (bbox and segm) load successfully
✅ ROCm device detection working correctly
✅ No security warnings or errors
✅ Backward compatibility maintained
✅ Performance improved on AMD GPUs
Impact
Related Issues
This addresses the PyTorch 2.6+ security changes and ROCm compatibility issues reported by users upgrading to newer PyTorch versions with AMD GPUs.
Breaking Changes
None. All changes are backward compatible and only activate when:
Files Modified
modules/subcore.py- Core compatibility fixesROCM_FIXES.md- Documentation (new)test_rocm_compatibility.py- Test script (new)