Skip to content

Adds monarch.actor_mesh.stack #396

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

allenwang28
Copy link
Contributor

Summary:
Context - one use case coming up in forge work is that we might want some pattern like this:

class Environment(Actor):
    endpoint
    def step(self, action):
        return "step"


class BrowserEnv(Environment):
    endpoint
    def step(self, action):
        return "browser"


class CodingEnv(Actor):
    endpoint
    def step(self, action):
        return "coding"


m = proc_mesh(...)
browsers = m.spawn("browser", BrowserEnv)
coders = m.spawn("coder", CodingEnv)

Previous APIs that would require:

for a in [browsers, coders]:
    a.step.call().get()

etc.

This change supports:

envs = monarch.stack(browsers, coders)

which enables

envs.step.call().get()

Implementation specific details:

  • Introduces StackedActorMeshRef and StackedEndpoint
    • These are essentially thin wrappers to ActorMeshRef and Endpoint but inherit the same APIs
  • Introduces EndpointInterface for which Endpoint and StackedEndpoint both inherit from.
  • stack can automatically detect the closest ancestor in its inheritance tree, or allow the user to provide a common interface (i.e. if the user prefers a specific common ancestor)

Differential Revision: D77606019

Summary:
Context - one use case coming up in forge work is that we might want some pattern like this:

```
class Environment(Actor):
    endpoint
    def step(self, action):
        return "step"


class BrowserEnv(Environment):
    endpoint
    def step(self, action):
        return "browser"


class CodingEnv(Actor):
    endpoint
    def step(self, action):
        return "coding"


m = proc_mesh(...)
browsers = m.spawn("browser", BrowserEnv)
coders = m.spawn("coder", CodingEnv)
```

Previous APIs that would require:

```
for a in [browsers, coders]:
    a.step.call().get()
```
etc.

This change supports:
```
envs = monarch.stack(browsers, coders)
```

which enables
```
envs.step.call().get()
```

Implementation specific details:
- Introduces `StackedActorMeshRef` and `StackedEndpoint`
    - These are essentially thin wrappers to `ActorMeshRef` and `Endpoint` but inherit the same APIs
- Introduces `EndpointInterface` for which `Endpoint` and `StackedEndpoint` both inherit from.
- `stack` can automatically detect the closest ancestor in its inheritance  tree, or allow the user to provide a common interface (i.e. if the user prefers a specific common ancestor)

Differential Revision: D77606019
@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jul 1, 2025
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D77606019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Meta Open Source bot. fb-exported
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants