Skip to content

Commit f6c5235

Browse files
lijianhao01qiqibao121
authored andcommitted
perf(examples/fastwam): enable the measured recipe in the zero1 script
Turns on the flags the previous commits added, which is the only training-visible change in this series: this script now trains with the forward autocast off, `rmsnorm_impl=wan`, two compiled regions, and fused AdamW. Anyone who was running it gets different numerics (bit-level, not semantic) and different peak memory, so it is separated deliberately. --optimizer TorchFusedAdamW +3.9% --cudnn-benchmark +1.4% --zero-parameters-as-bucket-view +2.0% model.disable_train_autocast +3.2% model.drop_all_true_cross_attn_mask +0.8% model.compile_vae_encode +1.6% model.mot_compile_blocks=both +5.7% (with model.rmsnorm_impl=wan) Cumulative 82.9 -> 102.3 samples/s on 8xA800 at per-device batch 24, which is within 0.8% of the upstream FastWAM reference on the same pod (103.28), i.e. at parity given the 0.6% paired spread. The header block documents each number, the measurement protocol (110 iterations, 10 warmed up, 100 timed, paired inside one sweep because cross-sweep drift reaches 3.4%), why `mot_compile_blocks` and `rmsnorm_impl` must move together, and why the gain is batch dependent. Two knobs stay off with the reason recorded rather than being enabled quietly: `--no-check-for-nan-in-loss-and-grad` (worth ~1.4%, removes the divergence guard) and `PER_DEVICE_BATCH_SIZE=24` (worth +7.9%, changes the effective batch size). Convergence check at batch 16 over 200 steps against the unmodified script: video loss tail-mean 0.18267 -> 0.18312 (+0.24%), action 0.13203 -> 0.13213 (+0.08%), no NaN, differences oscillating in both directions and decaying with convergence. Single seed only, so this is evidence of numerical perturbation rather than a proof of convergence neutrality. Change-Id: I97111747b81a652f4cd67b4f06da9aa7c8dbd737
1 parent 5ce06c5 commit f6c5235

1 file changed

Lines changed: 60 additions & 4 deletions

File tree

examples/embodied/fastwam/run_fastwam_sft_ddp_zero1_finetune.sh

Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,52 @@
2222
# The memory saved by ZeRO-1 is what makes the larger --per-device-batch-size
2323
# below affordable relative to the plain DDP script.
2424
#
25-
# Two optional ZeRO knobs are left off by default:
26-
# --zero-parameters-as-bucket-view further cuts peak memory, but can clash
27-
# with torch.compile + the DDP reducer.
25+
# One optional ZeRO knob is left off by default:
2826
# --zero-master-param-dtype fp32 rank-local fp32 master params, broadcast
2927
# after each step. Better numerics under
3028
# bf16 training at some bandwidth cost.
3129
#
30+
# ── Throughput recipe ─────────────────────────────────────────
31+
# The flags below the ZeRO block were each measured on 8xA800 (LIBERO-10, 224x448
32+
# two-camera, 9 frames), 110 iterations with 10 warmed up and 100 timed, comparing
33+
# paired runs inside one sweep (across sweeps the same config drifts by up to 3.4%,
34+
# so only paired numbers are meaningful):
35+
#
36+
# --optimizer TorchFusedAdamW +3.9% the default AdamW is unfused here
37+
# --cudnn-benchmark +1.4% autotunes the VAE convolutions
38+
# --zero-parameters-as-bucket-view +2.0% 1651 per-tensor broadcasts -> 8
39+
# model.disable_train_autocast +3.2% params are already bf16, so the
40+
# autocast wrapper only adds casts
41+
# model.drop_all_true_cross_attn_mask +0.8% an all-True mask forces SDPA off
42+
# its flash kernel onto cutlass
43+
# model.compile_vae_encode +1.6%
44+
# model.mot_compile_blocks=both +5.7% at --per-device-batch-size 24
45+
# + model.rmsnorm_impl=wan (see below)
46+
#
47+
# Cumulative: 82.9 -> 102.3 samples/s (8 GPUs) at batch 24.
48+
#
49+
# `mot_compile_blocks=both` and `rmsnorm_impl=wan` must be set together, and the
50+
# pairing is conditional:
51+
# * Compiling the MoT blocks only pays if the graph has no breaks. The TE
52+
# RMSNorm and the Triton RoPE are opaque to Dynamo, so with `rmsnorm_impl=te`
53+
# the compiled region fragments and throughput *drops* 7.2%.
54+
# * `rmsnorm_impl=wan` (`F.rms_norm`) is the slow path in eager on torch < 2.9,
55+
# where it decomposes into seven fp32 kernels - but inside a compiled region
56+
# Inductor fuses it into one Triton kernel, so the penalty is never paid and
57+
# peak memory even drops slightly (74.90 vs 75.06 GiB).
58+
# * So: compiling -> `wan`; not compiling -> `te`. On torch >= 2.9 `F.rms_norm`
59+
# has a native fused kernel and this should be re-measured.
60+
# * The gain is batch-dependent: at batch 16 the step is kernel-launch bound and
61+
# the same config is a wash. Measure on the batch size you will train at.
62+
#
63+
# Two more knobs are deliberately left off:
64+
# --no-check-for-nan-in-loss-and-grad worth ~1.4% (a nan_to_num sweep over
65+
# 6.02 B gradients each step), but it
66+
# removes the divergence guard.
67+
# PER_DEVICE_BATCH_SIZE=24 worth +7.9% over 16 and fits in 75.06 of
68+
# 79.33 GiB, but it changes the effective
69+
# batch size, which is a training decision.
70+
#
3271
# Usage:
3372
# bash run_fastwam_sft_ddp_zero1_finetune.sh
3473
# DATASET_PATH=/path/to/libero TOKENIZER_PATH=/path/to/tokenizer \
@@ -133,6 +172,14 @@ DISTRIBUTED_TRAINING_ARGS=(
133172
--no-ddp-broadcast-buffers
134173
--ddp-bucket-cap-mb 200
135174
--dtype bfloat16
175+
--zero-parameters-as-bucket-view
176+
)
177+
178+
# ── Throughput params ─────────────────────────────────────────
179+
# See the recipe block at the top of this file for the measured gain of each.
180+
PERF_ARGS=(
181+
--optimizer TorchFusedAdamW
182+
--cudnn-benchmark
136183
)
137184

138185
# ── Logging params ────────────────────────────────────────────
@@ -143,7 +190,15 @@ LOGGING_ARGS=(
143190
)
144191

145192
# ── Model/data dotlist overrides ──────────────────────────────
146-
MODEL_DATA_OVERRIDES=()
193+
# The four performance overrides pair with PERF_ARGS above; `mot_compile_blocks`
194+
# and `rmsnorm_impl` must move together (see the recipe block at the top).
195+
MODEL_DATA_OVERRIDES=(
196+
model.disable_train_autocast=true
197+
model.drop_all_true_cross_attn_mask=true
198+
model.compile_vae_encode=true
199+
model.mot_compile_blocks=both
200+
model.rmsnorm_impl=wan
201+
)
147202
if [[ -n "$ACTION_DIT_PRETRAINED_PATH" ]]; then
148203
MODEL_DATA_OVERRIDES+=("model.action_dit_pretrained_path=$ACTION_DIT_PRETRAINED_PATH")
149204
fi
@@ -167,6 +222,7 @@ PYTHONPATH=$LOONGFORGE_PATH:${PYTHONPATH:-} \
167222
"${DATA_ARGS[@]}" \
168223
"${TRAINING_ARGS[@]}" \
169224
"${DISTRIBUTED_TRAINING_ARGS[@]}" \
225+
"${PERF_ARGS[@]}" \
170226
"${LOGGING_ARGS[@]}" \
171227
"${MODEL_DATA_OVERRIDES[@]+"${MODEL_DATA_OVERRIDES[@]}"}" \
172228
"$@"

0 commit comments

Comments
 (0)