Add PyTorch 2.5+ compatibility patch for _pytree API

The torch.utils._pytree module changed its API in PyTorch 2.5:
- register_pytree_node became _register_pytree_node (or vice versa)
- This breaks audiocraft which uses the old API

Add monkey-patch to alias the function for backwards compatibility.

See: https://stackoverflow.com/questions/78501569

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-11-27 13:38:09 +01:00
parent 0288e32de9
commit 4c602a6c07

11
main.py
View File

@@ -16,6 +16,17 @@ os.chdir(PROJECT_ROOT)
# Add project root to path # Add project root to path
sys.path.insert(0, str(PROJECT_ROOT)) sys.path.insert(0, str(PROJECT_ROOT))
# PyTorch 2.5+ compatibility patch for audiocraft
# The _pytree API changed - add backwards compatibility
try:
import torch.utils._pytree as _pytree
if not hasattr(_pytree, 'register_pytree_node') and hasattr(_pytree, '_register_pytree_node'):
_pytree.register_pytree_node = _pytree._register_pytree_node
elif not hasattr(_pytree, '_register_pytree_node') and hasattr(_pytree, 'register_pytree_node'):
_pytree._register_pytree_node = _pytree.register_pytree_node
except Exception:
pass # Ignore if patch fails
from config.settings import get_settings from config.settings import get_settings
from src.core.gpu_manager import GPUMemoryManager from src.core.gpu_manager import GPUMemoryManager
from src.core.model_registry import ModelRegistry from src.core.model_registry import ModelRegistry