Upload pipeline.py with huggingface_hub
Browse files- pipeline.py +21 -12
pipeline.py
CHANGED
|
@@ -99,18 +99,27 @@ def load_pipeline(
|
|
| 99 |
|
| 100 |
if progress_cb:
|
| 101 |
progress_cb("Loading transformer…")
|
| 102 |
-
#
|
| 103 |
-
#
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
|
| 115 |
if progress_cb:
|
| 116 |
progress_cb("Loading video VAE…")
|
|
|
|
| 99 |
|
| 100 |
if progress_cb:
|
| 101 |
progress_cb("Loading transformer…")
|
| 102 |
+
# Sulphur 2 (22B) was trained with cross-attn modulation enabled.
|
| 103 |
+
# `from_single_file` can't infer this, so construct the model with the
|
| 104 |
+
# right config first, then load the converted state dict.
|
| 105 |
+
from diffusers.loaders.single_file_utils import (
|
| 106 |
+
convert_ltx_transformer_checkpoint_to_diffusers,
|
| 107 |
+
)
|
| 108 |
+
from safetensors import safe_open
|
| 109 |
+
|
| 110 |
+
transformer = LTX2VideoTransformer3DModel(
|
| 111 |
+
cross_attn_mod=True,
|
| 112 |
+
audio_cross_attn_mod=True,
|
| 113 |
+
)
|
| 114 |
+
with safe_open(paths["transformer"], framework="pt") as f:
|
| 115 |
+
# FP8 weights -> BF16 for diffusers compatibility
|
| 116 |
+
checkpoint = {k: f.get_slice(k)[:].to(torch.bfloat16) for k in f.keys()}
|
| 117 |
+
converted = convert_ltx_transformer_checkpoint_to_diffusers(checkpoint)
|
| 118 |
+
# Filter to keys that exist in the model (drops any extras)
|
| 119 |
+
model_keys = set(transformer.state_dict().keys())
|
| 120 |
+
filtered = {k: v for k, v in converted.items() if k in model_keys}
|
| 121 |
+
transformer.load_state_dict(filtered, strict=False)
|
| 122 |
+
transformer = transformer.to(torch.bfloat16).to(device)
|
| 123 |
|
| 124 |
if progress_cb:
|
| 125 |
progress_cb("Loading video VAE…")
|