Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
434d2f5
PullRequest: 353 [Lite] Add gradient checkpointing to FSDPEngine
Jul 14, 2025
d8038b2
PullRequest: 354 [lite] GRPO pre-commit: minor changes in FSDP engine
garrett4wade Jul 14, 2025
724628e
PullRequest: 355 [Lite] GRPO pre-commit 2: Refactor RemoteSGLangEngin…
garrett4wade Jul 14, 2025
8a15551
PullRequest: 357 [lite] GRPO pre-commit 3: Fix typos and experiment u…
garrett4wade Jul 14, 2025
3f95968
PullRequest: 358 [lite] Support GRPO training locally with the GSM8k …
garrett4wade Jul 15, 2025
c75dcaf
merge
garrett4wade Jul 16, 2025
b2bd639
PullRequest: 368 [lite] Refactor train engine after merging contribut…
garrett4wade Jul 16, 2025
b56f599
PullRequest: 371 [lite] [fix] fix misc bugs in GRPO implementation
garrett4wade Jul 16, 2025
ddabd9c
PullRequest: 370 [lite] Add Slurm Launcher and Ray Launcher
Jul 21, 2025
2f1b679
PullRequest: 392 [lite] Fix several bugs regarding RL learning and ad…
garrett4wade Jul 21, 2025
9c4da33
Merge branch 'lite' of https://github.com/inclusionAI/AReaL into lite
garrett4wade Jul 21, 2025
ab5db3f
.
garrett4wade Jul 21, 2025
4dd4a22
.
garrett4wade Jul 21, 2025
21bd032
PullRequest: 408 [Feature] Bump SGLang version to v0.4.9.post2
garrett4wade Jul 24, 2025
06d9370
PullRequest: 422 [lite] Fix tests and scripts after updating sgl to 0…
garrett4wade Jul 24, 2025
d6dbd90
PullRequest: 423 [lite] Remove the boba example for github release.
garrett4wade Jul 24, 2025
041121d
merge
garrett4wade Jul 24, 2025
be51586
Merge branch 'lite' of https://github.com/inclusionAI/AReaL into lite
garrett4wade Jul 24, 2025
b4b2018
Merge branch 'lite' of https://code.alipay.com/inclusionAI/AReaL into…
garrett4wade Jul 24, 2025
209aec6
update readme
garrett4wade Jul 24, 2025
8750616
Merge branch 'lite' of https://github.com/inclusionAI/AReaL into lite
garrett4wade Jul 24, 2025
86ee687
PullRequest: 431 [Fix] Fix environment of lite
garrett4wade Jul 25, 2025
04c8da4
PullRequest: 440 [FIX] fix update weight from disk
fishcrap Jul 25, 2025
7998055
PullRequest: 442 [lite] Refactor `RemoteSGLangEngine` into two parts:…
Jul 29, 2025
e825b99
PullRequest: 456 [lite] [Bug] Use `ProcessPoolExecutor` to calculate …
Jul 31, 2025
7a77fab
PullRequest: 460 [lite][fix] add a warning when reward computation ti…
garrett4wade Jul 31, 2025
7d1c852
PullRequest: 465 [lite][fix] Fix issues raised by tsao
garrett4wade Jul 31, 2025
58395f4
Merge branch 'lite' of https://code.alipay.com/inclusionAI/AReaL into…
garrett4wade Aug 1, 2025
8fb7564
PullRequest: 463 [FEAT] add config converter
fishcrap Aug 1, 2025
a962eb6
PullRequest: 466 [lite] Add seeding in training scripts and pad to ma…
garrett4wade Aug 1, 2025
c9cac38
PullRequest: 467 [lite][fix] remove logging functionality in stats_lo…
garrett4wade Aug 1, 2025
63a9628
rename arealite to areal
garrett4wade Aug 1, 2025
8bd2b4c
rename arealite to areal
garrett4wade Aug 1, 2025
cc8ac71
.
garrett4wade Aug 1, 2025
1518055
local experiment run
garrett4wade Aug 1, 2025
7229598
.
garrett4wade Aug 1, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
name: Test AReaLite
name: Test AReaL

on:
pull_request:
branches: [ lite ]
paths:
- .github/workflows/test-arealite.yml
- arealite/**
- .github/workflows/test-areal.yml
- areal/**
- ci/**
workflow_dispatch:

jobs:
test-arealite:
test-areal:
environment:
name: AReaLite-unittests
name: AReaL-unittests
runs-on: gpu
steps:
- uses: actions/checkout@v4

- run: bash ./ci/test_arealite.sh
- run: bash ./ci/test_areal.sh
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ repos:
- -r
- --remove-all-unused-imports
- --remove-unused-variables
files: ^(arealite/|examples/arealite/).*\.py$
files: ^(areal/|examples/lite/).*\.py$

- repo: https://github.com/pycqa/isort
rev: 5.13.2
Expand Down
30 changes: 15 additions & 15 deletions arealite/README.md → areal/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# AReaLite Design Doc
# AReaL-Lite Design Doc

## TL;DR

Follow our [step-by-step code walk-through](../docs/arealite/gsm8k_grpo.md) to
immediately get started with AReaLite!
Follow our [step-by-step code walk-through](../docs/areal/gsm8k_grpo.md) to immediately
get started with AReaL-Lite!

## Motivation

Expand All @@ -26,13 +26,13 @@ possible to achieve comparable efficiency with significantly fewer lines of code
presents an ideal opportunity to redesign the API and distill the massive codebase into
something clean and maintainable. Rather than pursuing maximum efficiency, our goal is
to deliver 90% of AReaL's functionality while dramatically reducing code complexity and
user burden. This philosophy drives AReaLite — the lightweight version of AReaL.
user burden. This philosophy drives AReaL-Lite — the lightweight version of AReaL.

AReaLite serves as the first phase in AReaL's broader refactoring initiative. It
AReaL-Lite serves as the first phase in AReaL's broader refactoring initiative. It
functions both as a standalone training library with intuitive interfaces and as the
foundation for AReaL's future core API definitions. The plan is to transform AReaL's
current worker-based architecture into an AI-centric architecture similar to AReaLite,
where AReaL will **extend** AReaLite's APIs and implementations to support additional
current worker-based architecture into an AI-centric architecture similar to AReaL-Lite,
where AReaL will **extend** AReaL-Lite's APIs and implementations to support additional
backends for efficient large-scale training.

## Design Principles
Expand All @@ -55,7 +55,7 @@ Our design is guided by seven core principles:
### Core Directory Structure

```
arealite/
areal/
├── api/ # Abstract interfaces and dataclasses
├── engine/ # Training and inference engines
├── launcher/ # Launcher for different backends
Expand Down Expand Up @@ -97,17 +97,17 @@ pipelines:
- **`workflow/rlvr.py`**: RLVR workflow that utilizes an `InferenceEngine` to sample
multiple responses for each prompt

#### 4. Entry Point Layer (`examples/arealite/`)
#### 4. Entry Point Layer (`examples/lite/`)

The entry point layer composes customization layer implementations to create complete RL
training pipelines. While we provide several reference examples, users have complete
freedom to adapt these to their specific use cases.

Entry points can be launched using launchers from `arealite/launcher/`, similar to other
Entry points can be launched using launchers from `areal/launcher/`, similar to other
distributed launch tools like `torchrun`:

```bash
python3 -m arealite.launcher.ray entrypoint.py --config my-config.yaml
python3 -m areal.launcher.ray entrypoint.py --config my-config.yaml
```

## Usage Examples
Expand All @@ -119,17 +119,17 @@ parameters for hyperparameter searches or other experimental needs:

```bash
# Launch with Ray launcher: 4 nodes (4 GPUs each), 3 nodes for generation, 1 node for training
python3 -m arealite.launcher.ray examples/arealite/gsm8k_grpo.py \
--config examples/arealite/configs/gsm8k_grpo.yaml \
python3 -m areal.launcher.ray examples/lite/gsm8k_grpo.py \
--config examples/lite/configs/gsm8k_grpo.yaml \
experiment_name=<your_experiment_name> \
trial_name=<your_trial_name> \
allocation_mode=sglang.d12p1t1+d4p1t1 \
cluster.n_nodes=4 \
cluster.n_gpus_per_node=4

# Launch with Slurm launcher: 16 nodes (8 GPUs each), 12 nodes for generation, 4 nodes for training
python3 -m arealite.launcher.slurm examples/arealite/gsm8k_grpo.py \
--config examples/arealite/configs/gsm8k_grpo.yaml \
python3 -m areal.launcher.slurm examples/lite/gsm8k_grpo.py \
--config examples/lite/configs/gsm8k_grpo.yaml \
experiment_name=<your_experiment_name> \
trial_name=<your_trial_name> \
allocation_mode=sglang.d96p1t1+d32p1t1 \
Expand Down
11 changes: 10 additions & 1 deletion arealite/api/cli_args.py → areal/api/cli_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from hydra import initialize as hydra_init
from omegaconf import MISSING, OmegaConf

from arealite.utils.fs import get_user_tmp
from areal.utils.fs import get_user_tmp


@dataclass
Expand Down Expand Up @@ -189,6 +189,15 @@ class TrainEngineConfig:
)
# Runtime microbatch limit
mb_spec: MicroBatchSpec = field(default_factory=MicroBatchSpec)
pad_to_maximum: bool = field(
default=False,
metadata={
"help": (
"Whether to pad each microbatch to the length upper bound specified by mb_spec. "
"Can reduce memory fragmentation but slow down training."
)
},
)

# Training Backend Configuration
disable_dropout: bool = field(default=False)
Expand Down
4 changes: 2 additions & 2 deletions arealite/api/engine_api.py → areal/api/engine_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from tensordict import TensorDict
from torchdata.stateful_dataloader import StatefulDataLoader

from arealite.api.io_struct import (
from areal.api.io_struct import (
FinetuneSpec,
LLMRequest,
LLMResponse,
Expand All @@ -18,7 +18,7 @@
)

if TYPE_CHECKING:
from arealite.api.workflow_api import RolloutWorkflow
from areal.api.workflow_api import RolloutWorkflow


@dataclass
Expand Down
File renamed without changes.
19 changes: 12 additions & 7 deletions arealite/api/io_struct.py → areal/api/io_struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@
from dataclasses import dataclass, field
from typing import TYPE_CHECKING, Any, Dict, List, Literal, Optional, Tuple

import torch
from gymnasium.core import ActType, ObsType
from PIL.Image import Image as ImageObject
from transformers import AutoProcessor, PreTrainedTokenizerFast

from arealite.api.cli_args import GenerationHyperparameters, SaverConfig
from arealite.utils.network import find_free_ports, gethostip
from areal.api.cli_args import GenerationHyperparameters, SaverConfig
from areal.utils.network import find_free_ports, gethostip

if TYPE_CHECKING:
from arealite.api.engine_api import TrainEngine
from areal.api.engine_api import TrainEngine


@dataclass
Expand Down Expand Up @@ -81,6 +79,7 @@ def steps_per_epoch(self):


class AllocationType(enum.Enum):
COLOCATE = 0
DECOUPLED_vLLM = 1
DECOUPLED_SGLANG = 2

Expand Down Expand Up @@ -124,11 +123,17 @@ def train_world_size(self) -> int:

@classmethod
def from_str(cls, allocation_mode: str):
alloc_decoupled = AllocationMode.extract_decoupled_alloc(allocation_mode)
if "vllm" in allocation_mode:
alloc_decoupled = AllocationMode.extract_decoupled_alloc(allocation_mode)
return cls(AllocationType.DECOUPLED_vLLM, alloc_decoupled)
elif "sglang" in allocation_mode:
alloc_decoupled = AllocationMode.extract_decoupled_alloc(allocation_mode)
return cls(AllocationType.DECOUPLED_SGLANG, alloc_decoupled)
else:
return cls(
AllocationType.COLOCATE,
AllocationMode.extract_parallelism_strategy(allocation_mode),
)
raise NotImplementedError(f"Failed to parse allocation: {allocation_mode}")

@staticmethod
Expand Down Expand Up @@ -196,7 +201,7 @@ def from_disk(
cls,
saver_config: SaverConfig,
) -> "WeightUpdateMeta":
from arealite.utils.saver import Saver
from areal.utils.saver import Saver

path = os.path.join(
Saver.get_save_checkpoint_root(saver_config),
Expand Down
File renamed without changes.
14 changes: 7 additions & 7 deletions arealite/api/workflow_api.py → areal/api/workflow_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@
from tensordict import TensorDict
from torchdata.stateful_dataloader import StatefulDataLoader

from arealite.api.cli_args import InferenceEngineConfig
from arealite.api.engine_api import InferenceEngine
from arealite.api.io_struct import RolloutStat
from arealite.utils.data import concat_padded_tensors
from areal.api.cli_args import InferenceEngineConfig
from areal.api.engine_api import InferenceEngine
from areal.api.io_struct import RolloutStat
from areal.utils.data import concat_padded_tensors
from realhf.base import logging

if TYPE_CHECKING:
from arealite.api.engine_api import InferenceEngine
from areal.api.engine_api import InferenceEngine

logger = logging.getLogger("arealite.workflow_api")
logger = logging.getLogger("areal.workflow_api")


ROLLOUT_POLL_WAIT_TIME = 0.05
Expand All @@ -33,7 +33,7 @@ async def arun_episode(
) -> TensorDict:
"""Run a single episode of the workflow.

See concrete example implementations under the `arealite/workflow` directory.
See concrete example implementations under the `areal/workflow` directory.
"""
raise NotImplementedError()

Expand Down
12 changes: 4 additions & 8 deletions arealite/dataset/__init__.py → areal/dataset/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,21 @@ def get_custom_dataset(
):

if "gsm8k" in path and type == "sft":
from examples.arealite.dataset.gsm8k import get_gsm8k_sft_dataset
from areal.dataset.gsm8k import get_gsm8k_sft_dataset

return get_gsm8k_sft_dataset(path, split, tokenizer, rank, world_size, **kwargs)
elif "gsm8k" in path and type == "rl":
from examples.arealite.dataset.gsm8k import get_gsm8k_rl_dataset
from areal.dataset.gsm8k import get_gsm8k_rl_dataset

return get_gsm8k_rl_dataset(path, split, rank, world_size, **kwargs)
elif "clevr_count_70k" in path and type == "sft":
from examples.arealite.dataset.clevr_count_70k import (
get_clevr_count_70k_sft_dataset,
)
from areal.dataset.clevr_count_70k import get_clevr_count_70k_sft_dataset

return get_clevr_count_70k_sft_dataset(
path, split, processor, rank, world_size, **kwargs
)
elif "clevr_count_70k" in path and type == "rl":
from examples.arealite.dataset.clevr_count_70k import (
get_clevr_count_70k_rl_dataset,
)
from areal.dataset.clevr_count_70k import get_clevr_count_70k_rl_dataset

return get_clevr_count_70k_rl_dataset(
path, split, processor, rank, world_size, **kwargs
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datasets import Dataset, load_dataset
from datasets import load_dataset
from datasets.distributed import split_dataset_by_node


Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
get_linear_schedule_with_warmup,
)

from arealite.api.cli_args import TrainEngineConfig
from arealite.api.engine_api import FinetuneSpec, TrainEngine
from arealite.utils.data import (
from areal.api.cli_args import TrainEngineConfig
from areal.api.engine_api import FinetuneSpec, TrainEngine
from areal.utils.data import (
MicroBatchList,
amend_position_ids,
pack_tensor_dict,
Expand All @@ -30,8 +30,8 @@
unpack_sequence,
unsqueeze_mb_list,
)
from arealite.utils.fsdp import get_cosine_schedule_with_warmup
from arealite.utils.model import VALID_VISION_MODELS, disable_dropout_in_model
from areal.utils.fsdp import get_cosine_schedule_with_warmup
from areal.utils.model import VALID_VISION_MODELS, disable_dropout_in_model
from realhf.api.core.data_api import load_hf_processor_and_tokenizer, load_hf_tokenizer
from realhf.base import constants, logging

Expand Down Expand Up @@ -259,11 +259,16 @@ def prepare_mb_list(self, input_: TensorDict) -> MicroBatchList:
input_ = amend_position_ids(input_)

mb_list = split_padded_tensor_dict_into_mb_list(input_, self.config.mb_spec)
mb_list.mbs = [pack_tensor_dict(mb) for mb in mb_list.mbs]
mb_list = pad_mb_list(
mb_list,
pad_value=0.0,
pad_to_maximum=self.config.pad_to_maximum,
)
logger.info(
f"Microbatch #tokens (rank {dist.get_rank()}): {mb_list.group_lens}"
f"Microbatch #tokens (rank {dist.get_rank()}): {mb_list.group_lens}, "
f"padded to: {mb_list.padded_to_lengths}, padding lengths: {mb_list.padding_lengths}"
)
mb_list.mbs = [pack_tensor_dict(mb) for mb in mb_list.mbs]
mb_list = pad_mb_list(mb_list, pad_value=0.0)
# NOTE: We unsqueeze here because huggingface transformer models requires
# packed input to be of shape [1, total_seqlen].
mb_list = unsqueeze_mb_list(mb_list)
Expand Down
17 changes: 8 additions & 9 deletions arealite/engine/fsdp_engine.py → areal/engine/fsdp_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,20 @@
)
from transformers import AutoProcessor, PreTrainedTokenizerFast

from arealite.api.cli_args import TrainEngineConfig
from arealite.api.engine_api import FinetuneSpec
from arealite.api.io_struct import ParamSpec, SaveLoadMeta, WeightUpdateMeta
from arealite.engine.base_hf_engine import BaseHFEngine
from arealite.utils.distributed import init_custom_process_group
from arealite.utils.fsdp import (
from areal.api.cli_args import TrainEngineConfig
from areal.api.engine_api import FinetuneSpec
from areal.api.io_struct import ParamSpec, SaveLoadMeta, WeightUpdateMeta
from areal.engine.base_hf_engine import BaseHFEngine
from areal.utils.distributed import init_custom_process_group
from areal.utils.fsdp import (
CPUOffloadPolicy,
MixedPrecisionPolicy,
apply_fsdp2,
create_fsdp_device_mesh,
fsdp2_clip_grad_norm_,
fsdp2_load_full_state_dict,
)
from arealite.utils.save_load import get_state_dict_from_repo_id_or_path
from realhf.api.core.data_api import load_hf_processor_and_tokenizer
from areal.utils.save_load import get_state_dict_from_repo_id_or_path
from realhf.base import logging, name_resolve, names, pkg_version

logger = logging.getLogger("FSDPEngine")
Expand All @@ -46,7 +45,7 @@ def initialize(self, addr: str | None, ft_spec: FinetuneSpec | None):
assert addr is None, "FSDPEngine does not support remote initialization."
assert pkg_version.is_version_greater_or_equal(
"torch", "2.4.0"
), f"arealite only supports FSDP2, which requires torch>=2.4.0"
), f"areal only supports FSDP2, which requires torch>=2.4.0"

self.create_process_group()
self.create_device_model()
Expand Down
10 changes: 5 additions & 5 deletions arealite/engine/ppo/actor.py → areal/engine/ppo/actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import torch
from tensordict import TensorDict

from arealite.api.cli_args import MicroBatchSpec, PPOActorConfig
from arealite.api.engine_api import TrainEngine
from arealite.engine.fsdp_engine import FSDPEngine
from arealite.utils.data import split_padded_tensor_dict_into_mb_list
from arealite.utils.functional import (
from areal.api.cli_args import MicroBatchSpec, PPOActorConfig
from areal.api.engine_api import TrainEngine
from areal.engine.fsdp_engine import FSDPEngine
from areal.utils.data import split_padded_tensor_dict_into_mb_list
from areal.utils.functional import (
gather_logprobs,
gather_logprobs_entropy,
masked_normalization,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
import torch.utils.data
from tensordict import TensorDict

from arealite.api.cli_args import TrainEngineConfig
from arealite.api.engine_api import TrainEngine
from arealite.engine.fsdp_engine import FSDPEngine
from arealite.utils.functional import gather_logprobs
from areal.api.cli_args import TrainEngineConfig
from areal.api.engine_api import TrainEngine
from areal.engine.fsdp_engine import FSDPEngine
from areal.utils.functional import gather_logprobs
from realhf.base import stats_tracker


Expand Down
Loading
Loading