Spaces:
Running
on
Zero
Running
on
Zero
move lora loading into optim code to work on CUDA memory
#2
by
linoyts
HF Staff
- opened
- app.py +16 -16
- optimization.py +17 -0
app.py
CHANGED
|
@@ -57,22 +57,22 @@ pipe = WanImageToVideoPipeline.from_pretrained(MODEL_ID,
|
|
| 57 |
# pipe.unload_lora_weights()
|
| 58 |
|
| 59 |
|
| 60 |
-
pipe.load_lora_weights(
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
)
|
| 65 |
-
kwargs = {}
|
| 66 |
-
kwargs["load_into_transformer_2"] = True
|
| 67 |
-
pipe.load_lora_weights(
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
)
|
| 72 |
-
pipe.set_adapters(["phantom", "phantom_2"], adapter_weights=[1., 1.])
|
| 73 |
-
pipe.fuse_lora(adapter_names=["phantom"], lora_scale=3., components=["transformer"])
|
| 74 |
-
pipe.fuse_lora(adapter_names=["phantom_2"], lora_scale=1., components=["transformer_2"])
|
| 75 |
-
pipe.unload_lora_weights()
|
| 76 |
|
| 77 |
for i in range(3):
|
| 78 |
gc.collect()
|
|
|
|
| 57 |
# pipe.unload_lora_weights()
|
| 58 |
|
| 59 |
|
| 60 |
+
# pipe.load_lora_weights(
|
| 61 |
+
# "vrgamedevgirl84/Wan14BT2VFusioniX",
|
| 62 |
+
# weight_name="FusionX_LoRa/Phantom_Wan_14B_FusionX_LoRA.safetensors",
|
| 63 |
+
# adapter_name="phantom"
|
| 64 |
+
# )
|
| 65 |
+
# kwargs = {}
|
| 66 |
+
# kwargs["load_into_transformer_2"] = True
|
| 67 |
+
# pipe.load_lora_weights(
|
| 68 |
+
# "vrgamedevgirl84/Wan14BT2VFusioniX",
|
| 69 |
+
# weight_name="FusionX_LoRa/Phantom_Wan_14B_FusionX_LoRA.safetensors",
|
| 70 |
+
# adapter_name="phantom_2", **kwargs
|
| 71 |
+
# )
|
| 72 |
+
# pipe.set_adapters(["phantom", "phantom_2"], adapter_weights=[1., 1.])
|
| 73 |
+
# pipe.fuse_lora(adapter_names=["phantom"], lora_scale=3., components=["transformer"])
|
| 74 |
+
# pipe.fuse_lora(adapter_names=["phantom_2"], lora_scale=1., components=["transformer_2"])
|
| 75 |
+
# pipe.unload_lora_weights()
|
| 76 |
|
| 77 |
for i in range(3):
|
| 78 |
gc.collect()
|
optimization.py
CHANGED
|
@@ -43,6 +43,23 @@ def optimize_pipeline_(pipeline: Callable[P, Any], *args: P.args, **kwargs: P.kw
|
|
| 43 |
@spaces.GPU(duration=1500)
|
| 44 |
def compile_transformer():
|
| 45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
with capture_component_call(pipeline, 'transformer') as call:
|
| 47 |
pipeline(*args, **kwargs)
|
| 48 |
|
|
|
|
| 43 |
@spaces.GPU(duration=1500)
|
| 44 |
def compile_transformer():
|
| 45 |
|
| 46 |
+
pipeline.load_lora_weights(
|
| 47 |
+
"vrgamedevgirl84/Wan14BT2VFusioniX",
|
| 48 |
+
weight_name="FusionX_LoRa/Phantom_Wan_14B_FusionX_LoRA.safetensors",
|
| 49 |
+
adapter_name="phantom"
|
| 50 |
+
)
|
| 51 |
+
kwargs = {}
|
| 52 |
+
kwargs["load_into_transformer_2"] = True
|
| 53 |
+
pipeline.load_lora_weights(
|
| 54 |
+
"vrgamedevgirl84/Wan14BT2VFusioniX",
|
| 55 |
+
weight_name="FusionX_LoRa/Phantom_Wan_14B_FusionX_LoRA.safetensors",
|
| 56 |
+
adapter_name="phantom_2", **kwargs
|
| 57 |
+
)
|
| 58 |
+
pipeline.set_adapters(["phantom", "phantom_2"], adapter_weights=[1., 1.])
|
| 59 |
+
pipeline.fuse_lora(adapter_names=["phantom"], lora_scale=3., components=["transformer"])
|
| 60 |
+
pipeline.fuse_lora(adapter_names=["phantom_2"], lora_scale=1., components=["transformer_2"])
|
| 61 |
+
pipeline.unload_lora_weights()
|
| 62 |
+
|
| 63 |
with capture_component_call(pipeline, 'transformer') as call:
|
| 64 |
pipeline(*args, **kwargs)
|
| 65 |
|