Skip to content

Commit feedd53

Browse files
committed
fix(recipe): recompute Gemma 4 VL SFT layers
Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com>
1 parent f3c8f2f commit feedd53

3 files changed

Lines changed: 37 additions & 34 deletions

File tree

‎examples/model_verification_cards/gemma-4-26b-a4b-it/card.yaml‎

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ summary: >
1111
forward comparison remains unverified because the recorded run compared a
1212
tensor-parallel padding position rather than the prompt's next token.
1313
Decoder-focused SFT is verified on one 8-GPU H100 node with TP4/PP1/EP8/ETP1,
14-
a frozen vision encoder, and selective core-attention and MoE-activation
15-
recompute. The real CORD-v2 run completed 10 optimizer steps with stable
16-
memory and saved iter_0000010. LoRA PEFT is also verified on four H100 GPUs
17-
with TP2/PP1/EP4/ETP1 and a complete adapter checkpoint. Long-context SFT is
18-
pending. The published Bridge recipes do not currently provide VLM pretraining.
14+
a frozen vision encoder, and full-layer uniform activation recompute with one
15+
layer per recompute unit. The real CORD-v2 run completed 10 optimizer steps
16+
with stable memory and saved iter_0000010. LoRA PEFT is also verified on four
17+
H100 GPUs with TP2/PP1/EP4/ETP1 and a complete adapter checkpoint.
18+
Long-context SFT is pending. The published Bridge recipes do not currently
19+
provide VLM pretraining.
1920
verification_index:
2021
model_level:
2122
verified:
@@ -181,7 +182,7 @@ items:
181182
status: verified
182183
precision: bf16
183184
enabled_features: {}
184-
bridge_commit: 81e559ca4d579cf2d9ed5b8f3f48bef82e06451f # pragma: allowlist secret
185+
bridge_commit: f3130a0e37c78945ecf98b301dfc90505c3c305f # pragma: allowlist secret
185186
command: >
186187
./scripts/training/train.sh --nodes 1 --gpus-per-node 8
187188
--recipe gemma4_vl_26b_sft_config --mode sft --dataset cord-v2
@@ -192,28 +193,30 @@ items:
192193
--save_dir work/model-verification/gemma-4-26b-a4b-it/sft-checkpoints
193194
--save_interval 10 logger.log_interval=1 logger.log_throughput=true
194195
logger.save_config_filepath=work/model-verification/gemma-4-26b-a4b-it/sft-post-setup.yaml
195-
last_verified: 2026-08-04
196+
last_verified: 2026-08-11
196197
metrics:
197-
initial_loss: 1.268018
198-
final_loss: 0.06543536
199-
last_10_steps_step_time_ms_avg: 18699.99
200-
last_10_steps_model_tflops_per_gpu_avg: 26.47
201-
peak_allocated_memory_gib: 70.624
202-
peak_reserved_memory_gib: 71.021
198+
initial_loss: 1.282612
199+
final_loss: 0.09127883
200+
last_10_steps_step_time_ms_avg: 15936.25
201+
last_10_steps_model_tflops_per_gpu_avg: 32.20
202+
peak_allocated_memory_gib: 65.223
203+
peak_reserved_memory_gib: 72.356
203204
expected_result: >
204-
On 2026-08-04 the single-node TP4/PP1/EP8/ETP1 run loaded the immutable
205+
On 2026-08-11 the single-node TP4/PP1/EP8/ETP1 run loaded the immutable
205206
BF16 checkpoint and real CORD-v2 revision, then completed exactly 10
206207
optimizer steps at MBS1 and GBS32. The persisted post-setup config
207208
confirmed a frozen vision encoder, trainable projection and language
208-
model, expandable CUDA allocator segments, and selective core_attn plus
209-
moe_act recompute with CUDA graphs and CPU offload disabled. Loss moved
210-
from 1.268018 to 0.06543536, final grad norm was 1.561, and every step
211-
reported zero skipped and zero NaN iterations. Across all eight ranks,
212-
allocated memory returned to 56.493 GiB after each step, while
213-
cumulative peak allocated and reserved memory remained at or below
214-
70.624 and 71.021 GiB. The run saved a complete iter_0000010 torch_dist
215-
checkpoint with eight rank shards, finalized metadata, training state,
216-
and a latest-checkpoint tracker containing iteration 10.
209+
model, expandable CUDA allocator segments, and full-layer uniform
210+
recompute with one layer per recompute unit directly from the recipe
211+
defaults, while CUDA graphs and CPU offload remained disabled. Loss
212+
moved from 1.282612 to 0.09127883, final grad norm was 3.090, and all 10
213+
steps reported zero skipped and zero NaN iterations. After iteration 2,
214+
logger-reported ranks returned to
215+
62.134-62.145 GiB allocated, while cumulative peak allocated and
216+
reserved memory remained at or below 65.223 and 72.356 GiB. The run
217+
saved a complete iter_0000010 torch_dist checkpoint with eight rank
218+
shards, finalized metadata, run config, training state, and a
219+
latest-checkpoint tracker containing iteration 10.
217220
218221
sft_export_inference:
219222
H100:

‎src/megatron/bridge/recipes/gemma4_vl/h100/gemma4_vl.py‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def gemma4_vl_26b_sft_8gpu_h100_bf16_config() -> ConfigContainer:
111111
112112
Default configuration: 8 GPUs
113113
- TP=4, PP=1, EP=8, ETP=1 (dense DP=2, expert DP=1)
114-
- Selective core-attention and MoE-activation recompute
114+
- Full-layer uniform activation recompute
115115
- Frozen vision encoder with trainable projection and language model
116116
- LR=5e-5 (full SFT)
117117
- Sequence length: 4096
@@ -130,12 +130,12 @@ def gemma4_vl_26b_sft_8gpu_h100_bf16_config() -> ConfigContainer:
130130
cfg.model.expert_model_parallel_size = 8
131131
cfg.model.expert_tensor_parallel_size = 1
132132

133-
# Real CORD-v2 measurements require both modules to preserve H100 memory
134-
# headroom after optimizer-state initialization. Full-layer recompute is not needed.
135-
cfg.model.recompute_granularity = "selective"
136-
cfg.model.recompute_modules = ["core_attn", "moe_act"]
137-
cfg.model.recompute_method = None
138-
cfg.model.recompute_num_layers = None
133+
# Real-data SFT has batch-dependent activation and cross-entropy workspace peaks.
134+
# Checkpoint each decoder layer to preserve H100 memory headroom after optimizer initialization.
135+
cfg.model.recompute_granularity = "full"
136+
cfg.model.recompute_modules = None
137+
cfg.model.recompute_method = "uniform"
138+
cfg.model.recompute_num_layers = 1
139139

140140
# Decoder-focused SFT keeps the vision encoder fixed while training the
141141
# multimodal projection and language model.

‎tests/unit_tests/recipes/test_gemma4_vl_recipes.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ def test_gemma4_vl_sft_uses_memory_stable_8gpu_contract(monkeypatch: pytest.Monk
6363
assert cfg.model.expert_model_parallel_size == 8
6464
assert cfg.model.expert_tensor_parallel_size == 1
6565
assert cfg.model.sequence_parallel is True
66-
assert cfg.model.recompute_granularity == "selective"
67-
assert cfg.model.recompute_modules == ["core_attn", "moe_act"]
68-
assert cfg.model.recompute_method is None
69-
assert cfg.model.recompute_num_layers is None
66+
assert cfg.model.recompute_granularity == "full"
67+
assert cfg.model.recompute_modules is None
68+
assert cfg.model.recompute_method == "uniform"
69+
assert cfg.model.recompute_num_layers == 1
7070
assert cfg.model.cuda_graph_impl == "none"
7171
assert cfg.model.freeze_vision_model is True
7272
assert cfg.model.freeze_vision_projection is False

0 commit comments

Comments
 (0)