Fix UnboundLocalError: move torch._dynamo import to module level
All checks were successful
Build ROCm Image / build (push) Successful in 2m39s

import inside a function creates a local binding that shadows the
module-level torch import, breaking all earlier torch references in
the same function scope.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-05 14:34:45 -04:00
parent 7babd0584e
commit 5766870304

View File

@@ -1,6 +1,7 @@
import logging
import time
import torch
import torch._dynamo
from typing import Optional, Tuple
logger = logging.getLogger(__name__)
@@ -52,7 +53,6 @@ def load_model() -> bool:
# s3gen (HiFiGAN vocoder + flow matching) since that's the bottleneck.
# suppress_errors=True falls back to eager for any op compile can't handle.
try:
import torch._dynamo
torch._dynamo.config.suppress_errors = True
chatterbox_model.s3gen = torch.compile(chatterbox_model.s3gen, dynamic=True)
logger.info("s3gen compiled with torch.compile")