feat: add Bailing V3 SWE SFT support - #1598
Conversation
Port the reviewed internal implementation to the public main branch while preserving newer upstream engine behavior. Key changes: - Add Bailing V3 KDA, gated MLA, and MoE model support - Add SWE SFT dataset loading and cache handling - Add focused model, loader, and dataset tests Refs: inclusionAI/AReaL#2188 Signed-off-by: chucai.dzq <chucai.dzq@alibaba-inc.com>
b51bfc5 to
c3f22f9
Compare
Separate message processing, tokenization, pipeline orchestration, and CLI code so each concern can evolve without growing a single dataset module. Signed-off-by: chucai.dzq <chucai.dzq@alibaba-inc.com>
Port the follow-up SWE SFT fixes from swe-dev so Bailing V3 adaptive chat templates use structural assistant masks and consistent thinking modes. Signed-off-by: chucai.dzq <chucai.dzq@alibaba-inc.com>
Prevent collection-time stubs from replacing the real areal.dataset package for subsequent data-service tests.
| # Precision-alignment dumps (AReaL-friend tools/precision-alignment): | ||
| # when AREAL_DUMP_ROUTING is set, enable megatron RouterReplay | ||
| # recording so MoE expert indices can be captured during forward. | ||
| if os.environ.get("AREAL_DUMP_ROUTING", "") and hasattr( |
There was a problem hiding this comment.
Is this part of R3 support? It's inappropriate to appear here, suggesting it should be removed.
There was a problem hiding this comment.
Removed in 6a1af81. This PR no longer enables RouterReplay or any precision-alignment routing dump behavior.
| ) | ||
|
|
||
| def lr_scheduler_step(self): | ||
| if os.environ.get("AREAL_DUMP_ROUTING", "") or os.environ.get( |
There was a problem hiding this comment.
the same as before
There was a problem hiding this comment.
Removed in 6a1af81. lr_scheduler_step() is restored to the normal scheduler path with no dump-related bypass.
|
|
||
| # Precision-alignment routing dump: record MoE expert indices for the | ||
| # first microbatch via megatron RouterReplay (enabled in initialize). | ||
| _routing_dump_path = os.environ.get("AREAL_DUMP_ROUTING", "") |
There was a problem hiding this comment.
the same as before
There was a problem hiding this comment.
Removed in 6a1af81. The RouterReplay record setup in forward_step has been deleted.
| ), | ||
| ) | ||
|
|
||
| if _routing_dump_path and not getattr(self, "_routing_dumped", False): |
There was a problem hiding this comment.
Similarly, it needs to be removed.
There was a problem hiding this comment.
Removed in 6a1af81. The routing-record collection, CPU copies, and .pt writes have all been deleted.
|
|
||
| # Precision-alignment forward-only mode: no optimizer exists (see | ||
| # _create_optimizer), so skip zero_grad/step and run forward only. | ||
| _fwd_only = bool( |
There was a problem hiding this comment.
please remove it
There was a problem hiding this comment.
Removed in 6a1af81. train_batch() now always follows the normal zero-grad, forward/backward, and optimizer-step path; the dump-only forward mode is gone.
| def _create_optimizer(self, ft_spec: FinetuneSpec) -> None: | ||
| if self.optimizer_config is None: | ||
| return | ||
| if os.environ.get("AREAL_DUMP_ROUTING", "") or os.environ.get( |
There was a problem hiding this comment.
please remove it
There was a problem hiding this comment.
Removed in 6a1af81. _create_optimizer() no longer skips optimizer creation based on dump environment variables.
|
|
||
| # Precision-alignment logp dump: save final per-token logprobs for | ||
| # the first microbatch (last PP stage only; this branch already is). | ||
| _logp_dump_path = os.environ.get("AREAL_DUMP_LOGP", "") |
There was a problem hiding this comment.
please remove it
There was a problem hiding this comment.
Removed in 6a1af81. The per-token log-probability dump and associated CPU/file I/O have been deleted. The updated head passes both sglang and vLLM unit-test jobs.
Keep Bailing V3 support focused on production training behavior by removing out-of-scope routing and log-probability dump paths.
Place the CP zigzag unit tests under the root test pattern used by the GCP unit-test workflow.
| def _build_hf_mcore_bridge(self): | ||
| if self.bridge_cls == "mbridge": | ||
| self.bridge = mbridge.AutoBridge.from_pretrained( | ||
| hf_config = PretrainedConfig.from_pretrained( |
There was a problem hiding this comment.
PretrainedConfig.from_pretrained() creates a base PreTrainedConfig. During serialization, to_dict() replaces the instance’s model_type="bailing_hybrid" with the base class’s empty model_type. As a result, regular HF checkpoints are exported with an invalid config.json, preventing AutoConfig, inference, or subsequent training from recognizing the model.
Please use AutoConfig.from_pretrained(..., trust_remote_code=True) to retain the actual config class, or always restore the original model configuration during export. A save/load round-trip test for Bailing V3 should also be added.
Description
Add Bailing V3 (KDA + gated MLA + MoE) support to the Megatron engine and provide an SWE SFT dataset pipeline with reusable training entrypoints.
This ports the reviewed implementation from internal PR 2188 onto the latest public
main. Internal Bailing example configs were intentionally excluded because they contain private checkpoint, storage, and cluster paths. The portableexamples/swe/config.pyandexamples/swe/train_sft.pyentrypoints are included.Related Issue
Internal reference: inclusionAI/AReaL PR 2188
Type of Change
Checklist
pre-commit run --all-files)./docs/build_all.sh)main/review-prcommand/create-prBreaking Change Details (if applicable):
None expected. Existing MoE config defaults now use
Noneto preserve each model bridge default; explicit values retain override behavior.Validation
git diff --check refs/remotes/github/main...HEAD— passedhttpxuvandpre-commitare unavailable in this environmentAdditional Context
The conflict with newer public-main chunked LM-head and NPU logic in
megatron_engine.pywas resolved by retaining upstream behavior and adding the Bailing V3 bridge/routing logic alongside it.