Skip to content

fix(nemo-gym): preserve replica identity during routing - #3374

Merged
terrykong merged 6 commits into
mainfrom
ansubramania/gym-shards/replication
Sep 21, 2026
Merged

terrykong merged 6 commits into
mainfrom
ansubramania/gym-shards/replication

Conversation

@ananthsub

@ananthsub ananthsub commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Preserves physical actor identity when one logical shard has multiple replicas.

Replica expansion and round-robin dispatch already use multiple actors. Other paths still keyed results by logical shard name, so one replica could overwrite another replica's timing metrics and failures could identify only the shard.

NemoGymShardSet.instance_label() now uses the shard name when it has one replica and shard/index when it has several. Actor timing metrics, log directories, and stream failures use the same label. Routing metrics zero-fill every actor instance for each prompt group, so normal metric aggregation reports the fraction of groups routed to each replica. Stream validation keeps local input errors as ValueError, while transport failures identify the actor instance that failed.

Replica selection remains round-robin. A future least-in-flight policy requires callers to acquire and release a dispatch lease so completed work can decrement the selected actor's load. This PR does not claim that lifecycle or hide it behind the current handle-only API.

The schema rejects replicas > 1 when placement_strategy is not STRICT_SPREAD. Replicas share one merged configuration and one port range. Placing two replicas on the same node would let them race for the same ports. Colocated instances must instead be separate shards with separate port ranges.

Example

env:
  nemo_gym:
    shards:
      - name: tools
        replicas: 3
        config_paths:
          - resources_servers/workplace_assistant/configs/workplace_assistant.yaml

These instances are reported as tools/0, tools/1, and tools/2.

Dependency

This PR targets the branch from PR #3373.

@copy-pr-bot

copy-pr-bot Bot commented Jul 27, 2026

Copy link
Copy Markdown

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

Contributors can view more details about this message here.

@ananthsub
ananthsub force-pushed the ansubramania/gym-shards/replication branch from e0d1388 to 77fcf6b Compare August 13, 2026 21:44
@ananthsub
ananthsub force-pushed the ansubramania/gym-shards/replication branch from 77fcf6b to 0448453 Compare August 13, 2026 22:04
@ananthsub
ananthsub force-pushed the ansubramania/gym-shards/replication branch from 0448453 to 320431d Compare August 13, 2026 22:14
@ananthsub
ananthsub force-pushed the ansubramania/gym-shards/replication branch 3 times, most recently from 6a314a5 to 768097e Compare August 14, 2026 19:32
@ananthsub
ananthsub force-pushed the ansubramania/gym-shards/replication branch 2 times, most recently from 426099c to c876e21 Compare August 31, 2026 18:11
@ananthsub
ananthsub marked this pull request as ready for review August 31, 2026 18:11
@ananthsub
ananthsub requested review from a team as code owners August 31, 2026 18:11
@copy-pr-bot

copy-pr-bot Bot commented Aug 31, 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.

@ananthsub ananthsub changed the title fix: address NeMo-Gym replicas individually rather than by shard fix(nemo-gym): preserve replica identity during routing Aug 31, 2026
@ananthsub
ananthsub force-pushed the ansubramania/gym-shards/replication branch from c876e21 to 4e15aae Compare September 1, 2026 06:26
@ananthsub ananthsub added the CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) label Sep 1, 2026
@ananthsub

Copy link
Copy Markdown
Contributor Author

/ok to test 4e15aae

@ananthsub
ananthsub force-pushed the ansubramania/gym-shards/replication branch from 4e15aae to 81bacdb Compare September 1, 2026 17:42
@ananthsub

Copy link
Copy Markdown
Contributor Author

/ok to test 81bacdb

@ananthsub
ananthsub force-pushed the ansubramania/gym-shards/replication branch from 81bacdb to 9d3c0cd Compare September 2, 2026 05:51
@ananthsub
ananthsub force-pushed the ansubramania/gym-shards/replication branch from 563d477 to 5cfa9c9 Compare September 17, 2026 16:57
@ananthsub

Copy link
Copy Markdown
Contributor Author

/ok to test 5cfa9c9

@ananthsub
ananthsub force-pushed the ansubramania/gym-shards/replication branch from 5cfa9c9 to 42d8219 Compare September 17, 2026 17:19
@ananthsub

Copy link
Copy Markdown
Contributor Author

/ok to test 42d8219

@ananthsub
ananthsub force-pushed the ansubramania/gym-shards/replication branch from 42d8219 to bca06ea Compare September 17, 2026 19:08
@ananthsub

Copy link
Copy Markdown
Contributor Author

/ok to test bca06ea

@ananthsub

Copy link
Copy Markdown
Contributor Author

/ok to test f503377

macandro96
macandro96 previously approved these changes Sep 18, 2026
@ananthsub

Copy link
Copy Markdown
Contributor Author

/ok to test 9a74630

@ananthsub

Copy link
Copy Markdown
Contributor Author

/ok to test 7bf4e04

@ananthsub

Copy link
Copy Markdown
Contributor Author

/ok to test 876a971

@ananthsub

Copy link
Copy Markdown
Contributor Author

/ok to test 4da801e

@ananthsub

Copy link
Copy Markdown
Contributor Author

/ok to test 67dbb8b

@ananthsub

Copy link
Copy Markdown
Contributor Author

/ok to test 6aa3ae9

@ananthsub

Copy link
Copy Markdown
Contributor Author

/ok to test c3d8177

terrykong
terrykong previously approved these changes Sep 21, 2026
Replica expansion and round-robin dispatch already worked, but everything
downstream of dispatch named only the shard, so the replicas of one shard
were indistinguishable once they reported back.

That was a bug in the metrics, not just a readability gap: timings were
collected into a dict keyed by shard, so the second replica overwrote the
first and the shard reported as though it had done a fraction of its work.
Keying by instance fixes it.

Instances are labelled the way their log directories already are -- the
shard name alone when it has one replica, shard/index when it has more --
so a metric, a log directory, and an error message all agree, and a shard
that is not replicated reads exactly as it did before replicas existed.

A failing replica now names the instance rather than the shard, since the
shard is still serving rows and only one node is at fault.

Also reject replicas on any placement strategy other than STRICT_SPREAD.
Replicas are stamped from one merge, so they share that shard's port range
and no per-replica override exists to give them separate ones. Only
STRICT_SPREAD guarantees each replica its own node and therefore its own
port space; elsewhere two replicas can land together and race for the same
ports at spinup. Gym picks a port at random and test-binds it before use,
so that surfaces as an intermittent startup failure rather than a
deterministic one. Since no config can express a fix, the combination is
refused at parse time rather than warned about after the placement group
has been built.

Signed-off-by: Ananth Subramaniam <[email protected]>
Keep local row-validation failures as ValueError while retaining shard-instance
attribution for actor stream failures under the new retry path.

Signed-off-by: Ananth Subramaniam <[email protected]>
Attach instance attribution as an exception note so routing remains diagnosable without breaking callers that classify transport failures by exception type.

Signed-off-by: Ananth Subramaniam <[email protected]>
Match the tokenizer-free rollout call and verify instance attribution without replacing the original actor failure.

Signed-off-by: Ananth Subramaniam <[email protected]>
@terrykong

Copy link
Copy Markdown
Collaborator

/ok to test 524f723

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.

3 participants