Skip to content

Commit b12eb3b

Browse files
[megatron] fix: Fix error in megatron workers (#4832)
### What does this PR do? There is a bug in megatron_workers.py, 745 line is redundant and introduces a bug. It overwrites the estimated_flops and promised_flops calculated on lines 742-744. Also, the condition "vl" in func.__name__ is brittle as it relies on a naming convention. This could lead to silent miscalculations of MFU if a new vision-language model's estimation function is named differently. A more robust approach is to attempt calling the function with the extra arguments and handle the TypeError if it doesn't support them. ### Checklist Before Starting - [ ] Search for similar PRs. Paste at least one query link here: ... - [ ] Format the PR title as `[{modules}] {type}: {description}` (This will be checked by the CI) - `{modules}` include `fsdp`, `megatron`, `sglang`, `vllm`, `rollout`, `trainer`, `ci`, `training_utils`, `recipe`, `hardware`, `deployment`, `ray`, `worker`, `single_controller`, `misc`, `perf`, `model`, `algo`, `env`, `tool`, `ckpt`, `doc`, `data`, `cfg`, `reward` - If this PR involves multiple modules, separate them with `,` like `[megatron, fsdp, doc]` - `{type}` is in `feat`, `fix`, `refactor`, `chore`, `test` - If this PR breaks any API (CLI arguments, config, function signature, etc.), add `[BREAKING]` to the beginning of the title. - Example: `[BREAKING][fsdp, megatron] feat: dynamic batching` ### Test > For changes that can not be tested by CI (e.g., algorithm implementation, new model support), validate by experiment(s) and show results like training curve plots, evaluation results, etc. ### API and Usage Example > Demonstrate how the API changes if any, and provide usage example(s) if possible. ```python # Add code snippet or script demonstrating how to use this ``` ### Design & Code Changes > Demonstrate the high-level design if this PR is complex, and list the specific changes. ### Checklist Before Submitting > [!IMPORTANT] > Please check all the following items before requesting a review, otherwise the reviewer might deprioritize this PR for review. - [ ] Read the [Contribute Guide](https://github.com/volcengine/verl/blob/main/CONTRIBUTING.md). - [ ] Apply [pre-commit checks](https://github.com/volcengine/verl/blob/main/CONTRIBUTING.md#code-linting-and-formatting): `pre-commit install && pre-commit run --all-files --show-diff-on-failure --color=always` - [ ] Add / Update [the documentation](https://github.com/volcengine/verl/tree/main/docs). - [ ] Add unit or end-to-end test(s) to [the CI workflow](https://github.com/volcengine/verl/tree/main/.github/workflows) to cover all the code. If not feasible, explain why: ... - [ ] Once your PR is ready for CI, send a message in [the `ci-request` channel](https://verl-project.slack.com/archives/C091TCESWB1) in [the `verl` Slack workspace](https://join.slack.com/t/verl-project/shared_invite/zt-3855yhg8g-CTkqXu~hKojPCmo7k_yXTQ). (If not accessible, please try [the Feishu group (飞书群)](https://applink.larkoffice.com/client/chat/chatter/add_by_link?link_token=772jd4f1-cd91-441e-a820-498c6614126a).) - [ ] If your PR is related to the `recipe` submodule, please also update the reference to the submodule commit via `git submodule update --remote` or `cd recipe && git pull origin main`.
1 parent 67a127b commit b12eb3b

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

verl/utils/flops_counter.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import inspect
16+
1517
import torch
1618
from transformers import PretrainedConfig
1719

@@ -540,8 +542,8 @@ def estimate_flops(self, batch_seqlens, delta_time, **kargs):
540542
"""
541543
tokens_sum = sum(batch_seqlens)
542544
func = ESTIMATE_FUNC.get(self.config.model_type, _estimate_unknown_flops)
543-
images_seqlens = kargs.get("images_seqlens", None)
544-
if images_seqlens is not None and "vl" in func.__name__:
545+
sig = inspect.signature(func)
546+
if any(p.kind == inspect.Parameter.VAR_KEYWORD for p in sig.parameters.values()):
545547
estimated_flops = func(self.config, tokens_sum, batch_seqlens, delta_time, **kargs)
546548
else:
547549
estimated_flops = func(self.config, tokens_sum, batch_seqlens, delta_time)

verl/workers/megatron_workers.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,6 @@ def update_actor(self, data: DataProto):
742742
estimated_flops, promised_flops = self.flops_counter.estimate_flops(
743743
global_num_tokens, delta_time, images_seqlens=images_seqlens
744744
)
745-
estimated_flops, promised_flops = self.flops_counter.estimate_flops(global_num_tokens, delta_time)
746745
metrics["perf/mfu/actor"] = estimated_flops * self.config.actor.ppo_epochs / promised_flops / self.world_size
747746
metrics["perf/max_memory_allocated_gb"] = get_torch_device().max_memory_allocated() / (1024**3)
748747
metrics["perf/max_memory_reserved_gb"] = get_torch_device().max_memory_reserved() / (1024**3)

0 commit comments

Comments
 (0)