feat(flops): add NemotronH MoE-aware FLOPs tracking for MFU#3309
Open
dafu-wu wants to merge 1 commit into
Open
feat(flops): add NemotronH MoE-aware FLOPs tracking for MFU#3309dafu-wu wants to merge 1 commit into
dafu-wu wants to merge 1 commit into
Conversation
NemotronH (e.g. Nemotron-3 Nano V3) is a hybrid Mamba/attention/MLP model whose layer layout is given by hybrid_override_pattern, which for the MoE variants is dominated by 'E' (MoE FFN) layers. The FLOPs tracker previously raised ValueError for NemotronHConfig, so total_flops/theoretical_tflops were never populated and no FLOPS/MFU line was logged. This wires up a nemotron_h branch in convert_config_to_flops_config and extends _hybrid_model_flops to account for 'E' layers via a new _moe_layer_flops helper (routed topk + shared experts, non-gated ReLU^2). Without the 'E' handling the dominant FFN cost would be omitted and MFU would be severely under-reported. Builds on NVIDIA-NeMo#1971 (which only added the wiring, not MoE-layer FLOPs). - flops_formulas: add gated_linear_unit/moe_shared_expert_num fields, _moe_layer_flops, and 'E' handling in _hybrid_model_flops - flops_tracker: import nemotronh and add nemotron_h config branch - tests: cover MoE-layer counting and shared-expert/topk scaling Signed-off-by: dafu-wu <wuchengyi2006@163.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.
What does this PR do ?
Add MoE-aware FLOPs tracking for NemotronH models (e.g. Nemotron-3 Nano V3) so that training runs report Training FLOPS and Model Floating Point Utilization (MFU).
NemotronH is a hybrid Mamba/attention/MLP model whose layer layout is given by
hybrid_override_pattern, which for the MoE variants is dominated byE(MoE FFN) layers. The FLOPs tracker previously raisedValueErrorforNemotronHConfig, sototal_flops/theoretical_tflopswere never populated and no FLOPS/MFU line was logged.This wires up a
nemotron_hbranch inconvert_config_to_flops_configand extends_hybrid_model_flopsto account forElayers via a new_moe_layer_flopshelper (routedtopk+ shared experts, non-gated ReLU^2). Without theEhandling the dominant FFN cost would be omitted and MFU would be severely under-reported.Builds on #1971 (which only added the wiring, not MoE-layer FLOPs).
flops_formulas: addgated_linear_unit/moe_shared_expert_numfields,_moe_layer_flops, andEhandling in_hybrid_model_flopsflops_tracker: importnemotronhand addnemotron_hconfig branchtests: cover MoE-layer counting and shared-expert/topk scalingIssues
n/a
Usage
With this, an SFT/GRPO run on a NemotronH model prints:
Before your PR is "Ready for review"
Pre checks:
Additional Information
moe_ffn_hidden_size * (moe_router_topk + moe_shared_expert_num)as the effective FFN width. NemotronH uses a non-gated ReLU^2 activation, sogated_linear_unit=False(factor 1); gated (SwiGLU-style) models would use factor 2.6 * N_active * tokensestimate (formula/rule-of-thumb ratio ≈ 0.76, expected since the rule-of-thumb ignores attention/mamba sublinear terms) and confirmed eachEin the pattern increases total FLOPs by exactly one_moe_layer_flops.