Skip to content

feat(policy): split-API train-step state machine on DTensor v1/v2 - #2692

Open
mehraakash wants to merge 16 commits into
NVIDIA-NeMo:mainfrom
mehraakash:asyncrl/split_train_dtensor
Open

mehraakash wants to merge 16 commits into
NVIDIA-NeMo:mainfrom
mehraakash:asyncrl/split_train_dtensor

Conversation

@mehraakash

@mehraakash mehraakash commented Jun 4, 2026 •

Copy link
Copy Markdown
Contributor

📚 Stacked PR — 3-PR async-GRPO split-API series (top → bottom):

Stack-aware base retargeting is unavailable for fork PRs (gh-stack limitation); manual header. Locally rebased so this branch contains #2683's commits — but GitHub's "Files changed" shows the cumulative diff. Per-layer scope: read commits authored on this branch (not present on #2683).


Summary

Adds the DTensor v1 + v2 backend implementations of the split-API train-step
methods (begin / train_microbatch / finish / abort), plus the
PolicyTrainerActor Ray wrapper that exposes the API to SingleController via
.remote(...). Sync train() is left untouched on both backends.

This is PR 2 of 3 in the SingleController split-API series:

  • PR 1 — `asyncrl/split_train_mcore` (Megatron + shared infra: `worker_mixin`, `tq_policy`). Open this branch's PR against `main` first — the dtensor PR diff includes those commits until PR 1 lands.
  • PR 2 — this PR (DTensor v1 + v2 + `PolicyTrainerActor` + GPU parity tests).
  • PR 3 — coming next (SC `_train_pump` rewrite to drive the split API end-to-end).

What's new

  • DTensor v1 state machine using the `N=1` placeholder trick. Per microbatch the loss is called with `global_valid_*=tensor(1.0)` so backward deposits un-normalized gradients; `finish_train_step` `all_reduce`s local mask sums to recover the true `N` (toks for TOKEN_LEVEL, seqs for SEQUENCE_LEVEL), rescales `p.grad` by `1/N`, runs grad_norm/clip/opt.step. Bin iteration with DP-rank dummy-bin padding handles seq-packing / dynamic-batching uneven splits without desyncing NCCL.
  • DTensor v2 same shape, built on the v2 helpers (`LossPostProcessor`, `get_microbatch_iterator`, `automodel_forward_backward`, `scale_grads_and_clip_grad_norm`). The clip helper has MoE/EP awareness; the manual `1/N` rescale runs before it.
  • `PolicyTrainerActor` at `nemo_rl/models/policy/policy_trainer_actor.py` — `@ray.remote(num_cpus=1, num_gpus=0)` wrapper that owns a `TQPolicy` instance and exposes `train_from_meta` (sync proxy), `prepare_logprobs_from_meta`, and the split API. `trainer_version` advances on sync `train_from_meta` or on `finish_train_step` (never on abort).
  • GPU parity tests at `tests/unit/models/policy/test_split_train_step.py`:
    • numerical equivalence vs sync `train()` for token-level and seq-level losses;
    • multi-bin-per-call under seq-packing;
    • split-state-machine lifecycle (double begin, abort idempotence).
      Parameterised over v1/v2.

Test plan

  • `pytest tests/unit/models/policy/test_split_train_step.py -v` on a multi-GPU CI runner.
  • Sync `train()` path unchanged — existing test_dtensor_worker* tests still pass.
  • No production caller of the split API yet (PR 3 will wire SC up), so no recipe regression possible from this PR.

@mehraakash
mehraakash requested review from a team as code owners June 4, 2026 22:33
@copy-pr-bot

copy-pr-bot Bot commented Jun 4, 2026

Copy link
Copy Markdown

Auto-sync is disabled for ready for review pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@mehraakash

Copy link
Copy Markdown
Contributor Author

/ok to test 21d91efcf

@mehraakash

Copy link
Copy Markdown
Contributor Author

/ok to test

@mehraakash

Copy link
Copy Markdown
Contributor Author

/ok to test d45f58d

@mehraakash

Copy link
Copy Markdown
Contributor Author

/ok to test 3748982

mehraakash added a commit to mehraakash/RL that referenced this pull request Jun 5, 2026
The file is introduced by NVIDIA-NeMo#2692 (DTensor PR), not by this branch.
Whitelisting it here causes pyrefly to fail with 'No Python files
matched pattern' since the file does not exist on mcore.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
Signed-off-by: Akash Mehra <[email protected]>
mehraakash added a commit to mehraakash/RL that referenced this pull request Jun 5, 2026
The file is introduced by NVIDIA-NeMo#2692 (DTensor PR), not by this branch.
Whitelisting it here causes pyrefly to fail with 'No Python files
matched pattern' since the file does not exist on this branch.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
Signed-off-by: Akash Mehra <[email protected]>
mehraakash added a commit to mehraakash/RL that referenced this pull request Jun 8, 2026
The file is introduced by NVIDIA-NeMo#2692 (DTensor PR), not by this branch.
Whitelisting it here causes pyrefly to fail with 'No Python files
matched pattern' since the file does not exist on this branch.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
Signed-off-by: Akash Mehra <[email protected]>
yuki-97 added a commit that referenced this pull request Jun 15, 2026
Split SC bring-up into two factories that match the actor model:

- setup_handle wires the four remote handles SC drives: dp_client,
  gen_handle, trainer_handle, env_handles. Internally delegates to
  grpo.setup with a TQ-mediated policy factory so the async path stays
  in step with grpo_train_sync; env_handles can be supplied by the
  caller or derived via setup_response_data.
- setup_single_controller_component builds the six local objects SC
  owns inside its actor process: dataloader, weight_synchronizer,
  advantage_estimator, tokenizer, rollout_manager, tq_buffer. Sharing a
  single TQReplayBuffer between RolloutManager and the sampler keeps
  the rollout writer + sampler in sync.

Both factories take a MasterConfig directly (no Ray init, no cluster
setup of their own) so the example launcher can compose them.

trainer_handle is currently set to the TQPolicy returned by grpo.setup;
SC's split-API ".remote(...)" calls expect a Ray actor wrapper
(PolicyTrainerActor from PR #2692). The wrapping point is documented in
the module docstring so the swap is mechanical once that lands.

Unit tests patch grpo.setup / setup_response_data / create_weight_synchronizer
to verify the factory shape, env_handles fallback, partition_id pass-through,
and the multi-dataloader guard.

Signed-off-by: Yuki Huang <[email protected]>
`finish_train_step` was calling both `model.start_grad_sync()` and
`model.finish_grad_sync()` unconditionally. In megatron-core's BucketGroup,
when `overlap_grad_reduce=False` (the production default), `finish_grad_sync`
internally invokes `start_grad_sync(force_all_reduce=True)`, so calling
`start_grad_sync` ourselves first dispatches the synchronous collective
once, and `finish_grad_sync` dispatches it again — scaling the reduced
gradient by ~world_size. The optimizer then steps with grads that are
DP-world-size too large.

Parity tests pass because they assert call order / state shape, not
numerical equivalence at world_size > 1. The bug surfaces only at runtime.

Fix: only call `start_grad_sync` explicitly when `overlap_grad_reduce=True`
(the async path that needs an explicit dispatch since `model.no_sync()`
gates off the per-microbatch hooks). For `overlap_grad_reduce=False`,
`finish_grad_sync` handles everything.

Tests:

- Parametrize `test_start_then_finish_grad_sync_called_after_rescale` on
  `overlap_grad_reduce` and assert the correct call order in each case.
- Add `distributed_data_parallel_config` to the test cfg fixture so the
  worker's branch can read the flag.

Reported by terrykong in PR NVIDIA-NeMo#2683 review.

Signed-off-by: Akash Mehra <[email protected]>
mehraakash added a commit to mehraakash/RL that referenced this pull request Jun 16, 2026
- Thread loss_fn through SingleController + begin_train_step. Real bug
  against TQPolicy / MegatronPolicyWorker whose begin_train_step requires
  loss_fn with no default; previously masked by the dryrun stub.
- SC owns trainer_version: drop result["trainer_version"] read (key not
  emitted by real backends); bump immediately after finish_train_step
  succeeds, before clear_samples, so SC's counter matches worker state
  even if clear_samples fails.
- Add TQPolicy.prepare_logprobs_from_meta(meta, refresh_policy_logprobs=,
  refresh_reference_logprobs=) dispatcher over the existing
  get_*_from_meta methods. SC wires it from the per-group hook with
  config-driven flags. PolicyTrainerActor signature mirrored in NVIDIA-NeMo#2692.
- Wrap _train_pump per-step body in try/except: on mid-step worker
  failure, call abort_train_step on the worker and clear the
  consumed-ids ledger before re-raising. TODO: retry policy is a
  follow-up.
- Document max_concurrency=1 contract in _train_pump docstring; set it
  explicitly on MegatronPolicyWorker rather than relying on Ray's
  sync-actor default.
- Migrate SingleControllerConfig from @DataClass to
  pydantic.BaseModel(extra="allow") to match the repo's MasterConfig
  style. Drop the extra: dict workaround field and the runtime Literal
  assert (pydantic validates at construction).
- Move five cross-actor TQ schema field names to module-level constants
  (PROMPT_IDS_FIELD, REWARD_FIELD, TOKEN_MASK_FIELD, SAMPLE_MASK_FIELD,
  ADVANTAGE_OUTPUT_FIELD). They're a fixed protocol with the rollout
  actor, not user-tunable.
- Drop dead RAY_TEMP_DIR macOS workaround from the dryrun test header
  (Linux CI doesn't need it; mac devs can set RAY_TMPDIR in shell).
- Tighten reap timeout to 0.0 for a true non-blocking peek; was 0.05.
- print -> log.info for the strict_on_policy auto-set notice.
- Add dryrun test exercising prepare_logprobs_from_meta with both flags
  set, only policy set, and neither set.

Signed-off-by: Akash Mehra <[email protected]>
mehraakash and others added 8 commits June 15, 2026 19:17
Two bugs around the split-API state machine fixed in one pass:

1. **no_sync_func leak (latent assertion on step 2 with PP=1).**
   `forward_backward_no_pipelining` (the PP=1 path, which is the common
   one) wraps inner microbatches in `model.config.no_sync_func` but runs
   the *last* microbatch OUTSIDE of it. Our outer `with self.model.no_sync():`
   in `train_microbatch` was therefore bypassed for the trailing MB.
   `register_grad_ready` leaked per-param counts past the explicit DP
   sync at `finish_train_step`, and the next `begin_train_step` then
   asserted on the stale counts (typically step 2).

   Fix: in `begin_train_step` also save and null `no_sync_func` (set to
   `contextlib.nullcontext`). Restore both hooks at finish/abort via the
   new `_restore_saved_grad_sync_func` helper.

   Spotted in yuki-97's PR NVIDIA-NeMo#2819 (`begin_train_step` also nulls
   `config.no_sync_func`); same fix landed here.

2. **No exception safety around the open step (terrykong, NVIDIA-NeMo#2683:640).**
   If `train_microbatch` or `finish_train_step` raised mid-body, both
   `grad_sync_func` and (now also) `no_sync_func` would stay nulled and
   future steps would run with the PP scheduler bypass disabled silently.

   Fix: extract `_train_microbatch_body` and `_finish_train_step_body`,
   wrap each entry method in try/except that calls
   `_restore_saved_grad_sync_func` before re-raising. Caller is still
   expected to invoke `abort_train_step` (idempotent on the saved
   values) to drop `_train_step_state`.

3. **Cleanup (terrykong, NVIDIA-NeMo#2683:582).** Drop dead `no_sync_active` field
   from `_split_step_state_init` — never read or written; `no_sync` is
   applied via the `with self.model.no_sync():` context manager.

Also: add module-level `log = logging.getLogger(__name__)` so the
try/except handlers can `log.exception(...)` if the restore itself fails.

Signed-off-by: Akash Mehra <[email protected]>
The split-API runs each microbatch with global_valid_*=1 (raw sums) and
applies the 1/N rescale once at finish, but the previous code used a
single inv_n for every non-min/max metric. ClippedPGLossFn normalizes
different metrics by different denominators — and some not at all — so
the single-scalar rescale was wrong for:

- Always-toks-normalized metrics under a SEQUENCE_LEVEL loss
  (token_mult_prob_error, gen_kl_error, policy_kl_error,
  js_divergence_error, approx_entropy, probs_ratio, probs_ratio_clamped).
  These came out off by ~average-sequence-length.
- Raw count metrics (num_valid_samples, num_unmasked_tokens) — these are
  ABSOLUTE counts the loss never normalized; the previous code divided
  them by N (e.g. 8.0 came out as 0.0039). Sync path passes them through
  via num_global_batches=1 → identity, then grpo.py's downstream reducer
  sums across microbatches for the global count.

Gradients are unaffected — they derive only from `loss`, whose
normalizer matches inv_n (loss-type-aware).

Fix: add module-level `_METRIC_NORMALIZATION_KIND` mapping each known
metric name to one of {toks, seqs, loss_type, none, skip}. In
`finish_train_step`, look up each metric's kind and apply the right
scale. Unknown metric names default to "loss_type" — preserves prior
behavior for any metric not in the table.

The catalog follows terrykong's review on NVIDIA-NeMo#2683 (`:789`/`:845`).
sampling_importance_ratio and is_oob_ratio have a flag-dependent
denominator (sequence_level_importance_ratios / sequence_level_loss_mask
toggles); for now they default to "loss_type" with a TODO noting the
seq-mask-tis + token-level mismatch.

Signed-off-by: Akash Mehra <[email protected]>
Two small follow-ups to terrykong's NVIDIA-NeMo#2683 review:

- :832 — capture curr_lr / curr_wd BEFORE scheduler.step so the per-mb
  metrics carry the value of THIS step, not the next. Drops the
  duplicate capture from inside the rescale loop.
- :538 — drop the misleading "Mirrors the v1/v2 implementations" line
  from the split-API block docstring; v1/v2 don't define these methods.
  Replaced with a brief surface description (begin / train_microbatch /
  finish / abort) before the mcore-specific details.

No behavior change.

Signed-off-by: Akash Mehra <[email protected]>
Adds the DTensor v1 + v2 backend implementations of the split-API methods
(begin_train_step / train_microbatch / finish_train_step / abort_train_step)
introduced in the mcore PR, plus the PolicyTrainerActor Ray wrapper that
exposes the API to SingleController via ``.remote(...)``.

- DTensor v1: state machine using the N=1 placeholder trick. Per microbatch
  the loss is called with ``global_valid_*=tensor(1.0)`` so backward
  deposits un-normalized gradients; ``finish_train_step`` all_reduces local
  mask sums to recover the true N (toks for TOKEN_LEVEL, seqs for
  SEQUENCE_LEVEL), rescales ``p.grad`` by 1/N, runs grad_norm/clip,
  optimizer.step, scheduler.step. Bin iteration with DP-rank dummy-bin
  padding handles seq-packing / dynamic-batching uneven splits without
  desyncing NCCL.

- DTensor v2: same shape, built on the v2 helpers (LossPostProcessor,
  get_microbatch_iterator, automodel_forward_backward,
  scale_grads_and_clip_grad_norm). The clip helper has MoE/EP awareness;
  the manual 1/N rescale runs before it.

- PolicyTrainerActor: ``@ray.remote(num_cpus=1, num_gpus=0)`` wrapper that
  owns a TQPolicy instance and exposes ``train_from_meta`` (sync proxy),
  ``prepare_logprobs_from_meta``, and the split API. ``trainer_version``
  advances on sync train_from_meta or on ``finish_train_step`` (never on
  abort).

- GPU parity tests at tests/unit/models/policy/test_split_train_step.py:
  numerical equivalence vs sync ``train()`` for token-level and seq-level
  losses, multi-bin-per-call under seq-packing, and split-state-machine
  lifecycle (double begin, abort idempotence). Parameterised over v1/v2.

Signed-off-by: Akash Mehra <[email protected]>
The file exists on this branch (added by the dtensor split-API work)
and pyrefly reports 0 errors for it, so it must be in the whitelist.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
Signed-off-by: Akash Mehra <[email protected]>
Update PolicyTrainerActor.prepare_logprobs_from_meta to accept
refresh_policy_logprobs / refresh_reference_logprobs kwargs and only
dispatch the requested calls. Mirrors the dispatcher signature added to
TQPolicy in NVIDIA-NeMo#2700; SingleController in NVIDIA-NeMo#2700 passes config-driven flags
based on advantage_policy_logprobs_field / advantage_reference_logprobs_field.

Body inlined here (calls TQPolicy.get_logprobs_from_meta and
get_reference_policy_logprobs_from_meta directly) so this PR stays
self-contained without depending on NVIDIA-NeMo#2700's TQPolicy helper. Once both
PRs merge, this can collapse to a one-line delegate.

Signed-off-by: Akash Mehra <[email protected]>
Three issues caught running tests/unit/models/policy/test_split_train_step.py
locally on the v0.5.0 container:

- test_split_train_step_parity_seq_packing was missing several config
  keys the seq-packing path requires (make_sequence_length_divisible_by,
  algorithm, sequence_length_round, logprob_mb_tokens). It also ran at
  fp32 but the seq-packing path goes through FlashAttention which
  requires fp16/bf16; switched to bfloat16.
- All three parametrized cases passed tokenizer=None; replaced with
  get_tokenizer(config["tokenizer"]) so PolicyConfig wiring works.
- _drive_split_path bypassed Policy._shard_for_train and called
  train_microbatch on each worker directly with the unsharded data, so
  the worker iterators received batches without micro_batch_indices
  populated. Now shards via run_all_workers_sharded_data — each DP rank
  gets its corresponding shard.

All six parametrized cases (token_level / seq_packing / state_machine x
v1 / v2) pass locally on the v0.5.0 container.

Signed-off-by: Akash Mehra <[email protected]>
@mehraakash
mehraakash force-pushed the asyncrl/split_train_dtensor branch from 35fb762 to d22810a Compare June 16, 2026 03:28
mehraakash added a commit to mehraakash/RL that referenced this pull request Jun 16, 2026
- Thread loss_fn through SingleController + begin_train_step. Real bug
  against TQPolicy / MegatronPolicyWorker whose begin_train_step requires
  loss_fn with no default; previously masked by the dryrun stub.
- SC owns trainer_version: drop result["trainer_version"] read (key not
  emitted by real backends); bump immediately after finish_train_step
  succeeds, before clear_samples, so SC's counter matches worker state
  even if clear_samples fails.
- Add TQPolicy.prepare_logprobs_from_meta(meta, refresh_policy_logprobs=,
  refresh_reference_logprobs=) dispatcher over the existing
  get_*_from_meta methods. SC wires it from the per-group hook with
  config-driven flags. PolicyTrainerActor signature mirrored in NVIDIA-NeMo#2692.
- Wrap _train_pump per-step body in try/except: on mid-step worker
  failure, call abort_train_step on the worker and clear the
  consumed-ids ledger before re-raising. TODO: retry policy is a
  follow-up.
- Document max_concurrency=1 contract in _train_pump docstring; set it
  explicitly on MegatronPolicyWorker rather than relying on Ray's
  sync-actor default.
- Migrate SingleControllerConfig from @DataClass to
  pydantic.BaseModel(extra="allow") to match the repo's MasterConfig
  style. Drop the extra: dict workaround field and the runtime Literal
  assert (pydantic validates at construction).
- Move five cross-actor TQ schema field names to module-level constants
  (PROMPT_IDS_FIELD, REWARD_FIELD, TOKEN_MASK_FIELD, SAMPLE_MASK_FIELD,
  ADVANTAGE_OUTPUT_FIELD). They're a fixed protocol with the rollout
  actor, not user-tunable.
- Drop dead RAY_TEMP_DIR macOS workaround from the dryrun test header
  (Linux CI doesn't need it; mac devs can set RAY_TMPDIR in shell).
- Tighten reap timeout to 0.0 for a true non-blocking peek; was 0.05.
- print -> log.info for the strict_on_policy auto-set notice.
- Add dryrun test exercising prepare_logprobs_from_meta with both flags
  set, only policy set, and neither set.

Signed-off-by: Akash Mehra <[email protected]>
yuki-97 added a commit that referenced this pull request Jun 19, 2026
Split SC bring-up into two factories that match the actor model:

- setup_handle wires the four remote handles SC drives: dp_client,
  gen_handle, trainer_handle, env_handles. Internally delegates to
  grpo.setup with a TQ-mediated policy factory so the async path stays
  in step with grpo_train_sync; env_handles can be supplied by the
  caller or derived via setup_response_data.
- setup_single_controller_component builds the six local objects SC
  owns inside its actor process: dataloader, weight_synchronizer,
  advantage_estimator, tokenizer, rollout_manager, tq_buffer. Sharing a
  single TQReplayBuffer between RolloutManager and the sampler keeps
  the rollout writer + sampler in sync.

Both factories take a MasterConfig directly (no Ray init, no cluster
setup of their own) so the example launcher can compose them.

trainer_handle is currently set to the TQPolicy returned by grpo.setup;
SC's split-API ".remote(...)" calls expect a Ray actor wrapper
(PolicyTrainerActor from PR #2692). The wrapping point is documented in
the module docstring so the swap is mechanical once that lands.

Unit tests patch grpo.setup / setup_response_data / create_weight_synchronizer
to verify the factory shape, env_handles fallback, partition_id pass-through,
and the multi-dataloader guard.

Signed-off-by: Yuki Huang <[email protected]>
mehraakash added a commit to mehraakash/RL that referenced this pull request Jul 7, 2026
The file is introduced by NVIDIA-NeMo#2692 (DTensor PR), not by this branch.
Whitelisting it here causes pyrefly to fail with 'No Python files
matched pattern' since the file does not exist on mcore.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
Signed-off-by: Akash Mehra <[email protected]>
mehraakash added a commit to mehraakash/RL that referenced this pull request Jul 7, 2026
- Thread loss_fn through SingleController + begin_train_step. Real bug
  against TQPolicy / MegatronPolicyWorker whose begin_train_step requires
  loss_fn with no default; previously masked by the dryrun stub.
- SC owns trainer_version: drop result["trainer_version"] read (key not
  emitted by real backends); bump immediately after finish_train_step
  succeeds, before clear_samples, so SC's counter matches worker state
  even if clear_samples fails.
- Add TQPolicy.prepare_logprobs_from_meta(meta, refresh_policy_logprobs=,
  refresh_reference_logprobs=) dispatcher over the existing
  get_*_from_meta methods. SC wires it from the per-group hook with
  config-driven flags. PolicyTrainerActor signature mirrored in NVIDIA-NeMo#2692.
- Wrap _train_pump per-step body in try/except: on mid-step worker
  failure, call abort_train_step on the worker and clear the
  consumed-ids ledger before re-raising. TODO: retry policy is a
  follow-up.
- Document max_concurrency=1 contract in _train_pump docstring; set it
  explicitly on MegatronPolicyWorker rather than relying on Ray's
  sync-actor default.
- Migrate SingleControllerConfig from @DataClass to
  pydantic.BaseModel(extra="allow") to match the repo's MasterConfig
  style. Drop the extra: dict workaround field and the runtime Literal
  assert (pydantic validates at construction).
- Move five cross-actor TQ schema field names to module-level constants
  (PROMPT_IDS_FIELD, REWARD_FIELD, TOKEN_MASK_FIELD, SAMPLE_MASK_FIELD,
  ADVANTAGE_OUTPUT_FIELD). They're a fixed protocol with the rollout
  actor, not user-tunable.
- Drop dead RAY_TEMP_DIR macOS workaround from the dryrun test header
  (Linux CI doesn't need it; mac devs can set RAY_TMPDIR in shell).
- Tighten reap timeout to 0.0 for a true non-blocking peek; was 0.05.
- print -> log.info for the strict_on_policy auto-set notice.
- Add dryrun test exercising prepare_logprobs_from_meta with both flags
  set, only policy set, and neither set.

Signed-off-by: Akash Mehra <[email protected]>
mehraakash added a commit to mehraakash/RL that referenced this pull request Jul 7, 2026
The file is introduced by NVIDIA-NeMo#2692 (DTensor PR), not by this branch.
Whitelisting it here causes pyrefly to fail with 'No Python files
matched pattern' since the file does not exist on mcore.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
Signed-off-by: Akash Mehra <[email protected]>
mehraakash added a commit to mehraakash/RL that referenced this pull request Jul 8, 2026
The file is introduced by NVIDIA-NeMo#2692 (DTensor PR), not by this branch.
Whitelisting it here causes pyrefly to fail with 'No Python files
matched pattern' since the file does not exist on mcore.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
Signed-off-by: Akash Mehra <[email protected]>
mehraakash added a commit to mehraakash/RL that referenced this pull request Jul 8, 2026
- Thread loss_fn through SingleController + begin_train_step. Real bug
  against TQPolicy / MegatronPolicyWorker whose begin_train_step requires
  loss_fn with no default; previously masked by the dryrun stub.
- SC owns trainer_version: drop result["trainer_version"] read (key not
  emitted by real backends); bump immediately after finish_train_step
  succeeds, before clear_samples, so SC's counter matches worker state
  even if clear_samples fails.
- Add TQPolicy.prepare_logprobs_from_meta(meta, refresh_policy_logprobs=,
  refresh_reference_logprobs=) dispatcher over the existing
  get_*_from_meta methods. SC wires it from the per-group hook with
  config-driven flags. PolicyTrainerActor signature mirrored in NVIDIA-NeMo#2692.
- Wrap _train_pump per-step body in try/except: on mid-step worker
  failure, call abort_train_step on the worker and clear the
  consumed-ids ledger before re-raising. TODO: retry policy is a
  follow-up.
- Document max_concurrency=1 contract in _train_pump docstring; set it
  explicitly on MegatronPolicyWorker rather than relying on Ray's
  sync-actor default.
- Migrate SingleControllerConfig from @DataClass to
  pydantic.BaseModel(extra="allow") to match the repo's MasterConfig
  style. Drop the extra: dict workaround field and the runtime Literal
  assert (pydantic validates at construction).
- Move five cross-actor TQ schema field names to module-level constants
  (PROMPT_IDS_FIELD, REWARD_FIELD, TOKEN_MASK_FIELD, SAMPLE_MASK_FIELD,
  ADVANTAGE_OUTPUT_FIELD). They're a fixed protocol with the rollout
  actor, not user-tunable.
- Drop dead RAY_TEMP_DIR macOS workaround from the dryrun test header
  (Linux CI doesn't need it; mac devs can set RAY_TMPDIR in shell).
- Tighten reap timeout to 0.0 for a true non-blocking peek; was 0.05.
- print -> log.info for the strict_on_policy auto-set notice.
- Add dryrun test exercising prepare_logprobs_from_meta with both flags
  set, only policy set, and neither set.

Signed-off-by: Akash Mehra <[email protected]>
yuki-97 pushed a commit to mehraakash/RL that referenced this pull request Jul 14, 2026
- Thread loss_fn through SingleController + begin_train_step. Real bug
  against TQPolicy / MegatronPolicyWorker whose begin_train_step requires
  loss_fn with no default; previously masked by the dryrun stub.
- SC owns trainer_version: drop result["trainer_version"] read (key not
  emitted by real backends); bump immediately after finish_train_step
  succeeds, before clear_samples, so SC's counter matches worker state
  even if clear_samples fails.
- Add TQPolicy.prepare_logprobs_from_meta(meta, refresh_policy_logprobs=,
  refresh_reference_logprobs=) dispatcher over the existing
  get_*_from_meta methods. SC wires it from the per-group hook with
  config-driven flags. PolicyTrainerActor signature mirrored in NVIDIA-NeMo#2692.
- Wrap _train_pump per-step body in try/except: on mid-step worker
  failure, call abort_train_step on the worker and clear the
  consumed-ids ledger before re-raising. TODO: retry policy is a
  follow-up.
- Document max_concurrency=1 contract in _train_pump docstring; set it
  explicitly on MegatronPolicyWorker rather than relying on Ray's
  sync-actor default.
- Migrate SingleControllerConfig from @DataClass to
  pydantic.BaseModel(extra="allow") to match the repo's MasterConfig
  style. Drop the extra: dict workaround field and the runtime Literal
  assert (pydantic validates at construction).
- Move five cross-actor TQ schema field names to module-level constants
  (PROMPT_IDS_FIELD, REWARD_FIELD, TOKEN_MASK_FIELD, SAMPLE_MASK_FIELD,
  ADVANTAGE_OUTPUT_FIELD). They're a fixed protocol with the rollout
  actor, not user-tunable.
- Drop dead RAY_TEMP_DIR macOS workaround from the dryrun test header
  (Linux CI doesn't need it; mac devs can set RAY_TMPDIR in shell).
- Tighten reap timeout to 0.0 for a true non-blocking peek; was 0.05.
- print -> log.info for the strict_on_policy auto-set notice.
- Add dryrun test exercising prepare_logprobs_from_meta with both flags
  set, only policy set, and neither set.

Signed-off-by: Akash Mehra <[email protected]>
@terrykong terrykong added CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) and removed CI:L0 Run doctests and unit tests labels Nov 5, 2026

This branch was previously deployed

2 inactive (outdated) deployments
public — 35fb762f Deployed Jun 9, 2026 by copy-pr-bot[bot] via release / finalize / publish-docs #829
test — 35fb762f Deployed Jun 9, 2026 by copy-pr-bot[bot] via Wait in test approval queue #12097
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants