From 5766870304060175e621073ec9c4e6ac6f445bb8 Mon Sep 17 00:00:00 2001 From: scott Date: Sun, 5 Apr 2026 14:34:45 -0400 Subject: [PATCH] Fix UnboundLocalError: move torch._dynamo import to module level 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 --- engine.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine.py b/engine.py index 557b2c1..e1691f7 100644 --- a/engine.py +++ b/engine.py @@ -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")