Skip to content

Fix Megatron teacher server startup crash (SampleManager.register_training_actors) - #2589

Open
Davids048 wants to merge 1 commit into
THUDM:mainfrom
Davids048:fix/megatron-server-register-actors
Open

Davids048 wants to merge 1 commit into
THUDM:mainfrom
Davids048:fix/megatron-server-register-actors

Conversation

@Davids048

Copy link
Copy Markdown

Summary

Launching the standalone Megatron teacher server (python -m slime.backends.megatron_utils.server.megatron_server)
with default arguments always crashes during startup. It fails before loading model weights or opening its HTTP port:

AttributeError: 'ActorHandle' object has no attribute 'register_training_actors'

This PR adds SampleManager.register_training_actors so RayTrainGroup can register actors when the teacher server
starts. It also adds a CPU unit test in CI so future changes do not break this path again.

Root Cause

  1. In slime/ray/actor_group.py, whenever a rollout manager is provided, RayTrainGroup._allocate_gpus_for_actor()
    calls self._rollout_manager.register_training_actors.remote(self.role, self._actor_handlers, self.args). It then
    reads update_weight_start_version from the returned dictionary.
  2. In slime/backends/megatron_utils/server/megatron_server.py, launch() passes its SampleManager actor as the
    rollout manager to create_training_models(). However, SampleManager never implemented
    register_training_actors.
  3. PR Support manual Megatron restarts with retained serving #2444 ("Support manual Megatron restarts with retained serving") added the register_training_actors call to
    RayTrainGroup. However, megatron_server.py was not updated, and CI only tested argument parsing
    (tests/utils/test_megatron_server_arguments.py). As a result, the standalone teacher server has crashed on every
    launch since PR Support manual Megatron restarts with retained serving #2444 (including v0.4.0).

Fix

  • slime/backends/megatron_utils/server/megatron_server.py: Add
    SampleManager.register_training_actors(self, role, actors, configuration) returning
    {"update_weight_start_version": getattr(self.args, "update_weight_start_version", 0)}.
    • The teacher server does not use a serving owner or training recovery. Therefore, returning the configured
      update_weight_start_version (or 0 by default) matches what RolloutManager.register_training_actors returns
      when neither is active.

Tests and CI

  • Added: tests/utils/test_megatron_server_startup.py (NUM_GPUS = 0, 5 CPU test cases, with an
    if __name__ == "__main__": entrypoint for running directly in CI with python).
    • Checks that SampleManager.register_training_actors defaults update_weight_start_version to 0 when unset, and
      keeps the configured value when set.
    • Calls RayTrainGroup.create(rollout_manager=...) with a real SampleManager instance, using a small wrapper that
      exposes .remote(...) calls and mocked Ray workers so no GPU or Ray cluster is needed. It checks that registration
      succeeds and passes update_weight_start_version to worker initialization and RayTrainGroup._disk_weight_version.
  • CI Registration: Added {'test_file': 'utils/test_megatron_server_startup.py', 'num_gpus': 0} under
    cpu-unittest in .github/workflows/pr-test.yml.j2, and regenerated .github/workflows/pr-test.yml with
    python .github/workflows/generate_github_workflows.py. Both this new file and
    tests/utils/test_megatron_server_arguments.py are CPU-only (NUM_GPUS = 0).
  • Regression Protection: Previously, CI only tested CLI argument parsing for the teacher server and never tested
    startup registration between RayTrainGroup and SampleManager. Without this fix, all 5 test cases fail with
    AttributeError. As a result, CI will now catch future changes in RayTrainGroup that break SampleManager.

Verification

Local Checks

Run from the repository root:

python tests/utils/test_megatron_server_startup.py          # 5 passed (all 5 fail with AttributeError before this fix)
pytest tests/utils/test_megatron_server_startup.py          # 5 passed
python tests/utils/test_megatron_server_arguments.py        # 3 passed
pytest tests/utils/test_megatron_server_arguments.py        # 3 passed
python .github/workflows/generate_github_workflows.py       # regenerated with no further diff
uvx ruff==0.14.7 check slime/backends/megatron_utils/server/megatron_server.py tests/utils/test_megatron_server_startup.py
uvx autoflake==2.0.2 --check --remove-all-unused-imports slime/backends/megatron_utils/server/megatron_server.py tests/utils/test_megatron_server_startup.py
uvx isort==5.13.2 --check --profile=black --line-length 119 --py 310 slime/backends/megatron_utils/server/megatron_server.py tests/utils/test_megatron_server_startup.py
uvx black==24.3.0 --check --line-length 119 slime/backends/megatron_utils/server/megatron_server.py tests/utils/test_megatron_server_startup.py

GPU Verification

Verified on 1 GPU with Qwen2.5-0.5B-Instruct using the default launch arguments for the teacher server:

  • Before fix: Launch crashed every time during startup with
    AttributeError: 'ActorHandle' object has no attribute 'register_training_actors' at slime/ray/actor_group.py:139
    and never opened its HTTP port.
  • After fix: The teacher server started cleanly and returned HTTP 200 on /generate across 3 consecutive GPU runs.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant