Skip to content

refactor: unify AWEX converters and adapters across v1 and v2 - #1684

Open
sitabulaixizawaluduo wants to merge 38 commits into
mainfrom
feature/v2-awex-native-converters
Open

sitabulaixizawaluduo wants to merge 38 commits into
mainfrom
feature/v2-awex-native-converters

Conversation

@sitabulaixizawaluduo

@sitabulaixizawaluduo sitabulaixizawaluduo commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator

Description

Unify the Megatron and SGLang AWEX integrations so v1 colocated weight updates and v2 separated weight updates share adapter implementations and native AWEX model conversion.

Shared adapters

  • Centralize Megatron, SGLang, and FSDP AWEX adapters and the training/inference Protocols in areal/engine/awex/.
  • Connect v1 and v2 entry points directly to the shared adapters and remove the legacy reader/writer facades and superseded v2 adapter modules.
  • Keep NCCL group setup, metadata exchange, DTE configuration/detection, and device utilities alongside the adapters, with no imports from areal.v2 in the shared AWEX package.
  • Reuse MegatronWeightResidency for weight, optimizer, and gradient memory management.
  • Retain v1 colocated IPC transfer and v2 separated full-weight and delta-weight transfer paths.

Native conversion and metadata

  • Use AWEX's native Megatron and SGLang converters, rank extraction, and sharding metadata.
  • Pass inference converter context through the weight-update gateway to training workers before generating parameter metadata.
  • Propagate the training parameter layout to SGLang metadata generation, including an explicit HF layout for FSDP.
  • Replace duplicated conversion and metadata handling with shared adapter logic.

Type of Change

  • ♻️ Refactoring

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AwexFSDPAdapter now imports and calls batch_send_recv_by_peer, so this mock targets a symbol that no longer exists in the FSDP module. The FSDP test case raises AttributeError before reaching the barrier assertion. Please patch batch_send_recv_by_peer instead, and verify that the transfer is invoked before the Gloo completion barrier.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in a17882b. The parameterized FSDP/Megatron/SGLang test now patches batch_send_recv_by_peer, checks its arguments for both use_group settings, and asserts that the transfer returns before the Gloo completion barrier. The SGLang copy test now asserts transfer -> copy -> synchronize -> barrier. I also updated the two DTE module-loader stubs to expose the new helper.

Validation: full pre-commit, Ruff, and Python compilation passed. Unit tests were not run locally.

Comment on lines +1755 to +1764
model_config, _ = PretrainedConfig.get_config_dict(actor.path)
if model_config.get("model_type") == "qwen2" or "Qwen2ForCausalLM" in (
model_config.get("architectures") or []
):
raise ValueError(
"Qwen2/Qwen2.5 text models do not support AWEX weight updates. "
"For RL, set actor._version=v1, rollout._version=v1, and "
"actor.weight_update_mode=xccl or disk. Controller v2 is not "
"supported for these models' RL weight updates."
)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This guard also rejects Qwen2/Qwen2.5 with v2 + use_lora=True, but the existing trainer routes that configuration through disk-based adapter updates, bypassing AWEX conversion. Is there a separate incompatibility that requires rejecting this path? If not, could we scope the guard to configurations that actually select AWEX?

Comment on lines +52 to +59
for peer in sorted(ops_by_peer):
peer_ops = ops_by_peer[peer]
batch_send_recv(
send_ops=peer_ops if send_ops else [],
recv_ops=peer_ops if recv_ops else [],
blocking=True,
use_group=True,
)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is peer serialization required for the shared adapter/native converter integration to work? It appears independent of the refactor and changes the default transfer scheduling. Unless there is a demonstrated correctness or resource issue that makes it necessary, could we preserve the existing scheduling here and move this change to a separate PR with before/after measurements?

Le8r0nJames
Le8r0nJames previously approved these changes Sep 11, 2026
Share Megatron and SGLang weight-update adapters so both versions use
native AWEX conversion and sharding metadata.

Key changes:
- Consolidate v1 colocate and v2 separation adapter implementations
- Preserve legacy entry points and shared Megatron weight residency
- Forward inference converter context through the weight-update gateway
- Propagate parameter layouts between training and inference workers
- Retain full-weight and delta-weight separation transfer paths
Allow metadata fetches to honor the gateway initialization timeout
instead of always using the aiohttp default.

Key changes:
- Extend training and inference adapter contracts compatibly
- Forward the timeout through FSDP, Megatron, and SGLang adapters
- Apply the timeout to metadata HTTP requests
Merge same-name TP shards before the planner indexes parameters,
and validate inference replicas before retaining a single layout.
This avoids missing TP shards and redundant metadata distribution.

Forward the initialization timeout to separation adapters.
Use the actor request timeout for the weight-update controller and
its gateway initialization and update requests, rather than silently
falling back to the shorter internal defaults.
Bound grouped P2P concurrency to one peer per rank while preserving
AWEX's blocking device synchronization and manual-stream fallback.
Keep senders and receivers on the same deterministic peer schedule
to limit concurrent NCCL P2P traffic during full weight updates.

Key changes:
- Use peer-serialized transfers in FSDP and Megatron senders.
- Use the matching schedule in the SGLang receiver.
- Preserve v1 colocate, DTE paths, and the manual-stream fallback.
Forked workers can inherit a per-task CUDA_VISIBLE_DEVICES namespace.
Use logical device zero when that namespace already covers the server.
Keep the shared AWEX package navigable without changing transfer logic.

Key changes:
- Move this module into its responsibility-based subpackage
- Update imports and affected runtime or test-loader references together
Keep the shared AWEX package navigable without changing transfer logic.

Key changes:
- Move this module into its responsibility-based subpackage
- Update imports and affected runtime or test-loader references together
Keep the shared AWEX package navigable without changing transfer logic.

Key changes:
- Move this module into its responsibility-based subpackage
- Update imports and affected runtime or test-loader references together
Keep the shared AWEX package navigable without changing transfer logic.

Key changes:
- Move this module into its responsibility-based subpackage
- Update imports and affected runtime or test-loader references together
Keep the shared AWEX package navigable without changing transfer logic.

Key changes:
- Move this module into its responsibility-based subpackage
- Update imports and affected runtime or test-loader references together
Keep the shared AWEX package navigable without changing transfer logic.

Key changes:
- Move this module into its responsibility-based subpackage
- Update imports and affected runtime or test-loader references together
Keep the shared AWEX package navigable without changing transfer logic.

Key changes:
- Move this module into its responsibility-based subpackage
- Update imports and affected runtime or test-loader references together
Keep the shared AWEX package navigable without changing transfer logic.

Key changes:
- Move this module into its responsibility-based subpackage
- Update imports and affected runtime or test-loader references together
Keep the shared AWEX package navigable without changing transfer logic.

Key changes:
- Move this module into its responsibility-based subpackage
- Update imports and affected runtime or test-loader references together
Keep adapter tests aligned with the peer-serialized transfer helper.

Assert transfer completion before the Gloo barrier and preserve the
SGLang transfer, copy, synchronize, barrier sequence. Update the DTE
module-loader stubs to expose the same helper.
Defer peer-serialized transport to a separate PR while keeping the
shared adapter and native converter changes.

Key changes:
- Restore blocking AWEX batch_send_recv on training and inference.
- Update transfer mocks while retaining completion-order assertions.
Disk updates bypass AWEX native conversion, so the model support guard
must allow them for both controller versions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

safe-to-test Ready to run unit-tests in a PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants