diff --git a/miles/utils/arguments.py b/miles/utils/arguments.py index ec78f3686..eb48351e9 100644 --- a/miles/utils/arguments.py +++ b/miles/utils/arguments.py @@ -2149,9 +2149,9 @@ def validate_dmd2_args(args) -> None: "--loss-type dmd2 samples the student unguided; set --diffusion-guidance-scale 1.0 " "and drop --diffusion-true-cfg-scale" ) - if args.use_lora or args.teacher_lora_adapter_paths is not None: + if args.teacher_lora_adapter_paths is not None: raise ValueError( - "--loss-type dmd2 trains the full student and critic; drop --use-lora and --teacher-lora-adapter-path" + "--loss-type dmd2 takes its teacher from --teacher-load alone; drop --teacher-lora-adapter-path" ) if args.ref_mode != "none": raise ValueError("--loss-type dmd2 uses no reference model; drop --ref-mode and --diffusion-kl-beta") diff --git a/scripts/run_diffusion_dmd2_h3_t2va_16gpu_multinode.py b/scripts/run_diffusion_dmd2_h3_t2va_16gpu_multinode.py index e13c3ed20..ee42f954d 100644 --- a/scripts/run_diffusion_dmd2_h3_t2va_16gpu_multinode.py +++ b/scripts/run_diffusion_dmd2_h3_t2va_16gpu_multinode.py @@ -34,6 +34,18 @@ Usage (after the multi-node bring-up, on the head node): MILES_SCRIPT_EXTERNAL_RAY=1 python3 scripts/run_diffusion_dmd2_h3_t2va_16gpu_multinode.py + +Single node, for smoke runs and the e2e CI: the script starts its own ray cluster. Two GPUs hold the +rollout engine (tp2) and FSDP DP=2 over the student, the critic and the teacher in one of two ways: + --lora the student and the critic train LoRA adapters (rank 64, lr 1e-4) over frozen + bf16 bases, with no CPU offload; what the e2e CI runs, not a tuned recipe; + --fsdp-cpu-offload the full-parameter recipe with its parameters, gradients and optimizer states + in host memory (about 1.6 TB with the engine). The master stays fp32: H3 keeps + proj_in / time_embedder / proj_out in fp32, and FSDP2 wants one original dtype + across a group's trainable parameters. + python3 scripts/run_diffusion_dmd2_h3_t2va_16gpu_multinode.py --num-nodes 1 --num-gpus-per-node 2 \ + --rollout-batch-size 4 --critic-steps-per-rollout 2 --num-rollout 2 --eval-interval 0 \ + --save-interval 0 --lora """ import hashlib @@ -80,10 +92,20 @@ @dataclass class ScriptArgs(U.ExecuteTrainConfig): num_rollout: int = 200 - # 5 critic steps x 64 samples; the student steps on the last 64. + # critic_steps_per_rollout critic steps x 64 samples; the student steps on the last 64. rollout_batch_size: int = 320 + critic_steps_per_rollout: int = 5 + # 0 disables eval / checkpoints. eval_interval: int = 5 save_interval: int = 50 + # Colocated train + rollout GPUs; one node starts its own ray cluster. + num_nodes: int = 2 + num_gpus_per_node: int = 8 + # Below 16 GPUs the two 31B optimizers do not fit: keep params, grads and optimizer states in + # host memory (the optimizer steps on the CPU). + fsdp_cpu_offload: bool = False + # Or train LoRA adapters of the student and the critic over frozen bf16 bases. + lora: bool = False duration_seconds: float = 5.0 data_dir: str = "/root/datasets" # "teacher" or "fasth3": render the eval prompts with that model instead of training. @@ -169,6 +191,8 @@ def execute(args: ScriptArgs, prompt_dir: str) -> None: "--n-samples-per-eval-prompt 1 " f"--save-eval-media-dir {run_dir}/eval_media " ) + if not args.reference and args.eval_interval <= 0: + eval_args = "" # Every eval video; training rollouts carry no media, since --rm-type none skips their decode. wandb_args = U.get_default_wandb_args( @@ -189,13 +213,14 @@ def execute(args: ScriptArgs, prompt_dir: str) -> None: "--update-weight-buffer-size 4294967296 " ) + num_gpus = args.num_nodes * args.num_gpus_per_node topology_args = ( - "--actor-num-nodes 2 " - "--actor-num-gpus-per-node 8 " - "--num-gpus-per-node 8 " - "--rollout-num-gpus 16 " + f"--actor-num-nodes {args.num_nodes} " + f"--actor-num-gpus-per-node {args.num_gpus_per_node} " + f"--num-gpus-per-node {args.num_gpus_per_node} " + f"--rollout-num-gpus {num_gpus} " "--rollout-num-gpus-per-engine 2 " - "--rollout-parser-num-workers 16 " + f"--rollout-parser-num-workers {num_gpus} " "--colocate " # H3 denoising blocks the engine's event loop for tens of seconds per sample. "--rollout-health-check-interval 60 " @@ -219,29 +244,38 @@ def execute(args: ScriptArgs, prompt_dir: str) -> None: f"--diffusion-eval-num-steps {eval_steps} " ) else: + save_args = f"--save {run_dir}/ckpt --save-interval {args.save_interval} " if args.save_interval > 0 else "" + offload_args = "--fsdp-cpu-offload --teacher-cpu-offload " if args.fsdp_cpu_offload else "" + if args.lora: + # The adapters leave H3's fp32-pinned modules frozen, so the master can be bf16. + params_args = ( + "--use-lora --lora-ipc-weight-sync --lora-rank 64 --lora-alpha 128 " + "--sglang-lora-merge-mode merge " + "--lr 1e-4 --critic-lr 1e-4 " + "--fsdp-master-dtype bf16 --fsdp-reduce-dtype bf16 " + ) + else: + params_args = "--lr 2e-6 --critic-lr 2e-6 --fsdp-master-dtype fp32 --fsdp-reduce-dtype fp32 " mode_args = ( f"--hf-checkpoint {MODEL} " - f"--save {run_dir}/ckpt " - f"--save-interval {args.save_interval} " + f"{save_args}" f"--num-rollout {args.num_rollout} " - f"--eval-interval {args.eval_interval} " + f"{f'--eval-interval {args.eval_interval} ' if args.eval_interval > 0 else ''}" "--loss-type dmd2 " f"--teacher-load {MODEL} " "--dmd2-teacher-guidance-scale 1.0 " - "--dmd2-critic-steps-per-rollout 5 " + f"--dmd2-critic-steps-per-rollout {args.critic_steps_per_rollout} " "--dmd2-score-sigma-range 0.001 0.999 " "--dmd2-critic-loss-space x0 " "--fsdp-flow-shift visual=5.0 " "--diffusion-step-strategy-path miles.rollout.step_strategy_hub.stop_at_random_step " "--diffusion-sde-type ode " - "--lr 2e-6 " - "--critic-lr 2e-6 " + f"{params_args}" "--weight-decay 0.01 " "--train-backend fsdp " - "--fsdp-master-dtype fp32 " - "--fsdp-reduce-dtype fp32 " "--diffusion-forward-dtype bf16 " "--gradient-checkpointing " + f"{offload_args}" ) U.execute_train( @@ -249,7 +283,7 @@ def execute(args: ScriptArgs, prompt_dir: str) -> None: f"{mode_args} {rollout_args} {diffusion_args} {eval_args} {wandb_args} {sglang_args} " f"{topology_args} {args.extra_args}" ), - num_gpus_per_node=8, + num_gpus_per_node=args.num_gpus_per_node, config=args, extra_env_vars={"PYTORCH_CUDA_ALLOC_CONF": "expandable_segments:True"}, ) diff --git a/tests/ci/fixtures/e2e_standards/test_h3_t2va_dmd2_16xGPU_single_node_2xGPU_proxy.json b/tests/ci/fixtures/e2e_standards/test_h3_t2va_dmd2_16xGPU_single_node_2xGPU_proxy.json new file mode 100644 index 000000000..163dfc516 --- /dev/null +++ b/tests/ci/fixtures/e2e_standards/test_h3_t2va_dmd2_16xGPU_single_node_2xGPU_proxy.json @@ -0,0 +1,114 @@ +{ + "meta": { + "commit": "439990e5e86b6d6bac94a9ac2d0e154e690ff26e", + "source": "test_h3_t2va_dmd2_16xGPU_single_node_2xGPU_proxy.py" + }, + "metrics": { + "train/critic-grad_norm": [ + [ + 1.0, + 0.06304825842380524 + ], + [ + 2.0, + 1.4389699697494507 + ], + [ + 3.0, + 0.04073259234428406 + ], + [ + 4.0, + 0.30865904688835144 + ] + ], + "train/critic-loss": [ + [ + 1.0, + 0.10361059755086899 + ], + [ + 2.0, + 0.3423595726490021 + ], + [ + 3.0, + 0.04162454791367054 + ], + [ + 4.0, + 0.8172207176685333 + ] + ], + "train/dmd2_grad_abs_mean": [ + [ + 1.0, + 0.08365654572844505 + ], + [ + 2.0, + 0.027618293650448322 + ] + ], + "train/dmd2_score_gap_abs_mean": [ + [ + 1.0, + 0.03811744134873152 + ], + [ + 2.0, + 0.021260653622448444 + ] + ], + "train/dmd2_teacher_dist_abs_mean": [ + [ + 1.0, + 0.39523235708475113 + ], + [ + 2.0, + 0.83000248670578 + ] + ], + "train/dmd2_x0_mean": [ + [ + 1.0, + 0.056482404470443726 + ], + [ + 2.0, + -0.15415865182876587 + ] + ], + "train/dmd2_x0_std": [ + [ + 1.0, + 1.0739970207214355 + ], + [ + 2.0, + 2.4941294193267822 + ] + ], + "train/grad_norm": [ + [ + 1.0, + 0.009701848961412907 + ], + [ + 2.0, + 0.04545477405190468 + ] + ], + "train/x0_mean_abs_diff": [ + [ + 1.0, + 0.0606351857462888 + ], + [ + 2.0, + 0.33430661600102823 + ] + ] + } +} diff --git a/tests/e2e/short/test_h3_t2va_dmd2_16xGPU_single_node_2xGPU_proxy.py b/tests/e2e/short/test_h3_t2va_dmd2_16xGPU_single_node_2xGPU_proxy.py new file mode 100644 index 000000000..dd24c5b5c --- /dev/null +++ b/tests/e2e/short/test_h3_t2va_dmd2_16xGPU_single_node_2xGPU_proxy.py @@ -0,0 +1,52 @@ +"""E2E: MiniMax H3 t2va 4-step DMD2 (data-free), 2-GPU colocate (FSDP DP=2 over the student, +the critic and the teacher, one tp2 sglang rollout engine, no reward), 2 rollouts of 4 +prompts: 2 critic steps of 2 samples, then 1 student step on the last 2 — runs the recipe +script itself with its single-node knobs and checks its metric series against the registered +standard (tests/ci/fixtures/e2e_standards/). Two GPUs cannot hold the full-parameter recipe, +and its CPU-offloaded form (--fsdp-cpu-offload, about 1.6 TB of host memory) does not fit the +shared CI node next to another e2e, so the student and the critic train LoRA adapters over +frozen bf16 bases here (--lora, about 110 GB per GPU at the critic step). Runs with +--deterministic-mode, so every metric is compared strictly, bit for bit. The only e2e +exercising the multi-trainer-group driver, the critic -> actor hand-off and the rollout +stopped at a random step.""" + +from tests.ci.e2e_metrics_registry import register_e2e_ci + +register_e2e_ci( + est_time=1200, + suite="stage-c-3-gpu-h200", + labels=["e2e"], + script="scripts/run_diffusion_dmd2_h3_t2va_16gpu_multinode.py", + args=[ + "--num-nodes", + "1", + "--num-gpus-per-node", + "2", + "--num-rollout", + "2", + "--rollout-batch-size", + "4", + "--critic-steps-per-rollout", + "2", + "--eval-interval", + "0", + "--save-interval", + "0", + "--duration-seconds", + "4", + "--lora", + "--extra-args", + "--deterministic-mode", + ], + metrics=[ + "train/critic-loss", + "train/critic-grad_norm", + "train/grad_norm", + "train/dmd2_grad_abs_mean", + "train/dmd2_score_gap_abs_mean", + "train/dmd2_teacher_dist_abs_mean", + "train/dmd2_x0_mean", + "train/dmd2_x0_std", + "train/x0_mean_abs_diff", + ], +) diff --git a/tests/fast/utils/test_dmd2_arguments.py b/tests/fast/utils/test_dmd2_arguments.py index fb0ac64fc..e9d34ed7f 100644 --- a/tests/fast/utils/test_dmd2_arguments.py +++ b/tests/fast/utils/test_dmd2_arguments.py @@ -125,8 +125,7 @@ def test_valid_dmd2_args_pass_unchanged(): ({"dmd2_score_sigma_range": [0.5, 1.5]}, "0 <= MIN < MAX <= 1"), ({"diffusion_guidance_scale": 4.5}, "samples the student unguided"), ({"diffusion_true_cfg_scale": 4.5}, "samples the student unguided"), - ({"use_lora": True}, "drop --use-lora"), - ({"teacher_lora_adapter_paths": ["teacher-adapter"]}, "drop --use-lora and --teacher-lora-adapter-path"), + ({"teacher_lora_adapter_paths": ["teacher-adapter"]}, "drop --teacher-lora-adapter-path"), ({"ref_mode": "ref"}, "uses no reference model"), ({"diffusion_recompute_old_log_prob": True}, "not DMD2"), ({"num_steps_per_rollout": 2}, "one actor step per rollout"),