Open
Conversation
c1abe2e to
a1b8efc
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
We have a lot of similar training code implemented differently across the local and serverless backends. This makes it hard to maintain.
We should keep the training code in ART and import it into the serverless backend.
This PR implements that change.
Mental Model
There are 3 layers:
The refactor mostly changed layer 3, and a small part of layer 1.
Before, the same Megatron execution logic existed in two places:
train.py:1.
Those two scripts both did the same kinds of work:
The serverless worker also had its own separate SFT loop.
There was also smaller duplication at the ART backend layer:
Both of those built RL config objects and aggregated training metrics separately.
So before, changing RL training logic meant touching multiple files.
How It Works Now
Now the shared Megatron execution lives in one ART module:
That module owns the actual training process:
The wrappers are now thin:
The important design choice is that offload/reload stayed outside the shared runner:
packages/art/megatron/train.py:41.
So the shared code is “training logic only”, and the local-only memory management stays local-only.
At the backend layer, the shared RL config/metrics glue now lives in .venv/lib/python3.12/site-packages/art/_backend_training.py:15.
Both .venv/lib/python3.12/site-packages/art/local/backend.py:613 and .venv/lib/python3.12/site-packages/art/serverless/backend.py:260 use it.
Current End-to-End Flows
Local RL with ART + Megatron:
python3.12/site-packages/art/megatron/service.py:209.
calls .venv/lib/python3.12/site-packages/art/megatron/shared.py:113.
python3.12/site-packages/art/megatron/service.py:271.
Serverless RL:
backend.py:193.
backend.py:319 using the client defined at .venv/lib/python3.12/site-packages/art/serverless/client.py:183.
megatron_trainer.py:97.
shared.py:113.
Serverless SFT:
The server workflow downloads the artifact and tokenizes it into SFTBatch objects in app/temporal/workflows/training_workflows.py:825.
The repo’s MegatronTrainer.train_sft() writes the tokenized batches to disk and writes an SFT job file at trainers/megatron_trainer.py:149.
The repo worker megatron/train.py:42 dispatches to .venv/lib/python3.12/site-packages/art/megatron/shared.py:230.
RL backend config/metric aggregation is shared in one place.