Skip to content

CFG Parallel #10879

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

CFG Parallel #10879

wants to merge 1 commit into from

Conversation

a-r-r-o-w
Copy link
Member

@a-r-r-o-w a-r-r-o-w commented Feb 23, 2025

WIP Pt. 2 for guide on how to make custom hooks!

import torch
import torch.distributed as dist
from diffusers import LTXPipeline
from diffusers.utils import export_to_video
from diffusers.hooks._cfg_parallel import apply_cfg_parallel

dist.init_process_group(backend="nccl")

world_size = dist.get_world_size()
rank = dist.get_rank()
assert world_size == 2

torch.cuda.set_device(rank)

pipe = LTXPipeline.from_pretrained("a-r-r-o-w/LTX-Video-diffusers", torch_dtype=torch.bfloat16)
pipe.to("cuda")

apply_cfg_parallel(pipe.transformer)

prompt = "A woman with long brown hair and light skin smiles at another woman with long blonde hair. The woman with brown hair wears a black jacket and has a small, barely noticeable mole on her right cheek. The camera angle is a close-up, focused on the woman with brown hair's face. The lighting is warm and natural, likely from the setting sun, casting a soft glow on the scene. The scene appears to be real-life footage"
negative_prompt = "worst quality, inconsistent motion, blurry, jittery, distorted"

video = pipe(
    prompt=prompt,
    negative_prompt=negative_prompt,
    width=704,
    height=480,
    num_frames=161,
    num_inference_steps=50,
    generator=torch.Generator().manual_seed(42),  # !!! IMPORTANT !!!
).frames[0]

if rank == 0:
    export_to_video(video, "output.mp4", fps=24)

dist.destroy_process_group()
torchrun --nnodes=1 --nproc_per_node=2 cfg_parallel_ltx_video.py

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Copy link
Contributor

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the contributing guidelines are likely to be ignored.

@github-actions github-actions bot added the stale Issues that haven't received updates label Mar 25, 2025
@a-r-r-o-w a-r-r-o-w closed this Apr 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale Issues that haven't received updates
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants