Skip to content

Commit c63d2b1

Browse files
committed
Skeleton for writing monarch presentation demo
Using a gallery file so it is easy to generate a webpage and notebook from it. added some option config to the sphinx build so that one demo can be quickly rebuild without redoing the whole docs. Differential Revision: [D84272165](https://our.internmc.facebook.com/intern/diff/D84272165/) **NOTE FOR REVIEWERS**: This PR has internal Meta-specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D84272165/)! ghstack-source-id: 315168912 Pull Request resolved: #1478
1 parent 9700834 commit c63d2b1

File tree

5 files changed

+96
-0
lines changed

5 files changed

+96
-0
lines changed
Lines changed: 12 additions & 0 deletions
Loading

docs/source/assets/__init__.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import os
2+
3+
from IPython.display import display, HTML
4+
5+
6+
def show_svg(filename: str) -> None:
7+
"""Display an SVG file centered in the notebook.
8+
9+
Args:
10+
filename: Name of the SVG file (e.g., 'message_flow.svg')
11+
"""
12+
cwd = os.getcwd()
13+
monarch_path, subpath = cwd.rsplit("/docs", maxsplit=1)
14+
svg_path = os.path.join(monarch_path, "source", "assets", filename)
15+
with open(svg_path, "r") as f:
16+
svg_content = f.read()
17+
html_content = f'<div style="text-align: center;">{svg_content}</div>'
18+
display(HTML(html_content))

docs/source/assets/config.py

Whitespace-only changes.

docs/source/conf.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
sys.path.insert(0, os.path.abspath("."))
6464
sys.path.insert(0, os.path.abspath("../.."))
6565
sys.path.insert(0, os.path.abspath("_ext")) # Add our custom extensions
66+
sys.path.insert(0, os.path.abspath("generated/examples")) # assets for examples
6667

6768
html_theme = "pytorch_sphinx_theme2"
6869
html_theme_path = [pytorch_sphinx_theme2.get_html_theme_path()]
@@ -159,6 +160,16 @@
159160
".md": "markdown",
160161
}
161162

163+
164+
ONE_GALLERY_EXAMPLE = os.environ.get("ONE_GALLERY_EXAMPLE", None)
165+
if ONE_GALLERY_EXAMPLE is not None:
166+
import re
167+
168+
exclude_patterns = ["**"] # Reset exclude_patterns to ensure books are included
169+
sphinx_gallery_conf["filename_pattern"] = re.escape(ONE_GALLERY_EXAMPLE)
170+
sphinx_gallery_conf["plot_gallery"] = "True"
171+
sphinx_gallery_conf["only_warn_on_example_error"] = "False"
172+
162173
# Configure MyST-Parser to properly handle relative links in the books directory
163174
myst_url_schemes = ["http", "https", "mailto"]
164175

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
# All rights reserved.
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
# pyre-unsafe
8+
9+
"""
10+
Getting Started
11+
===============
12+
13+
This guide introduces the core concepts of Monarch, a framework for building
14+
multi-machine training programs using actors. We'll cover:
15+
16+
- Defining actors with endpoint functions
17+
- Spawning actors locally and across multiple hosts and processes
18+
- Sending messages and organizing actors into meshes
19+
- The supervision tree for fault tolerance
20+
- Distributed tensors and RDMA capabilities
21+
"""
22+
23+
from assets import show_svg
24+
25+
# %%
26+
# Defining an Actor
27+
# -----------------
28+
# At its core, Monarch uses actors as a way to create multi-machine training programs.
29+
# Actors are Python objects that expose a number of endpoint functions. These functions
30+
# can be called by other actors in the system and their responses gathered asynchronously.
31+
#
32+
# Let's start by defining a simple actor:
33+
34+
from monarch.actor import Actor, endpoint, this_proc
35+
36+
37+
class Counter(Actor):
38+
def __init__(self, initial_value: int):
39+
self.value = initial_value
40+
41+
@endpoint
42+
def increment(self) -> None:
43+
self.value += 1
44+
45+
@endpoint
46+
def get_value(self) -> int:
47+
return self.value
48+
49+
50+
# %%
51+
# Message Flow Diagram
52+
# ===================
53+
# Here's how messages flow between actors:
54+
55+
show_svg("message_flow.svg")

0 commit comments

Comments
 (0)