| |
| |
| |
| |
|
|
|
|
| |
| |
| |
|
|
| |
| |
|
|
| |
| |
| |
| |
| |
| |
|
|
| |
| |
| |
|
|
| |
| |
| |
| |
| |
|
|
| |
| |
|
|
| |
|
|
| |
| |
| |
|
|
|
|
|
|
| |
| |
| |
| |
| |
|
|
| |
| |
| |
| |
|
|
|
|
| import os |
| import torch |
| import torch.nn as nn |
| import torch.distributed as dist |
| import torch.multiprocessing as mp |
| from videox_fun.utils.predict_t2v import predict_t2v |
| |
|
|
| def cleanup(): |
| """销毁分布式进程组""" |
| dist.destroy_process_group() |
|
|
| def worker(rank, lora_paths): |
| """ |
| 这个 'worker' 函数就是被唤起到每个 GPU 上的核心子程序。 |
| 'rank' 参数是当前进程的 ID,也对应了 GPU 的 ID (0, 1, 2, ...)。 |
| """ |
| print(f"工作进程已在 Rank {rank} (GPU {rank}) 上启动...") |
| |
| path = lora_paths[rank] |
| |
| |
| torch.cuda.set_device(rank) |
| |
| predict_t2v(sample_size = [512, 288], lora_path = path, num_inference_steps = 30, num_generated_videos=50, seed=0, device=rank) |
|
|
| print(f"--- 进程 {rank} 在 GPU {rank} 上运行完毕 ---\n") |
|
|
| |
| cleanup() |
|
|
| def main(): |
| |
| num_gpus = torch.cuda.device_count() |
| print(f"检测到 {num_gpus} 个 GPU。") |
|
|
| |
| |
| lora_paths = [ |
| '/nfs/ywang29/Reward_finetuning/VideoX-Fun/output_Oct2_1/checkpoint-1000.safetensors', |
| '/nfs/ywang29/Reward_finetuning/VideoX-Fun/output_Oct2_1/checkpoint-1500.safetensors', |
| '/nfs/ywang29/Reward_finetuning/VideoX-Fun/output_Oct2_1/checkpoint-2000.safetensors', |
| '/nfs/ywang29/Reward_finetuning/VideoX-Fun/output_Oct2_1/checkpoint-5000.safetensors', |
| '/nfs/ywang29/Reward_finetuning/VideoX-Fun/output_Oct2_1/checkpoint-8000.safetensors', |
| ] |
|
|
| |
| procs_to_start = min(num_gpus, len(lora_paths)) |
| if procs_to_start < len(lora_paths): |
| print(f"警告: 定义了 {len(lora_paths)} 组参数,但只有 {num_gpus} 个 GPU 可用。") |
| print(f"将只为前 {procs_to_start} 组参数启动进程。") |
|
|
|
|
| |
| |
| |
| mp.spawn(worker, |
| args=(lora_paths,), |
| nprocs=procs_to_start, |
| join=True) |
|
|
|
|
| if __name__ == "__main__": |
| main() |