degen69 commited on
Commit
6ca2fca
·
verified ·
1 Parent(s): a073e24

Upload pipeline.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. 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
- # fp8_e4m3fn weights are loaded into bfloat16 compute precision to maximise
103
- # diffusers compatibility; the weight file on disk is fp8-quantised.
104
- transformer = LTX2VideoTransformer3DModel.from_single_file(
105
- paths["transformer"],
106
- torch_dtype=torch.bfloat16,
107
- # Sulphur 2 (22B) was trained with cross-attn adaln enabled, giving
108
- # 9-row (not 6-row) scale_shift tables.
109
- original_config={
110
- "video_cross_attn_adaln": True,
111
- "audio_cross_attn_adaln": True,
112
- },
113
- ).to(device)
 
 
 
 
 
 
 
 
 
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…")