Skip to content

Commit 07ac70d

Browse files
committed
Enhance SkyReels-V2 documentation: update model loading for GPU support and remove outdated notes
1 parent a7e7b2f commit 07ac70d

File tree

1 file changed

+22
-56
lines changed

1 file changed

+22
-56
lines changed

docs/source/en/api/pipelines/skyreels_v2.md

Lines changed: 22 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -150,19 +150,30 @@ From the original repo:
150150
import torch
151151
from diffusers import AutoModel, SkyReelsV2DiffusionForcingPipeline, UniPCMultistepScheduler
152152
from diffusers.utils import export_to_video
153+
# For faster loading into the GPU
154+
os.environ["HF_ENABLE_PARALLEL_LOADING"] = "yes"
153155

154-
vae = AutoModel.from_pretrained("Skywork/SkyReels-V2-DF-14B-540P-Diffusers", subfolder="vae", torch_dtype=torch.float32)
155-
transformer = AutoModel.from_pretrained("Skywork/SkyReels-V2-DF-14B-540P-Diffusers", subfolder="transformer", torch_dtype=torch.bfloat16)
156+
157+
model_id = "Skywork/SkyReels-V2-DF-1.3B-540P-Diffusers"
158+
vae = AutoModel.from_pretrained(model_id,
159+
subfolder="vae",
160+
torch_dtype=torch.float32,
161+
device_map="cuda")
156162

157163
pipeline = SkyReelsV2DiffusionForcingPipeline.from_pretrained(
158-
"Skywork/SkyReels-V2-DF-14B-540P-Diffusers",
164+
model_id,
159165
vae=vae,
160-
transformer=transformer,
161-
torch_dtype=torch.bfloat16
166+
torch_dtype=torch.bfloat16,
167+
device_map="cuda"
162168
)
163169
flow_shift = 8.0 # 8.0 for T2V, 5.0 for I2V
164170
pipeline.scheduler = UniPCMultistepScheduler.from_config(pipeline.scheduler.config, flow_shift=flow_shift)
165-
pipeline = pipeline.to("cuda")
171+
172+
# Some acceleration helpers
173+
# Be sure to install Flash Attention: https://github.com/Dao-AILab/flash-attention#installation-and-features
174+
# Normally 14 min., with compile_repeated_blocks(fullgraph=True) 12 min., with Flash Attention too 5.5 min.
175+
#pipeline.transformer.set_attention_backend("flash")
176+
#pipeline.transformer.compile_repeated_blocks(fullgraph=True)
166177

167178
prompt = "A cat and a dog baking a cake together in a kitchen. The cat is carefully measuring flour, while the dog is stirring the batter with a wooden spoon. The kitchen is cozy, with sunlight streaming through the window."
168179

@@ -200,13 +211,12 @@ from diffusers.utils import export_to_video, load_image
200211

201212

202213
model_id = "Skywork/SkyReels-V2-DF-14B-720P-Diffusers"
203-
vae = AutoencoderKLWan.from_pretrained(model_id, subfolder="vae", torch_dtype=torch.float32)
214+
vae = AutoencoderKLWan.from_pretrained(model_id, subfolder="vae", torch_dtype=torch.float32, device_map="cuda")
204215
pipeline = SkyReelsV2DiffusionForcingImageToVideoPipeline.from_pretrained(
205-
model_id, vae=vae, torch_dtype=torch.bfloat16
216+
model_id, vae=vae, torch_dtype=torch.bfloat16, device_map="cuda"
206217
)
207218
flow_shift = 5.0 # 8.0 for T2V, 5.0 for I2V
208219
pipeline.scheduler = UniPCMultistepScheduler.from_config(pipeline.scheduler.config, flow_shift=flow_shift)
209-
pipeline.to("cuda")
210220

211221
first_frame = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/flf2v_input_first_frame.png")
212222
last_frame = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/flf2v_input_last_frame.png")
@@ -263,13 +273,12 @@ from diffusers.utils import export_to_video, load_video
263273

264274

265275
model_id = "Skywork/SkyReels-V2-DF-14B-720P-Diffusers"
266-
vae = AutoencoderKLWan.from_pretrained(model_id, subfolder="vae", torch_dtype=torch.float32)
276+
vae = AutoencoderKLWan.from_pretrained(model_id, subfolder="vae", torch_dtype=torch.float32, device_map="cuda")
267277
pipeline = SkyReelsV2DiffusionForcingVideoToVideoPipeline.from_pretrained(
268-
model_id, vae=vae, torch_dtype=torch.bfloat16
278+
model_id, vae=vae, torch_dtype=torch.bfloat16, device_map="cuda"
269279
)
270280
flow_shift = 5.0 # 8.0 for T2V, 5.0 for I2V
271281
pipeline.scheduler = UniPCMultistepScheduler.from_config(pipeline.scheduler.config, flow_shift=flow_shift)
272-
pipeline.to("cuda")
273282

274283
video = load_video("input_video.mp4")
275284

@@ -286,50 +295,7 @@ export_to_video(output, "video.mp4", fps=24, quality=8)
286295
</hfoption>
287296
</hfoptions>
288297

289-
290-
## Notes
291-
292-
- SkyReels-V2 supports LoRAs with [`~loaders.SkyReelsV2LoraLoaderMixin.load_lora_weights`].
293-
294-
<details>
295-
<summary>Show example code</summary>
296-
297-
```py
298-
import torch
299-
from diffusers import AutoModel, SkyReelsV2DiffusionForcingPipeline
300-
from diffusers.utils import export_to_video
301-
302-
vae = AutoModel.from_pretrained(
303-
"Skywork/SkyReels-V2-DF-1.3B-540P-Diffusers", subfolder="vae", torch_dtype=torch.float32
304-
)
305-
pipeline = SkyReelsV2DiffusionForcingPipeline.from_pretrained(
306-
"Skywork/SkyReels-V2-DF-1.3B-540P-Diffusers", vae=vae, torch_dtype=torch.bfloat16
307-
)
308-
pipeline.to("cuda")
309-
310-
pipeline.load_lora_weights("benjamin-paine/steamboat-willie-1.3b", adapter_name="steamboat-willie")
311-
pipeline.set_adapters("steamboat-willie")
312-
313-
pipeline.enable_model_cpu_offload()
314-
315-
# use "steamboat willie style" to trigger the LoRA
316-
prompt = """
317-
steamboat willie style, golden era animation, The camera rushes from far to near in a low-angle shot,
318-
revealing a white ferret on a log. It plays, leaps into the water, and emerges, as the camera zooms in
319-
for a close-up. Water splashes berry bushes nearby, while moss, snow, and leaves blanket the ground.
320-
Birch trees and a light blue sky frame the scene, with ferns in the foreground. Side lighting casts dynamic
321-
shadows and warm highlights. Medium composition, front view, low angle, with depth of field.
322-
"""
323-
324-
output = pipeline(
325-
prompt=prompt,
326-
num_frames=97,
327-
guidance_scale=6.0,
328-
).frames[0]
329-
export_to_video(output, "video.mp4", fps=24)
330-
```
331-
332-
</details>
298+
`SkyReelsV2Pipeline` and `SkyReelsV2ImageToVideoPipeline` are also available without Diffusion Forcing framework applied.
333299

334300

335301
## SkyReelsV2DiffusionForcingPipeline

0 commit comments

Comments
 (0)