Spaces:
Paused
Paused
Fix: make trellis2/__init__.py fully lazy to survive partial-module namespace
Browse filesThe installed TRELLIS.2 wheels (o_voxel/flex_gemm) register a 'trellis2'
namespace in sys.modules before app.py runs, leaving it partially initialized.
The original eager 'from . import models' then fails because 'models' isn't
an attribute yet on the partial stub.
Replace the eager submodule imports with a lazy __getattr__ (the same pattern
used by all trellis2 submodule __init__.py files). All external access patterns
(from trellis2.pipelines import X, trellis2.modules.sparse.SparseTensor) still
work — Python's import machinery resolves absolute submodule paths independently
of the parent package's __init__.
TRELLIS.2/trellis2/__init__.py
CHANGED
|
@@ -1,6 +1,16 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
from
|
| 5 |
-
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import importlib
|
| 2 |
+
|
| 3 |
+
# Lazy-load all submodules to avoid circular-import errors when trellis2 is
|
| 4 |
+
# first imported from an environment where a partial trellis2 namespace already
|
| 5 |
+
# exists in sys.modules (e.g. registered as a dependency by o_voxel/flex_gemm).
|
| 6 |
+
_submodules = frozenset((
|
| 7 |
+
'models', 'modules', 'pipelines',
|
| 8 |
+
'renderers', 'representations', 'utils',
|
| 9 |
+
))
|
| 10 |
+
|
| 11 |
+
def __getattr__(name):
|
| 12 |
+
if name in _submodules:
|
| 13 |
+
module = importlib.import_module(f'.{name}', __name__)
|
| 14 |
+
globals()[name] = module
|
| 15 |
+
return module
|
| 16 |
+
raise AttributeError(f"module 'trellis2' has no attribute {name!r}")
|