[training, test] feat: add unit tests for theoretical_memory_utils - #3785
Closed
lonexreb wants to merge 1 commit into
Closed
[training, test] feat: add unit tests for theoretical_memory_utils#3785lonexreb wants to merge 1 commit into
lonexreb wants to merge 1 commit into
Conversation
theoretical_memory_utils.py exports three public helpers (compute_weight_and_optimizer_memory, compute_activation_memory, report_theoretical_memory) and one private vocab helper. All four operate on a ConfigContainer-shaped object and do pure arithmetic — no GPU, no model construction, no checkpoints — so they are a natural unit-test target. This commit adds 19 tests across four classes that exercise: - weight-and-optimizer memory: positive output, distributed vs. non-distributed optimizer accounting, data-parallel scaling, tensor-parallel sharding, separate-vs-shared embeddings, gated linear (silu vs. non-silu), layer count, MoE expert count, GQA vs. MHA, and verbose-mode logging - activation memory: positivity, layer/TP/batch sensitivity, interleaved VPP penalty, non-interleaved PP microbatch discount, PP=1 output-layer term, and verbose logging - report_theoretical_memory: sequence-parallel + selective recompute prints the full breakdown; otherwise weight-only; full recompute also prints weight-only. MegatronMIMOProvider is patched out so the early-return MIMO check does not short-circuit normal configs. - NUM_BYTES_IN_MEGABYTE constant Follows the pattern of recently-merged unit-test PRs NVIDIA-NeMo#3650 (pg_utils) and NVIDIA-NeMo#3695 (FLOPs calculator). No production changes. Signed-off-by: lonexreb <reach2shubhankar@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
`src/megatron/bridge/training/utils/theoretical_memory_utils.py` exports three public helpers that compute model memory footprint analytically from a `ConfigContainer`:
They do pure arithmetic on dataclass fields — no GPU, no model construction, no checkpoints — so they're a natural unit-test target that was previously uncovered.
What this PR adds
19 tests across four classes in `tests/unit_tests/training/utils/test_theoretical_memory_utils.py`:
`TestComputeWeightAndOptimizerMemory` (11)
`TestComputeActivationMemory` (7)
`TestReportTheoreticalMemory` (3)
`MegatronMIMOProvider` is patched out so the early-return MIMO check doesn't short-circuit normal configs.
`TestNumBytesInMegabyteConstant` (1)
Why
Follows the recently-merged unit-test pattern from #3650 (pg_utils) and #3695 (FLOPs calculator) — small, GPU-free, high-signal coverage of an analytic helper.
Test plan
🤖 Generated with Claude Code