Skip to content

[Bug] Validate activation memory budget - #4291

Merged
tianyu-l merged 1 commit into
pytorch:mainfrom
taking-lying-flat:fix/memory-budget-validation
Aug 23, 2026
Merged

tianyu-l merged 1 commit into
pytorch:mainfrom
taking-lying-flat:fix/memory-budget-validation

Conversation

@taking-lying-flat

@taking-lying-flat taking-lying-flat commented Aug 23, 2026 •

Copy link
Copy Markdown
Contributor

Problem

MemoryBudgetAC documents memory_budget as an inclusive value from 0 to 1, but its Config currently accepts every floating-point value. MemoryBudgetAC.apply then assigns that value directly to torch._functorch.config.activation_memory_budget.

This allows negative values, values above 1, NaN, and ±Inf to reach Functorch. Because the destination is process-global configuration, an invalid value can affect compiler partitioning beyond the config object that introduced it and can surface as a delayed, difficult-to-diagnose failure instead of a clear configuration error.

Fix

Validate memory_budget in MemoryBudgetAC.Config.post_init before the policy can be applied. The inclusive comparison accepts exactly values in the documented range, including the 0 and 1 boundaries. It also rejects all non-finite float values: infinities fall outside the range, while comparisons with NaN are false.

The validation is intentionally kept in the owning config rather than in apply so every construction path fails early and invalid state is never written to Functorch's process-global config.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Aug 23, 2026
@tianyu-l
tianyu-l merged commit 9854306 into pytorch:main Aug 23, 2026
15 checks passed
tianyu-l pushed a commit that referenced this pull request Sep 19, 2026
…tokens (#4301)

With the default validation dataloader (concat-then-split packing,
validate.py Config), a per-rank validation split holding fewer than
num_tokens_per_batch tokens yields zero packed rows, because
`_packing_output_is_full` drops partially filled rows. The validate loop
then breaks on the first StopIteration with `accumulated_loss` still
None, and the bare `assert accumulated_loss is not None` kills the whole
training run with a message-less AssertionError at the first validation
step. Without the assert, `global_loss_sum / num_global_valid_tokens`
raises ZeroDivisionError instead.

This PR replaces the assert with a ValueError naming the cause
(validation dataset supplied fewer than num_tokens_per_batch tokens on
this rank; concat-then-split packing drops partial batches) and the
remedy (decrease training.num_tokens_per_microbatch_per_dp_rank or use a
larger validation set), and guards the zero-valid-token division the
same way. Same fail-fast-with-a-clear-message class as the merged #4287
and #4291.

No numerical path changes: this is validation-layer error handling only,
the loss computation is untouched, so no numerics proof applies. No new
CLI flags.

Tests: two unit tests in tests/unit_tests/test_validate.py construct
both zero-batch and zero-valid-token conditions using the file's
existing validator harness. On main they fail with the bare
AssertionError and ZeroDivisionError; with this change they assert the
ValueError messages. pre-commit passes on both touched files.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants