Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
88faa6dc22 | ||
|
|
083b8fe9ec | ||
|
|
853208336e |
@@ -6,6 +6,10 @@ on:
|
||||
pull_request:
|
||||
types: [opened, synchronize, reopened, ready_for_review]
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
unit-tests:
|
||||
name: Unit tests
|
||||
@@ -15,15 +19,16 @@ jobs:
|
||||
uses: actions/checkout@v7
|
||||
with:
|
||||
submodules: false
|
||||
- name: Init public submodules
|
||||
run: |
|
||||
git config --global url."https://github.com/".insteadOf "git@github.com:"
|
||||
git submodule update --init --recursive -- deps/verifiers deps/renderers deps/prime-envs deps/pydantic-config
|
||||
- name: Install uv
|
||||
uses: astral-sh/setup-uv@v10.0.1
|
||||
with:
|
||||
enable-cache: true
|
||||
cache-dependency-glob: "uv.lock"
|
||||
- parallel:
|
||||
- name: Init public submodules
|
||||
run: |
|
||||
git config --global url."https://github.com/".insteadOf "git@github.com:"
|
||||
git submodule update --init --recursive -- deps/verifiers deps/renderers deps/prime-envs deps/pydantic-config
|
||||
- name: Install uv
|
||||
uses: astral-sh/setup-uv@v10.0.1
|
||||
with:
|
||||
enable-cache: true
|
||||
cache-dependency-glob: "uv.lock"
|
||||
- name: Install dependencies
|
||||
run: uv sync --all-extras --all-packages --locked
|
||||
- name: Run tests
|
||||
|
||||
@@ -5,20 +5,103 @@ on:
|
||||
branches: [main]
|
||||
pull_request:
|
||||
types: [opened, synchronize, reopened, ready_for_review]
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref }}
|
||||
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
|
||||
|
||||
jobs:
|
||||
changes:
|
||||
name: Select tests
|
||||
runs-on: ubuntu-latest
|
||||
if: github.event_name != 'pull_request' || github.event.pull_request.draft == false
|
||||
permissions:
|
||||
pull-requests: read
|
||||
outputs:
|
||||
unit: ${{ github.event_name != 'pull_request' || steps.filter.outputs.unit == 'true' }}
|
||||
integration: ${{ steps.matrix.outputs.tests }}
|
||||
eval: ${{ github.event_name != 'pull_request' || steps.filter.outputs.eval == 'true' }}
|
||||
steps:
|
||||
- uses: dorny/paths-filter@v4
|
||||
id: filter
|
||||
if: github.event_name == 'pull_request'
|
||||
with:
|
||||
filters: |
|
||||
unit:
|
||||
- &runtime
|
||||
- '.github/workflows/gpu_tests.yaml'
|
||||
- '{pyproject.toml,uv.lock,.python-version,.gitmodules}'
|
||||
- 'deps/**'
|
||||
- 'packages/**/pyproject.toml'
|
||||
- 'packages/prime-rl-configs/src/prime_rl/configs/{trainer,shared,__init__}.py'
|
||||
- 'packages/prime-rl-configs/src/prime_rl/utils/**'
|
||||
- 'src/prime_rl/*.py'
|
||||
- 'src/prime_rl/{trainer,multimodal,transports,utils}/**'
|
||||
- 'tests/{__init__.py,conftest.py,utils.py}'
|
||||
- 'tests/integration/{__init__.py,conftest.py}'
|
||||
- 'tests/unit/{train,inference}/**'
|
||||
- 'src/prime_rl/inference/**'
|
||||
sft:
|
||||
- *runtime
|
||||
- 'tools/convert_{dcp_to_bf16,dcp_to_fp8,bf16_to_fp8,fp8_to_bf16}.py'
|
||||
- 'src/prime_rl/dashboard/**'
|
||||
- 'tests/integration/dashboard_smoke.py'
|
||||
- 'packages/prime-rl-configs/src/prime_rl/configs/{sft,eval,monitors}.py'
|
||||
- 'src/prime_rl/entrypoints/{sft,dashboard}.py'
|
||||
- 'src/prime_rl/monitors/**'
|
||||
- 'src/prime_rl/eval/{online,runner}.py'
|
||||
- 'tests/integration/test_reverse_text_sft{,_lora}.py'
|
||||
- 'configs/ci/integration/reverse-text-sft{,-lora}/**'
|
||||
rl:
|
||||
- *runtime
|
||||
- 'tools/convert_{dcp_to_bf16,dcp_to_fp8,bf16_to_fp8,fp8_to_bf16}.py'
|
||||
- 'src/prime_rl/dashboard/**'
|
||||
- 'tests/integration/dashboard_smoke.py'
|
||||
- 'packages/prime-rl-configs/src/prime_rl/configs/{rl,orchestrator,inference,env_server,algorithm,eval,monitors}.py'
|
||||
- 'src/prime_rl/entrypoints/{rl,trainer,inference,orchestrator,env_server,dashboard}.py'
|
||||
- 'src/prime_rl/{inference,orchestrator,monitors}/**'
|
||||
- 'src/prime_rl/eval/{online,runner}.py'
|
||||
- 'tests/integration/test_reverse_text{,_lora,_moe,_rl_opd,_rl_sft}.py'
|
||||
- 'tests/integration/test_alphabet_sort.py'
|
||||
- 'configs/ci/integration/reverse-text{,-lora,-moe,-rl-opd,-rl-sft}/**'
|
||||
- 'configs/ci/integration/alphabet_sort.toml'
|
||||
eval:
|
||||
- *runtime
|
||||
- 'packages/prime-rl-configs/src/prime_rl/configs/{eval,orchestrator,inference,env_server,algorithm,monitors}.py'
|
||||
- 'src/prime_rl/{eval,orchestrator,monitors}/**'
|
||||
- 'src/prime_rl/entrypoints/{eval,env_server}.py'
|
||||
- 'tests/integration/test_gsm8k_eval.py'
|
||||
- 'configs/ci/integration/gsm8k-eval.toml'
|
||||
- name: Build integration matrix
|
||||
id: matrix
|
||||
env:
|
||||
# Main and manual runs retain the full suite.
|
||||
RUN_ALL: ${{ github.event_name != 'pull_request' }}
|
||||
SFT: ${{ steps.filter.outputs.sft || 'false' }}
|
||||
RL: ${{ steps.filter.outputs.rl || 'false' }}
|
||||
run: |
|
||||
tests=$(jq -cn --argjson all "$RUN_ALL" --argjson sft "$SFT" --argjson rl "$RL" '[
|
||||
if $all or $sft then "reverse_text_sft", "reverse_text_sft_lora" else empty end,
|
||||
if $all or $rl then
|
||||
"reverse_text", "reverse_text_rl_opd", "reverse_text_rl_sft",
|
||||
"alphabet_sort", "reverse_text_lora", "reverse_text_moe"
|
||||
else empty end
|
||||
]')
|
||||
echo "tests=$tests" >> "$GITHUB_OUTPUT"
|
||||
|
||||
unit-tests:
|
||||
name: Unit tests
|
||||
needs: changes
|
||||
runs-on: prime-rl-2xh200
|
||||
container:
|
||||
image: pytorch/pytorch:2.10.0-cuda13.0-cudnn9-devel
|
||||
options: --gpus all
|
||||
timeout-minutes: 45
|
||||
if: github.event_name == 'push' || github.event.pull_request.draft == false
|
||||
if: needs.changes.outputs.unit == 'true'
|
||||
steps:
|
||||
- name: Install Git
|
||||
run: |
|
||||
@@ -29,15 +112,16 @@ jobs:
|
||||
uses: actions/checkout@v7
|
||||
with:
|
||||
submodules: false
|
||||
- name: Init public submodules
|
||||
run: |
|
||||
git config --global url."https://github.com/".insteadOf "git@github.com:"
|
||||
git submodule update --init --recursive -- deps/verifiers deps/renderers deps/prime-envs deps/pydantic-config
|
||||
- name: Install uv
|
||||
uses: astral-sh/setup-uv@v10.0.1
|
||||
with:
|
||||
enable-cache: true
|
||||
cache-dependency-glob: "uv.lock"
|
||||
- parallel:
|
||||
- name: Init public submodules
|
||||
run: |
|
||||
git config --global url."https://github.com/".insteadOf "git@github.com:"
|
||||
git submodule update --init --recursive -- deps/verifiers deps/renderers deps/prime-envs deps/pydantic-config
|
||||
- name: Install uv
|
||||
uses: astral-sh/setup-uv@v10.0.1
|
||||
with:
|
||||
enable-cache: true
|
||||
cache-dependency-glob: "uv.lock"
|
||||
- name: Install dependencies
|
||||
run: uv sync --all-extras --all-packages --locked
|
||||
- name: Run unit tests
|
||||
@@ -53,46 +137,20 @@ jobs:
|
||||
|
||||
integration-tests:
|
||||
name: Integration tests (${{ matrix.test }})
|
||||
runs-on: ${{ matrix.runner }}
|
||||
needs: changes
|
||||
runs-on: prime-rl-2xh200
|
||||
container:
|
||||
image: pytorch/pytorch:2.10.0-cuda13.0-cudnn9-devel
|
||||
options: --gpus all
|
||||
timeout-minutes: 60
|
||||
if: github.event_name == 'push' || github.event.pull_request.draft == false
|
||||
if: needs.changes.outputs.integration != '[]'
|
||||
strategy:
|
||||
fail-fast: false
|
||||
# Bound per-PR fan-out: at most 5 integration jobs at a time (plus unit-tests),
|
||||
# i.e. 6 h200 pods per PR. Tune together with the ARC scale set maxRunners.
|
||||
max-parallel: 5
|
||||
matrix:
|
||||
include:
|
||||
- test: reverse_text_sft
|
||||
runner: prime-rl-2xh200
|
||||
pytest_args: "tests/integration/test_reverse_text_sft.py"
|
||||
- test: reverse_text_sft_lora
|
||||
runner: prime-rl-2xh200
|
||||
pytest_args: "tests/integration/test_reverse_text_sft_lora.py"
|
||||
- test: reverse_text
|
||||
runner: prime-rl-2xh200
|
||||
pytest_args: "tests/integration/test_reverse_text.py"
|
||||
- test: reverse_text_rl_opd
|
||||
runner: prime-rl-2xh200
|
||||
pytest_args: "tests/integration/test_reverse_text_rl_opd.py"
|
||||
- test: reverse_text_rl_sft
|
||||
runner: prime-rl-2xh200
|
||||
pytest_args: "tests/integration/test_reverse_text_rl_sft.py"
|
||||
- test: alphabet_sort
|
||||
runner: prime-rl-2xh200
|
||||
pytest_args: "tests/integration/test_alphabet_sort.py"
|
||||
- test: reverse_text_lora
|
||||
runner: prime-rl-2xh200
|
||||
pytest_args: "tests/integration/test_reverse_text_lora.py"
|
||||
- test: reverse_text_moe
|
||||
runner: prime-rl-2xh200
|
||||
pytest_args: "tests/integration/test_reverse_text_moe.py"
|
||||
- test: gsm8k_eval
|
||||
runner: prime-rl-2xh200
|
||||
pytest_args: "tests/integration/test_gsm8k_eval.py"
|
||||
test: ${{ fromJSON(needs.changes.outputs.integration) }}
|
||||
steps:
|
||||
- name: Install Git
|
||||
run: |
|
||||
@@ -103,15 +161,16 @@ jobs:
|
||||
uses: actions/checkout@v7
|
||||
with:
|
||||
submodules: false
|
||||
- name: Init public submodules
|
||||
run: |
|
||||
git config --global url."https://github.com/".insteadOf "git@github.com:"
|
||||
git submodule update --init --recursive -- deps/verifiers deps/renderers deps/prime-envs deps/pydantic-config
|
||||
- name: Install uv
|
||||
uses: astral-sh/setup-uv@v10.0.1
|
||||
with:
|
||||
enable-cache: true
|
||||
cache-dependency-glob: "uv.lock"
|
||||
- parallel:
|
||||
- name: Init public submodules
|
||||
run: |
|
||||
git config --global url."https://github.com/".insteadOf "git@github.com:"
|
||||
git submodule update --init --recursive -- deps/verifiers deps/renderers deps/prime-envs deps/pydantic-config
|
||||
- name: Install uv
|
||||
uses: astral-sh/setup-uv@v10.0.1
|
||||
with:
|
||||
enable-cache: true
|
||||
cache-dependency-glob: "uv.lock"
|
||||
- name: Install dependencies
|
||||
run: uv sync --all-extras --all-packages --locked
|
||||
- name: Run integration tests
|
||||
@@ -126,7 +185,7 @@ jobs:
|
||||
GITHUB_HEAD_REF: ${{ github.head_ref }}
|
||||
PYTEST_OUTPUT_DIR: /tmp/outputs
|
||||
VLLM_WORKER_MULTIPROC_METHOD: spawn
|
||||
run: uv run pytest -vvs ${{ matrix.pytest_args }}
|
||||
run: uv run pytest -vvs tests/integration/test_${{ matrix.test }}.py
|
||||
- name: Upload run logs on failure
|
||||
if: failure()
|
||||
uses: actions/upload-artifact@v7
|
||||
@@ -135,3 +194,47 @@ jobs:
|
||||
path: /tmp/outputs/**/*.log
|
||||
retention-days: 7
|
||||
if-no-files-found: ignore
|
||||
|
||||
eval-tests:
|
||||
name: Integration tests (gsm8k_eval)
|
||||
needs: changes
|
||||
if: needs.changes.outputs.eval == 'true'
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 30
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v7
|
||||
with:
|
||||
submodules: false
|
||||
- parallel:
|
||||
- name: Init public submodules
|
||||
run: |
|
||||
git config --global url."https://github.com/".insteadOf "git@github.com:"
|
||||
git submodule update --init --recursive -- deps/verifiers deps/renderers deps/prime-envs deps/pydantic-config
|
||||
- name: Install uv
|
||||
uses: astral-sh/setup-uv@v10.0.1
|
||||
with:
|
||||
enable-cache: true
|
||||
cache-dependency-glob: "uv.lock"
|
||||
- name: Install dependencies
|
||||
run: uv sync --all-extras --all-packages --locked
|
||||
- name: Run eval tests
|
||||
env:
|
||||
USERNAME_CI: CI_RUNNER
|
||||
WANDB_MODE: offline
|
||||
HF_TOKEN: ${{ secrets.HF_TOKEN }}
|
||||
PRIME_API_KEY: ${{ secrets.PRIME_API_KEY }}
|
||||
PRIME_BASE_URL: ${{ secrets.PRIME_BASE_URL }}
|
||||
PRIME_TEAM_ID: ${{ secrets.PRIME_TEAM_ID }}
|
||||
GITHUB_REF_NAME: ${{ github.ref_name }}
|
||||
GITHUB_HEAD_REF: ${{ github.head_ref }}
|
||||
PYTEST_OUTPUT_DIR: /tmp/outputs
|
||||
run: uv run pytest -vvs tests/integration/test_gsm8k_eval.py
|
||||
- name: Upload run logs on failure
|
||||
if: failure()
|
||||
uses: actions/upload-artifact@v7
|
||||
with:
|
||||
name: gsm8k_eval-logs
|
||||
path: /tmp/outputs/**/*.log
|
||||
retention-days: 7
|
||||
if-no-files-found: ignore
|
||||
|
||||
@@ -9,6 +9,10 @@ on:
|
||||
# This will trigger the workflow for pull requests to any branch
|
||||
types: [opened, synchronize, reopened]
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
ruff:
|
||||
name: Ruff
|
||||
|
||||
Vendored
+1
-1
Submodule deps/renderers updated: e3ace55754...41f9290949
+1
-1
@@ -42,7 +42,7 @@ uv run pytest tests/integration/test_reverse_text.py -vvs # one specific scenar
|
||||
| Workflow | Trigger | What runs | Where |
|
||||
|---|---|---|---|
|
||||
| [`cpu_tests.yaml`](https://github.com/PrimeIntellect-ai/prime-rl/blob/main/.github/workflows/cpu_tests.yaml) | every PR + push to `main` | `pytest tests/unit -m "not gpu"`, plus a slim-wheel install check that `prime-rl-configs` imports cleanly without heavy deps (no torch / vllm / transformers / wandb / verifiers / datasets / liger / loguru in `sys.modules`) | `ubuntu-latest` |
|
||||
| [`gpu_tests.yaml`](https://github.com/PrimeIntellect-ai/prime-rl/blob/main/.github/workflows/gpu_tests.yaml) | every non-draft PR + push to `main` | `pytest tests/unit -m gpu`, plus a matrix of named integration scenarios (`reverse_text`, `reverse_text_sft`, `reverse_text_sft_lora`, `reverse_text_lora`, `reverse_text_moe`, `reverse_text_rl_opd`, `reverse_text_rl_sft`, `alphabet_sort`, `gsm8k_eval`), with `max-parallel: 5` bounding fan-out | self-hosted `prime-rl-2xh200` k8s scale set (2xH200) |
|
||||
| [`gpu_tests.yaml`](https://github.com/PrimeIntellect-ai/prime-rl/blob/main/.github/workflows/gpu_tests.yaml) | relevant changes in non-draft PRs; full suite on push to `main` or manual dispatch | `pytest tests/unit -m gpu`, plus RL/SFT integration scenarios (`reverse_text`, `reverse_text_sft`, `reverse_text_sft_lora`, `reverse_text_lora`, `reverse_text_moe`, `reverse_text_rl_opd`, `reverse_text_rl_sft`, `alphabet_sort`) with `max-parallel: 5`; separate hosted `gsm8k_eval` job | self-hosted `prime-rl-2xh200` k8s scale set (2xH200); `ubuntu-latest` for test selection and hosted eval |
|
||||
| [`nightly_tests.yaml`](https://github.com/PrimeIntellect-ai/prime-rl/blob/main/.github/workflows/nightly_tests.yaml) | 03:00 PST daily + manual `workflow_dispatch` (single-file filter optional) | every file in `tests/nightly/`, one matrix job per file | `research-cluster` |
|
||||
|
||||
The GPU + Nightly workflows skip drafts — open the PR as **Draft** until you're ready to consume CI compute, then mark it ready for review to trigger the GPU matrix.
|
||||
|
||||
@@ -696,11 +696,10 @@ def _distribute_group(
|
||||
|
||||
def pad_micro_batch(micro_batch: MicroBatch, pad_to_multiple_of: int) -> MicroBatch:
|
||||
"""
|
||||
Pad a micro batch with the given padding size sample
|
||||
Return the padded micro batch.
|
||||
Pad a micro batch with loss-masked tokens up to the next multiple of `pad_to_multiple_of`.
|
||||
Args:
|
||||
micro_batch: The micro batch to pad.
|
||||
padding_size: The number of padding tokens to add.
|
||||
pad_to_multiple_of: The multiple to pad the sequence length up to.
|
||||
Returns:
|
||||
The padded micro batch.
|
||||
"""
|
||||
|
||||
@@ -12,6 +12,7 @@ import triton.language as tl
|
||||
FP8_MAX = 448.0
|
||||
FP8_MIN = -448.0
|
||||
FP8_EPS = 1e-10
|
||||
KEY_ALIGNMENT = 16
|
||||
|
||||
|
||||
@triton.jit
|
||||
@@ -88,17 +89,6 @@ def per_token_group_quant_fp8(
|
||||
return x_q, x_s
|
||||
|
||||
|
||||
@triton.autotune(
|
||||
configs=[
|
||||
triton.Config({"BLOCK_M": 64, "BLOCK_N": 64}, num_warps=4, num_stages=2),
|
||||
triton.Config({"BLOCK_M": 64, "BLOCK_N": 128}, num_warps=4, num_stages=2),
|
||||
triton.Config({"BLOCK_M": 128, "BLOCK_N": 64}, num_warps=8, num_stages=2),
|
||||
triton.Config({"BLOCK_M": 128, "BLOCK_N": 128}, num_warps=8, num_stages=2),
|
||||
triton.Config({"BLOCK_M": 64, "BLOCK_N": 64}, num_warps=8, num_stages=3),
|
||||
triton.Config({"BLOCK_M": 64, "BLOCK_N": 128}, num_warps=8, num_stages=3),
|
||||
],
|
||||
key=["S_Q", "S_K_BUCKET", "H", "D"],
|
||||
)
|
||||
@triton.jit
|
||||
def _triton_fp8_indexer_kernel(
|
||||
Q_fp8,
|
||||
@@ -116,7 +106,6 @@ def _triton_fp8_indexer_kernel(
|
||||
stride_ws,
|
||||
H: tl.constexpr,
|
||||
D: tl.constexpr,
|
||||
S_K_BUCKET: tl.constexpr,
|
||||
BLOCK_M: tl.constexpr,
|
||||
BLOCK_N: tl.constexpr,
|
||||
):
|
||||
@@ -201,6 +190,8 @@ def fp8_indexer(
|
||||
|
||||
q_flat = q.reshape(S_q * H, D).contiguous()
|
||||
q_fp8, q_scales = per_token_group_quant_fp8(q_flat, group_size=D, use_ue8m0=True)
|
||||
S_k_aligned = triton.cdiv(S_k, KEY_ALIGNMENT) * KEY_ALIGNMENT
|
||||
k = torch.nn.functional.pad(k, (0, 0, 0, S_k_aligned - S_k))
|
||||
k_fp8, k_scales = per_token_group_quant_fp8(k.contiguous(), group_size=D, use_ue8m0=True)
|
||||
|
||||
q_fp8 = q_fp8.view(S_q, H, D).permute(1, 0, 2).contiguous()
|
||||
@@ -209,12 +200,10 @@ def fp8_indexer(
|
||||
q_scales = q_scales.view(S_q, H)
|
||||
w = w * q_scales
|
||||
|
||||
logits = torch.empty(S_q, S_k, dtype=torch.float32, device=device)
|
||||
logits = torch.empty(S_q, S_k_aligned, dtype=torch.float32, device=device)
|
||||
|
||||
grid = lambda meta: (
|
||||
triton.cdiv(S_q, meta["BLOCK_M"]),
|
||||
triton.cdiv(S_k, meta["BLOCK_N"]),
|
||||
)
|
||||
BLOCK_M, BLOCK_N = 64, 128
|
||||
grid = (triton.cdiv(S_q, BLOCK_M), triton.cdiv(S_k_aligned, BLOCK_N))
|
||||
_triton_fp8_indexer_kernel[grid](
|
||||
q_fp8,
|
||||
k_fp8,
|
||||
@@ -224,16 +213,17 @@ def fp8_indexer(
|
||||
ks,
|
||||
ke,
|
||||
S_q,
|
||||
S_k,
|
||||
S_k_aligned,
|
||||
q_fp8.stride(0),
|
||||
q_fp8.stride(1),
|
||||
k_fp8.stride(0),
|
||||
w.stride(0),
|
||||
H=H,
|
||||
D=D,
|
||||
# Packed document tails change S_k between batches. Reuse tuning within
|
||||
# a size bucket; exact S_k still controls strides and all bounds masks.
|
||||
S_K_BUCKET=triton.next_power_of_2(S_k),
|
||||
BLOCK_M=BLOCK_M,
|
||||
BLOCK_N=BLOCK_N,
|
||||
num_warps=4,
|
||||
num_stages=2,
|
||||
)
|
||||
|
||||
actual_topk = min(topk, S_k)
|
||||
|
||||
@@ -112,7 +112,7 @@ class ParallelDims:
|
||||
|
||||
# Create all the submesh here to ensure all required process groups are
|
||||
# initialized:
|
||||
# Mesh for data loading (no communication on this mesh)
|
||||
# Mesh for data loading and per-step token counts
|
||||
dp_mesh_dim_names = []
|
||||
# Mesh for param sharding
|
||||
dp_shard_cp_mesh_dim_names = []
|
||||
@@ -172,7 +172,7 @@ class ParallelDims:
|
||||
|
||||
# Create all the submesh here to ensure all required process groups are
|
||||
# initialized:
|
||||
# Mesh for data loading (no communication on this mesh)
|
||||
# Mesh for data loading and per-step token counts
|
||||
dp_mesh_dim_names = []
|
||||
# Mesh for param sharding
|
||||
dp_shard_cp_mesh_dim_names = []
|
||||
@@ -263,13 +263,6 @@ class ParallelDims:
|
||||
def non_data_parallel_size(self):
|
||||
return self.cp * self.pp
|
||||
|
||||
@cached_property
|
||||
def seq_len_divisor(self):
|
||||
# Context Parallel requires that seq_len be divisible by 2 * CP degree,
|
||||
# when load balancing is enabled (by default).
|
||||
# https://github.com/pytorch/pytorch/blob/4f62dcc/torch/distributed/tensor/experimental/_attention.py#L1246
|
||||
return self.cp * 2
|
||||
|
||||
@cached_property
|
||||
def logger(self):
|
||||
return get_logger()
|
||||
@@ -309,7 +302,7 @@ def resolve_ep(config: ModelConfig) -> None:
|
||||
get_logger().info(f"EP auto: world_size={world_size}, dp_replicate={dp_replicate} -> resolved ep={resolved_ep}")
|
||||
|
||||
|
||||
def get_parallel_dims(config: ModelConfig, seq_len: int | None = None) -> ParallelDims:
|
||||
def get_parallel_dims(config: ModelConfig) -> ParallelDims:
|
||||
assert isinstance(config.ep, int), (
|
||||
f"config.ep must be resolved to an int before get_parallel_dims; got {config.ep!r}. "
|
||||
"Call resolve_ep(config) first."
|
||||
@@ -325,12 +318,4 @@ def get_parallel_dims(config: ModelConfig, seq_len: int | None = None) -> Parall
|
||||
world_size=dist.get_world_size(),
|
||||
)
|
||||
|
||||
# Validate sequence length against parallel dimensions requirements
|
||||
if seq_len is not None and seq_len % parallel_dims.seq_len_divisor != 0:
|
||||
raise ValueError(
|
||||
f"Sequence length ({seq_len}) must be divisible by "
|
||||
f"seq_len_divisor ({parallel_dims.seq_len_divisor}) for the given parallel dimensions. "
|
||||
f"This requirement comes from context parallel (CP={config.cp})."
|
||||
)
|
||||
|
||||
return parallel_dims
|
||||
|
||||
@@ -339,7 +339,9 @@ def train(config: TrainerConfig):
|
||||
cp_size = parallel_dims.cp
|
||||
|
||||
step_tokens_per_expert = 0
|
||||
step_local_num_tokens = 0
|
||||
for micro_step, micro_batch in enumerate(micro_batch_workers(prepare, micro_batches)):
|
||||
step_local_num_tokens += micro_batch["input_ids"].shape[1]
|
||||
input_ids = micro_batch["input_ids"].to("cuda")
|
||||
position_ids = micro_batch["position_ids"].to("cuda")
|
||||
advantages = micro_batch["advantages"].to("cuda")
|
||||
@@ -627,9 +629,10 @@ def train(config: TrainerConfig):
|
||||
if is_moe_model:
|
||||
tensor_stats.update(get_expert_load_stats(step_tokens_per_expert, dp_cp_group))
|
||||
|
||||
# Compute step metrics
|
||||
num_local_tokens = seq_len * batch_size
|
||||
num_tokens = parallel_dims.get_mesh("dp").size() * num_local_tokens
|
||||
# The dp mesh excludes cp, whose ranks hold the same rows.
|
||||
global_num_tokens = torch.tensor(step_local_num_tokens, dtype=torch.int64, device="cuda")
|
||||
dist.all_reduce(global_num_tokens, op=dist.ReduceOp.SUM, group=parallel_dims.get_mesh("dp").get_group())
|
||||
num_tokens = global_num_tokens.item()
|
||||
progress.total_tokens += num_tokens
|
||||
progress.total_samples += batch_size
|
||||
perf_counter = get_perf_counter(model, seq_len)
|
||||
|
||||
@@ -249,6 +249,13 @@ class RendererResolver:
|
||||
renderer = create_renderer(self.tokenizer, config)
|
||||
if self.processor is not None and hasattr(renderer, "_processor"):
|
||||
renderer._processor = self.processor
|
||||
if not getattr(renderer, "is_prefix_stable", False):
|
||||
get_logger().warning(
|
||||
f"SFT renderer {type(renderer).__name__} does not guarantee prefix stability. "
|
||||
"SFT renders each conversation once to produce one training sample; "
|
||||
"it does not expand N assistant turns into N samples. Depending on the template, "
|
||||
"reasoning from earlier turns may be omitted from the training sample."
|
||||
)
|
||||
self.renderers[config] = renderer
|
||||
return renderer
|
||||
|
||||
@@ -473,12 +480,13 @@ class SFTDataset(StatefulIterableDataset):
|
||||
|
||||
|
||||
class CatDataset(StatefulIterableDataset):
|
||||
"""Concatenate text and multimodal samples into one fixed-length row."""
|
||||
"""Pack samples into rows of at most `seq_len` tokens, padded to a multiple of `pad_to_multiple_of`."""
|
||||
|
||||
def __init__(self, dataset: StatefulIterableDataset, seq_len: int):
|
||||
def __init__(self, dataset: StatefulIterableDataset, seq_len: int, pad_to_multiple_of: int):
|
||||
self.logger = get_logger()
|
||||
self.dataset = dataset
|
||||
self.seq_len = seq_len
|
||||
self.pad_to_multiple_of = pad_to_multiple_of
|
||||
self.pending_sample: Sample | None = None
|
||||
|
||||
def state_dict(self) -> dict:
|
||||
@@ -582,7 +590,7 @@ class CatDataset(StatefulIterableDataset):
|
||||
if kept > 0:
|
||||
result["seq_lens"].append(kept)
|
||||
remaining -= kept
|
||||
pad_len = seq_len - len(result["input_ids"])
|
||||
pad_len = -len(result["input_ids"]) % self.pad_to_multiple_of
|
||||
if pad_len > 0:
|
||||
result["input_ids"].extend([0] * pad_len)
|
||||
result["position_ids"].extend(range(pad_len))
|
||||
@@ -752,8 +760,8 @@ def setup_dataset(
|
||||
raise ValueError(f"Invalid dataset type: {config.type}")
|
||||
|
||||
|
||||
def setup_dataloader(dataset: StatefulIterableDataset, config: DataConfig) -> StatefulDataLoader:
|
||||
packing_dataset = CatDataset(dataset, config.seq_len * config.micro_batch_size)
|
||||
def setup_dataloader(dataset: StatefulIterableDataset, config: DataConfig, cp: int) -> StatefulDataLoader:
|
||||
packing_dataset = CatDataset(dataset, config.seq_len * config.micro_batch_size, pad_to_multiple_of=cp)
|
||||
return StatefulDataLoader(
|
||||
packing_dataset,
|
||||
batch_size=1,
|
||||
|
||||
@@ -113,7 +113,7 @@ def train(config: SFTConfig):
|
||||
resolve_ep(config.model)
|
||||
|
||||
# Initialize parallel dimensions
|
||||
parallel_dims = get_parallel_dims(config.model, config.data.seq_len)
|
||||
parallel_dims = get_parallel_dims(config.model)
|
||||
|
||||
total_micro_batches = config.data.batch_size * config.model.cp
|
||||
micro_batches_per_step = world.world_size * config.data.micro_batch_size
|
||||
@@ -192,7 +192,7 @@ def train(config: SFTConfig):
|
||||
processor=processor,
|
||||
multimodal=multimodal,
|
||||
)
|
||||
dataloader = setup_dataloader(dataset, config.data)
|
||||
dataloader = setup_dataloader(dataset, config.data, config.model.cp)
|
||||
|
||||
val_raw_dataset = None
|
||||
if config.val is not None:
|
||||
@@ -257,7 +257,7 @@ def train(config: SFTConfig):
|
||||
|
||||
if cp_enabled:
|
||||
# CP requires the sequence length to be divisible by cp_size. CatDataset
|
||||
# pads every pack to seq_len; shard_for_cp raises on violations.
|
||||
# pads every pack to a multiple of it; shard_for_cp raises on violations.
|
||||
defer_vlm_cp_to_model = (
|
||||
mm_kwargs is not None and "image_grid_thw" in mm_kwargs and config.model.cp_style == "ulysses"
|
||||
)
|
||||
@@ -345,7 +345,7 @@ def train(config: SFTConfig):
|
||||
processor=processor,
|
||||
multimodal=multimodal,
|
||||
)
|
||||
val_dataloader = setup_dataloader(val_dataset, config.val.data)
|
||||
val_dataloader = setup_dataloader(val_dataset, config.val.data, config.model.cp)
|
||||
|
||||
# No train/eval switch: no dropout in these models, and toggling would trigger torch.compile recompilation
|
||||
mean_loss, nan_count = run_eval_loop(val_dataloader)
|
||||
@@ -451,7 +451,9 @@ def train(config: SFTConfig):
|
||||
)
|
||||
|
||||
step_tokens_per_expert = 0
|
||||
step_local_num_tokens = 0
|
||||
for micro_step, micro_batch in enumerate(micro_batches):
|
||||
step_local_num_tokens += micro_batch["input_ids"].shape[1]
|
||||
if config.log.log_data:
|
||||
print_sample(
|
||||
micro_batch["input_ids"].flatten().tolist(), micro_batch["loss_mask"].flatten().tolist(), tokenizer
|
||||
@@ -549,14 +551,10 @@ def train(config: SFTConfig):
|
||||
if memory_profiler is not None:
|
||||
memory_profiler.step()
|
||||
|
||||
# Compute step metrics. CP shards the same sequences across cp ranks
|
||||
# (sequence-sharded data parallelism on the seq dim), so the unique
|
||||
# training tokens per step is dp_size * (batch_per_dp_rank * seq).
|
||||
# The `dp` mesh excludes cp by construction (parallel_dims.py), mirroring
|
||||
# the RL trainer's accounting (rl/train.py).
|
||||
dp_size = parallel_dims.get_mesh("dp").size()
|
||||
num_local_tokens = config.data.seq_len * (config.data.batch_size // dp_size)
|
||||
num_tokens = dp_size * num_local_tokens
|
||||
# The dp mesh excludes cp, whose ranks hold the same rows.
|
||||
global_num_tokens = torch.tensor(step_local_num_tokens, dtype=torch.int64, device="cuda")
|
||||
dist.all_reduce(global_num_tokens, op=dist.ReduceOp.SUM, group=parallel_dims.get_mesh("dp").get_group())
|
||||
num_tokens = global_num_tokens.item()
|
||||
progress.total_tokens += num_tokens
|
||||
dataset_progress = get_dataset_progress(dataloader)
|
||||
progress.total_samples = dataset_progress["step"]
|
||||
|
||||
@@ -19,7 +19,7 @@ def setup_fake_dataloader(config: FakeDataConfig, non_dp_size: int = 1):
|
||||
seed=config.seed,
|
||||
non_dp_size=non_dp_size,
|
||||
)
|
||||
return dataset, setup_dataloader(dataset, config)
|
||||
return dataset, setup_dataloader(dataset, config, cp=1)
|
||||
|
||||
|
||||
def test_fake_dataset_single_rank_state():
|
||||
@@ -88,7 +88,7 @@ def test_fake_dataset_single_rank_resume():
|
||||
|
||||
# Reload dataloader
|
||||
state_dict = dataloader.state_dict()
|
||||
dataloader = setup_dataloader(dataset, config)
|
||||
dataloader = setup_dataloader(dataset, config, cp=1)
|
||||
dataloader.load_state_dict(state_dict)
|
||||
dataiter = iter(dataloader)
|
||||
|
||||
@@ -110,7 +110,8 @@ def test_fake_dataset_single_rank_state_with_packing():
|
||||
micro_batch = next(dataiter)
|
||||
num_packed_examples = len(micro_batch["input_ids"][micro_batch["loss_mask"]].unique())
|
||||
step += num_packed_examples
|
||||
assert micro_batch["input_ids"].shape == (1, 128)
|
||||
assert micro_batch["input_ids"].shape[0] == 1
|
||||
assert micro_batch["input_ids"].shape[1] <= 128
|
||||
assert micro_batch["seq_lens"].sum() == micro_batch["input_ids"].shape[1]
|
||||
worker_state = dataloader.state_dict()["_snapshot"]["_worker_snapshots"]["worker_0"]["dataset_state"]
|
||||
pending_sample = worker_state.get("pending_sample")
|
||||
@@ -186,7 +187,7 @@ def test_dataloader_shards_across_ranks_and_workers(
|
||||
seq_len=config.seq_len,
|
||||
non_dp_size=non_dp_size,
|
||||
)
|
||||
return setup_dataloader(dataset, config)
|
||||
return setup_dataloader(dataset, config, cp=1)
|
||||
|
||||
dataloader = setup_epoch_dataloader()
|
||||
dataiter = iter(dataloader)
|
||||
|
||||
@@ -443,6 +443,7 @@ def test_cat_dataset_packs_multimodal_samples():
|
||||
),
|
||||
],
|
||||
seq_len=5,
|
||||
pad_to_multiple_of=1,
|
||||
)
|
||||
|
||||
packed = next(iter(dataset))
|
||||
@@ -467,23 +468,24 @@ def test_cat_dataset_packs_text_and_multimodal_samples_together():
|
||||
mm_token_type_ids=[0, 1],
|
||||
),
|
||||
_sft_sample([4]),
|
||||
_sft_sample([5, 6]),
|
||||
_sft_sample([5, 6, 7, 8, 9, 10]),
|
||||
],
|
||||
seq_len=5,
|
||||
seq_len=9,
|
||||
pad_to_multiple_of=3,
|
||||
)
|
||||
|
||||
dataiter = iter(dataset)
|
||||
packed = next(dataiter)
|
||||
text_pack = next(dataiter)
|
||||
|
||||
assert packed["input_ids"] == [1, 2, 3, 4, 0]
|
||||
assert packed["loss_mask"] == [True, True, True, True, False]
|
||||
assert packed["seq_lens"] == [1, 2, 2]
|
||||
assert packed["input_ids"] == [1, 2, 3, 4, 0, 0]
|
||||
assert packed["loss_mask"] == [True, True, True, True, False, False]
|
||||
assert packed["seq_lens"] == [1, 2, 3]
|
||||
assert packed["mm_kwargs"] is not None
|
||||
assert packed["mm_token_type_ids"] == [0, 0, 1, 0, 0]
|
||||
assert text_pack["input_ids"] == [5, 6, 0, 0, 0]
|
||||
assert text_pack["loss_mask"] == [True, True, False, False, False]
|
||||
assert text_pack["seq_lens"] == [5]
|
||||
assert packed["mm_token_type_ids"] == [0, 0, 1, 0, 0, 0]
|
||||
assert text_pack["input_ids"] == [5, 6, 7, 8, 9, 10]
|
||||
assert text_pack["loss_mask"] == [True] * 6
|
||||
assert text_pack["seq_lens"] == [6]
|
||||
assert text_pack["mm_kwargs"] is None
|
||||
assert text_pack["mm_token_type_ids"] is None
|
||||
|
||||
@@ -508,6 +510,10 @@ class EffortRenderer:
|
||||
def __init__(self, tokenizer, config):
|
||||
self.config = config
|
||||
|
||||
@property
|
||||
def is_prefix_stable(self):
|
||||
return self.config.reasoning_effort == "low"
|
||||
|
||||
def render(self, messages, **kwargs):
|
||||
return RenderedTokens(token_ids=[0, 1], message_indices=[-1, 0], sampled_mask=[False, True])
|
||||
|
||||
@@ -528,8 +534,21 @@ def custom_renderer_config(tmp_path):
|
||||
def test_renderer_resolver_applies_renderer_columns_to_custom_renderer(custom_renderer_config):
|
||||
resolver = sft_data.RendererResolver(tokenizer=None, config=custom_renderer_config)
|
||||
|
||||
default = resolver({"messages": [], "reasoning_effort": None})
|
||||
high = resolver({"messages": [], "reasoning_effort": "high"})
|
||||
warnings = []
|
||||
logger = sft_data.get_logger()
|
||||
sink = logger.add(lambda message: warnings.append(str(message)), level="WARNING", format="{message}")
|
||||
try:
|
||||
default = resolver({"messages": [], "reasoning_effort": None})
|
||||
assert warnings == []
|
||||
high = resolver({"messages": [], "reasoning_effort": "high"})
|
||||
assert resolver({"reasoning_effort": "high"}) is high
|
||||
assert len(warnings) == 1
|
||||
assert "does not guarantee prefix stability" in warnings[0]
|
||||
assert "one training sample" in warnings[0]
|
||||
assert "does not expand N assistant turns into N samples" in warnings[0]
|
||||
assert "reasoning from earlier turns may be omitted" in warnings[0]
|
||||
finally:
|
||||
logger.remove(sink)
|
||||
|
||||
assert default.config.reasoning_effort == "low"
|
||||
assert high.config.reasoning_effort == "high"
|
||||
|
||||
Reference in New Issue
Block a user