Fix PyTorch 2.7+ and ROCm/AMD GPU Compatibility #67
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)