Spaces:
Build error
Build error
up
Browse files- check.py +5 -2
- optimization.py +11 -13
check.py
CHANGED
|
@@ -50,10 +50,12 @@ optimize_pipeline_(
|
|
| 50 |
pipe,
|
| 51 |
conditions=[condition1],
|
| 52 |
prompt="prompt",
|
|
|
|
| 53 |
height=LANDSCAPE_HEIGHT,
|
| 54 |
width=LANDSCAPE_WIDTH,
|
| 55 |
num_frames=MAX_FRAMES_MODEL,
|
| 56 |
-
num_inference_steps=2
|
|
|
|
| 57 |
)
|
| 58 |
|
| 59 |
default_prompt_i2v = "make this image come alive, cinematic motion, smooth animation"
|
|
@@ -79,4 +81,5 @@ output_frames_list = pipe(
|
|
| 79 |
guidance_scale=float(guidance_scale),
|
| 80 |
num_inference_steps=int(steps),
|
| 81 |
generator=torch.Generator(device="cuda").manual_seed(current_seed),
|
| 82 |
-
).frames[0]
|
|
|
|
|
|
| 50 |
pipe,
|
| 51 |
conditions=[condition1],
|
| 52 |
prompt="prompt",
|
| 53 |
+
negative_prompt="prompt",
|
| 54 |
height=LANDSCAPE_HEIGHT,
|
| 55 |
width=LANDSCAPE_WIDTH,
|
| 56 |
num_frames=MAX_FRAMES_MODEL,
|
| 57 |
+
num_inference_steps=2,
|
| 58 |
+
guidance_scale=1.0,
|
| 59 |
)
|
| 60 |
|
| 61 |
default_prompt_i2v = "make this image come alive, cinematic motion, smooth animation"
|
|
|
|
| 81 |
guidance_scale=float(guidance_scale),
|
| 82 |
num_inference_steps=int(steps),
|
| 83 |
generator=torch.Generator(device="cuda").manual_seed(current_seed),
|
| 84 |
+
).frames[0]
|
| 85 |
+
export_to_video(output_frames_list, "output_original.mp4", fps=24)
|
optimization.py
CHANGED
|
@@ -19,20 +19,17 @@ P = ParamSpec("P")
|
|
| 19 |
|
| 20 |
# Sequence packing in LTX is a bit of a pain.
|
| 21 |
# See: https://github.com/huggingface/diffusers/blob/c052791b5fe29ce8a308bf63dda97aa205b729be/src/diffusers/pipelines/ltx/pipeline_ltx.py#L420
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
# "hidden_states": {1: TRANSFORMER_NUM_FRAMES_DIM},
|
| 27 |
-
# }
|
| 28 |
|
| 29 |
INDUCTOR_CONFIGS = {
|
| 30 |
"conv_1x1_as_mm": True,
|
| 31 |
"epilogue_fusion": False,
|
| 32 |
"coordinate_descent_tuning": True,
|
| 33 |
"coordinate_descent_check_all_directions": True,
|
| 34 |
-
|
| 35 |
-
"max_autotune": False,
|
| 36 |
"triton.cudagraphs": True,
|
| 37 |
}
|
| 38 |
TRANSFORMER_SPATIAL_PATCH_SIZE = 1
|
|
@@ -54,8 +51,8 @@ def optimize_pipeline_(pipeline: Callable[P, Any], *args: P.args, **kwargs: P.kw
|
|
| 54 |
|
| 55 |
@spaces.GPU(duration=1500)
|
| 56 |
def compile_transformer():
|
| 57 |
-
|
| 58 |
-
|
| 59 |
|
| 60 |
quantize_(pipeline.transformer, float8_dynamic_activation_float8_weight())
|
| 61 |
|
|
@@ -87,13 +84,13 @@ def optimize_pipeline_(pipeline: Callable[P, Any], *args: P.args, **kwargs: P.kw
|
|
| 87 |
mod=pipeline.transformer,
|
| 88 |
args=call.args,
|
| 89 |
kwargs=call.kwargs | {"hidden_states": hidden_states_landscape},
|
| 90 |
-
|
| 91 |
)
|
| 92 |
exported_portrait = torch.export.export(
|
| 93 |
mod=pipeline.transformer,
|
| 94 |
args=call.args,
|
| 95 |
kwargs=call.kwargs | {"hidden_states": hidden_states_portrait},
|
| 96 |
-
|
| 97 |
)
|
| 98 |
|
| 99 |
compiled_landscape = aoti_compile(exported_landscape, INDUCTOR_CONFIGS)
|
|
@@ -129,7 +126,8 @@ def optimize_pipeline_(pipeline: Callable[P, Any], *args: P.args, **kwargs: P.kw
|
|
| 129 |
with torch.no_grad():
|
| 130 |
combined_transformer(**call.kwargs)
|
| 131 |
|
| 132 |
-
pipeline.transformer =
|
|
|
|
| 133 |
|
| 134 |
with torch.no_grad():
|
| 135 |
pipeline.transformer(**call.kwargs)
|
|
|
|
| 19 |
|
| 20 |
# Sequence packing in LTX is a bit of a pain.
|
| 21 |
# See: https://github.com/huggingface/diffusers/blob/c052791b5fe29ce8a308bf63dda97aa205b729be/src/diffusers/pipelines/ltx/pipeline_ltx.py#L420
|
| 22 |
+
TRANSFORMER_NUM_FRAMES_DIM = torch.export.Dim.AUTO
|
| 23 |
+
TRANSFORMER_DYNAMIC_SHAPES = {
|
| 24 |
+
"hidden_states": {1: TRANSFORMER_NUM_FRAMES_DIM},
|
| 25 |
+
}
|
|
|
|
|
|
|
| 26 |
|
| 27 |
INDUCTOR_CONFIGS = {
|
| 28 |
"conv_1x1_as_mm": True,
|
| 29 |
"epilogue_fusion": False,
|
| 30 |
"coordinate_descent_tuning": True,
|
| 31 |
"coordinate_descent_check_all_directions": True,
|
| 32 |
+
"max_autotune": False, # doesn't help much
|
|
|
|
| 33 |
"triton.cudagraphs": True,
|
| 34 |
}
|
| 35 |
TRANSFORMER_SPATIAL_PATCH_SIZE = 1
|
|
|
|
| 51 |
|
| 52 |
@spaces.GPU(duration=1500)
|
| 53 |
def compile_transformer():
|
| 54 |
+
dynamic_shapes = tree_map_only((torch.Tensor, bool), lambda t: None, call.kwargs)
|
| 55 |
+
dynamic_shapes |= TRANSFORMER_DYNAMIC_SHAPES
|
| 56 |
|
| 57 |
quantize_(pipeline.transformer, float8_dynamic_activation_float8_weight())
|
| 58 |
|
|
|
|
| 84 |
mod=pipeline.transformer,
|
| 85 |
args=call.args,
|
| 86 |
kwargs=call.kwargs | {"hidden_states": hidden_states_landscape},
|
| 87 |
+
dynamic_shapes=dynamic_shapes,
|
| 88 |
)
|
| 89 |
exported_portrait = torch.export.export(
|
| 90 |
mod=pipeline.transformer,
|
| 91 |
args=call.args,
|
| 92 |
kwargs=call.kwargs | {"hidden_states": hidden_states_portrait},
|
| 93 |
+
dynamic_shapes=dynamic_shapes,
|
| 94 |
)
|
| 95 |
|
| 96 |
compiled_landscape = aoti_compile(exported_landscape, INDUCTOR_CONFIGS)
|
|
|
|
| 126 |
with torch.no_grad():
|
| 127 |
combined_transformer(**call.kwargs)
|
| 128 |
|
| 129 |
+
pipeline.transformer = combined_transformer
|
| 130 |
+
# pipeline.transformer = cudagraph(combined_transformer)
|
| 131 |
|
| 132 |
with torch.no_grad():
|
| 133 |
pipeline.transformer(**call.kwargs)
|