Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -177,6 +177,8 @@ except Exception as e:
|
|
| 177 |
print(f"[PATCH 5] Could not apply key mapping patch: {e}")
|
| 178 |
|
| 179 |
# --- PATCH 7: MATERIALIZE LEFTOVER META TENSORS (unused vision_tower / rotary buffers) ---
|
|
|
|
|
|
|
| 180 |
try:
|
| 181 |
from ltx_pipelines.utils import model_ledger as _ml
|
| 182 |
|
|
@@ -203,18 +205,26 @@ try:
|
|
| 203 |
new_buf = torch.zeros(b.shape, dtype=b.dtype, device=device)
|
| 204 |
parent.register_buffer(leaf, new_buf, persistent=False)
|
| 205 |
|
| 206 |
-
|
| 207 |
def _patched_text_encoder(self):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 208 |
model = self.text_encoder_builder.build(device=self._target_device(), dtype=self.dtype)
|
| 209 |
target_device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 210 |
_materialize_meta_(model, target_device) # fix only the meta leftovers
|
| 211 |
-
|
|
|
|
|
|
|
|
|
|
| 212 |
|
| 213 |
_ml.ModelLedger.text_encoder = _patched_text_encoder
|
| 214 |
print("[PATCH 7] Patched ModelLedger.text_encoder to materialize leftover meta tensors "
|
| 215 |
-
"
|
| 216 |
except Exception as e:
|
| 217 |
-
print(f"[PATCH 7] Could not
|
| 218 |
|
| 219 |
|
| 220 |
logging.getLogger().setLevel(logging.INFO)
|
|
|
|
| 177 |
print(f"[PATCH 5] Could not apply key mapping patch: {e}")
|
| 178 |
|
| 179 |
# --- PATCH 7: MATERIALIZE LEFTOVER META TENSORS (unused vision_tower / rotary buffers) ---
|
| 180 |
+
# Also manually restores the cached_property caching contract that ModelLedger.text_encoder
|
| 181 |
+
# originally had, since replacing the class attribute with a plain function loses it.
|
| 182 |
try:
|
| 183 |
from ltx_pipelines.utils import model_ledger as _ml
|
| 184 |
|
|
|
|
| 205 |
new_buf = torch.zeros(b.shape, dtype=b.dtype, device=device)
|
| 206 |
parent.register_buffer(leaf, new_buf, persistent=False)
|
| 207 |
|
|
|
|
| 208 |
def _patched_text_encoder(self):
|
| 209 |
+
# Manually replicate cached_property behavior: reuse the cached instance
|
| 210 |
+
# from __dict__ if it's already been built, exactly like the original
|
| 211 |
+
# ModelLedger contract documents (cleared only via clear_vram()).
|
| 212 |
+
if "text_encoder" in self.__dict__:
|
| 213 |
+
return self.__dict__["text_encoder"]
|
| 214 |
+
|
| 215 |
model = self.text_encoder_builder.build(device=self._target_device(), dtype=self.dtype)
|
| 216 |
target_device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 217 |
_materialize_meta_(model, target_device) # fix only the meta leftovers
|
| 218 |
+
model = model.to(target_device).eval()
|
| 219 |
+
|
| 220 |
+
self.__dict__["text_encoder"] = model # cache it, same as the original cached_property
|
| 221 |
+
return model
|
| 222 |
|
| 223 |
_ml.ModelLedger.text_encoder = _patched_text_encoder
|
| 224 |
print("[PATCH 7] Patched ModelLedger.text_encoder to materialize leftover meta tensors "
|
| 225 |
+
"AND restore caching (instance __dict__) so it isn't rebuilt on every call.")
|
| 226 |
except Exception as e:
|
| 227 |
+
print(f"[PATCH 7] Could not apply ModelLedger.text_encoder patch: {e}")
|
| 228 |
|
| 229 |
|
| 230 |
logging.getLogger().setLevel(logging.INFO)
|