-
Notifications
You must be signed in to change notification settings - Fork 42
Add report generation strategy for the MegatronRun #787
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
juntaowww
wants to merge
7
commits into
NVIDIA:main
Choose a base branch
from
juntaowww:megatron_run_report
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
da3a0ea
Add `MegatronRunReportGenerationStrategy`
juntaowww 8b2dbea
Add tests
juntaowww c257022
Fix copyright year
juntaowww 27edf70
Fix tests
juntaowww 347aba8
Change report to csv format
juntaowww 0efbc49
Skip first 20 iters instead of keeping last 10
juntaowww 27ac52a
Fix overwrite behavior between test and scenario configuration
juntaowww File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
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
149 changes: 149 additions & 0 deletions
149
tests/report_generation_strategy/test_megatron_run_report_generation_strategy.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,149 @@ | ||
| # SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES | ||
| # Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
|
|
||
| from cloudai import TestRun | ||
| from cloudai.core import METRIC_ERROR | ||
| from cloudai.systems.slurm.slurm_system import SlurmSystem | ||
| from cloudai.workloads.megatron_run import ( | ||
| MegatronRunCmdArgs, | ||
| MegatronRunReportGenerationStrategy, | ||
| MegatronRunTestDefinition, | ||
| ) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def megatron_run_tr(tmp_path: Path) -> TestRun: | ||
| test = MegatronRunTestDefinition( | ||
| name="megatron_run", | ||
| description="desc", | ||
| test_template_name="t", | ||
| cmd_args=MegatronRunCmdArgs(docker_image_url="http://url", run_script=Path(__file__)), | ||
| ) | ||
| tr = TestRun(name="megatron_run_test", test=test, num_nodes=1, nodes=[], output_path=tmp_path) | ||
|
|
||
| stdout_content = ( | ||
| "[2026-01-16 07:32:24] iteration 5/ 100 | consumed samples: 10240 | " | ||
| "elapsed time per iteration (ms): 15800.0 | throughput per GPU (TFLOP/s/GPU): 490.0 | " | ||
| "learning rate: 4.134000E-07 | global batch size: 2048 | lm loss: 1.344240E+01 | " | ||
| "seq_load_balancing_loss: 1.000203E+00 | loss scale: 1.0 | grad norm: 2.870 | " | ||
| "num zeros: 1174412544.0 | params norm: 8660.607 | " | ||
| "number of skipped iterations: 0 | number of nan iterations: 0 |\n" | ||
| "[2026-01-16 07:32:39] iteration 6/ 100 | consumed samples: 12288 | " | ||
| "elapsed time per iteration (ms): 15639.0 | throughput per GPU (TFLOP/s/GPU): 494.6 | " | ||
| "learning rate: 4.180800E-07 | global batch size: 2048 | lm loss: 1.342407E+01 | " | ||
| "seq_load_balancing_loss: 1.000202E+00 | loss scale: 1.0 | grad norm: 2.867 | " | ||
| "num zeros: 1174412672.0 | params norm: 8660.606 | " | ||
| "number of skipped iterations: 0 | number of nan iterations: 0 |\n" | ||
| "[2026-01-16 07:32:54] iteration 7/ 100 | consumed samples: 14336 | " | ||
| "elapsed time per iteration (ms): 15448.5 | throughput per GPU (TFLOP/s/GPU): 500.6 | " | ||
| "learning rate: 4.227600E-07 | global batch size: 2048 | lm loss: 1.340574E+01 | " | ||
| "seq_load_balancing_loss: 1.000201E+00 | loss scale: 1.0 | grad norm: 2.864 | " | ||
| "num zeros: 1174412800.0 | params norm: 8660.605 | " | ||
| "number of skipped iterations: 0 | number of nan iterations: 0 |\n" | ||
| ) | ||
| (tr.output_path / "stdout.txt").write_text(stdout_content) | ||
|
|
||
| return tr | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def megatron_run_tr_no_data(tmp_path: Path) -> TestRun: | ||
| test = MegatronRunTestDefinition( | ||
| name="megatron_run", | ||
| description="desc", | ||
| test_template_name="t", | ||
| cmd_args=MegatronRunCmdArgs(docker_image_url="http://url", run_script=Path(__file__)), | ||
| ) | ||
| tr = TestRun(name="megatron_run_test", test=test, num_nodes=1, nodes=[], output_path=tmp_path) | ||
|
|
||
| stdout_content = """ | ||
| Some random log output without iteration metrics | ||
| Starting training... | ||
| """ | ||
| (tr.output_path / "stdout.txt").write_text(stdout_content) | ||
|
|
||
| return tr | ||
juntaowww marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| def test_megatron_run_can_handle_directory(slurm_system: SlurmSystem, megatron_run_tr: TestRun) -> None: | ||
| strategy = MegatronRunReportGenerationStrategy(slurm_system, megatron_run_tr) | ||
| assert strategy.can_handle_directory() | ||
|
|
||
|
|
||
| def test_megatron_run_cannot_handle_directory_without_iteration_data( | ||
| slurm_system: SlurmSystem, megatron_run_tr_no_data: TestRun | ||
| ) -> None: | ||
| strategy = MegatronRunReportGenerationStrategy(slurm_system, megatron_run_tr_no_data) | ||
| assert not strategy.can_handle_directory() | ||
|
|
||
|
|
||
| def test_megatron_run_extract_and_generate_report(slurm_system: SlurmSystem, megatron_run_tr: TestRun) -> None: | ||
| strategy = MegatronRunReportGenerationStrategy(slurm_system, megatron_run_tr) | ||
| strategy.generate_report() | ||
| report_path = megatron_run_tr.output_path / "megatron_run_report.txt" | ||
| assert report_path.is_file() | ||
| content = report_path.read_text() | ||
| assert "Iteration Time (ms)" in content | ||
| assert "TFLOP/s per GPU" in content | ||
| assert "avg:" in content | ||
| assert "median:" in content | ||
| assert "min:" in content | ||
| assert "max:" in content | ||
| assert "std:" in content | ||
|
|
||
|
|
||
| def test_megatron_run_get_metric_iteration_time(slurm_system: SlurmSystem, megatron_run_tr: TestRun) -> None: | ||
| strategy = MegatronRunReportGenerationStrategy(slurm_system, megatron_run_tr) | ||
| # Expected: avg of [15800.0, 15639.0, 15448.5] | ||
| expected_avg = (15800.0 + 15639.0 + 15448.5) / 3 | ||
| metric = strategy.get_metric("iteration-time") | ||
| assert abs(metric - expected_avg) < 0.1 | ||
|
|
||
|
|
||
| def test_megatron_run_get_metric_default(slurm_system: SlurmSystem, megatron_run_tr: TestRun) -> None: | ||
| strategy = MegatronRunReportGenerationStrategy(slurm_system, megatron_run_tr) | ||
| # Default should return iteration-time | ||
| expected_avg = (15800.0 + 15639.0 + 15448.5) / 3 | ||
| metric = strategy.get_metric("default") | ||
| assert abs(metric - expected_avg) < 0.1 | ||
|
|
||
|
|
||
| def test_megatron_run_get_metric_tflops(slurm_system: SlurmSystem, megatron_run_tr: TestRun) -> None: | ||
| strategy = MegatronRunReportGenerationStrategy(slurm_system, megatron_run_tr) | ||
| # Expected: avg of [490.0, 494.6, 500.6] | ||
| expected_avg = (490.0 + 494.6 + 500.6) / 3 | ||
| metric = strategy.get_metric("tflops-per-gpu") | ||
| assert abs(metric - expected_avg) < 0.1 | ||
|
|
||
|
|
||
| def test_megatron_run_get_metric_invalid(slurm_system: SlurmSystem, megatron_run_tr: TestRun) -> None: | ||
| strategy = MegatronRunReportGenerationStrategy(slurm_system, megatron_run_tr) | ||
| metric = strategy.get_metric("invalid-metric") | ||
| assert metric == METRIC_ERROR | ||
|
|
||
|
|
||
| def test_megatron_run_get_metric_no_data(slurm_system: SlurmSystem, megatron_run_tr_no_data: TestRun) -> None: | ||
| strategy = MegatronRunReportGenerationStrategy(slurm_system, megatron_run_tr_no_data) | ||
| metric = strategy.get_metric("iteration-time") | ||
| assert metric == METRIC_ERROR | ||
|
|
||
|
|
||
| def test_megatron_run_metrics_class_var() -> None: | ||
| assert MegatronRunReportGenerationStrategy.metrics == ["default", "iteration-time", "tflops-per-gpu"] | ||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if taking the last 10 iterations is the most relevant. What if the training has some ups and downs (as I already saw). Maybe just skipping the warmup, so say the 20 first iterations is enough ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, skipping the warmup stage makes more sense, have updated to skipping the first 20 iterations. Originally was following the format in Megatron-Bridge report. Maybe later need to unify the formats for computing statistics.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The last 10 iteration is what the GPU perf team uses. I have seen those runs on IB clusters and mostly towards the end it remains stable.