Problem: PyTorch 2.7.0+rocm6.3 changed the default weights_only parameter to True, blocking YOLO model loading due to getattr function restriction.
Error:
WeightsUnpickler error: Unsupported global: GLOBAL getattr was not an allowed global by default
Solution: Added getattr to PyTorch safe globals during module initialization in subcore.py:
# Add getattr to safe globals for PyTorch 2.6+ compatibility
if hasattr(torch.serialization, 'add_safe_globals'):
torch.serialization.add_safe_globals([getattr])
logging.info("[Impact Pack/Subpack] Added getattr to PyTorch safe globals for YOLO model compatibility")Enhancement: Added automatic ROCm/CUDA device detection for inference functions.
Changes:
inference_bbox(): Auto-detects and uses CUDA/ROCm when availableinference_segm(): Auto-detects and uses CUDA/ROCm when available
# If device is empty and CUDA/ROCm is available, use it
if not device and torch.cuda.is_available():
device = "cuda"python3 -c "
from modules import subcore
model = subcore.load_yolo('/path/to/model.pt')
print('Model loaded successfully!')
"python3 -c "
import torch
print(f'PyTorch: {torch.__version__}')
print(f'CUDA/ROCm available: {torch.cuda.is_available()}')
print(f'Device: {torch.cuda.get_device_name() if torch.cuda.is_available() else \"CPU\"}')
"- OS: Linux
- Python: 3.12.3
- PyTorch: 2.7.0+rocm6.3
- GPU: AMD Radeon RX 7900 XTX
- ComfyUI: 0.3.44
/modules/subcore.py:- Added
getattrto safe globals during initialization - Enhanced device auto-detection in inference functions
- Added
✅ All YOLO models load successfully
✅ ROCm device detection working
✅ No security warnings
✅ Backward compatibility maintained
- The fix maintains PyTorch's security features while allowing trusted YOLO models
- ROCm is treated as CUDA in PyTorch, so
device="cuda"works for both - No changes needed to existing workflows or user code