@@ -17,15 +17,16 @@ For now lets take a look at the builtins
1717
1818 $ torchx builtins
1919 Found <n> builtin configs:
20- 1. echo
21- 2. touch
20+ ...
21+ i. utils.echo
22+ j. utils.touch
2223 ...
2324
24- Echo looks familiar and simple. Lets understand how to run ``echo ``.
25+ Echo looks familiar and simple. Lets understand how to run ``utils. echo ``.
2526
2627.. code-block :: shell-session
2728
28- $ torchx run --scheduler local echo --help
29+ $ torchx run --scheduler local utils. echo --help
2930 usage: torchx run echo [-h] [--msg MSG]
3031
3132 Echos a message
@@ -38,7 +39,7 @@ We can see that it takes a ``--msg`` argument. Lets try running it locally
3839
3940.. code-block :: shell-session
4041
41- $ torchx run --scheduler local echo --msg "hello world"
42+ $ torchx run --scheduler local utils. echo --msg "hello world"
4243
4344 .. note :: ``echo`` in this context is just an app spec. It is not the application
4445 logic itself but rather just the "job definition" for running `/bin/echo `.
@@ -58,16 +59,16 @@ This is just a regular python file where we define the app spec.
5859
5960.. code-block :: shell-session
6061
61- $ touch ~/echo_torchx .py
62+ $ touch ~/test .py
6263
63- Now copy paste the following into echo_torchx .py
64+ Now copy paste the following into test .py
6465
6566::
6667
6768 import torchx.specs as specs
6869
6970
70- def get_app_spec (num_replicas: int, msg: str = "hello world") -> specs.AppDef:
71+ def echo (num_replicas: int, msg: str = "hello world") -> specs.AppDef:
7172 """
7273 Echos a message to stdout (calls /bin/echo)
7374
@@ -83,8 +84,8 @@ Now copy paste the following into echo_torchx.py
8384 name="echo",
8485 entrypoint="/bin/echo",
8586 image="/tmp",
86- args=[f"replica #{specs.macros.replica_id}: msg"],
87- num_replicas=1 ,
87+ args=[f"replica #{specs.macros.replica_id}: { msg} "],
88+ num_replicas=num_replicas ,
8889 )
8990 ],
9091 )
@@ -103,13 +104,86 @@ Now lets try running our custom ``echo``
103104
104105.. code-block :: shell-session
105106
106- $ torchx run --scheduler local ~/echo_torchx .py --num_replicas 4 --msg "foobar"
107+ $ torchx run --scheduler local ~/test .py:echo --num_replicas 4 --msg "foobar"
107108
108109 replica #0: foobar
109110 replica #1: foobar
110111 replica #2: foobar
111112 replica #3: foobar
112113
114+ Running on Other Images
115+ -----------------------------
116+ So far we've run ``utils.echo `` with ``image=/tmp ``. This means that the
117+ ``entrypoint `` we specified is relative to ``/tmp ``. That did not matter for us
118+ since we specified an absolute path as the entrypoint (``entrypoint=/bin/echo ``).
119+ Had we specified ``entrypoint=echo `` the local scheduler would have tried to invoke
120+ ``/tmp/echo ``.
121+
122+ If you have a pre-built application binary, setting the image to a local directory is a
123+ quick way to validate the application and the ``specs.AppDef ``. But its not all
124+ that useful if you want to run the application on a remote scheduler
125+ (see :ref: `Running On Other Schedulers `).
126+
127+ .. note :: The ``image`` string in ``specs.Role`` is an identifier to a container image
128+ supported by the scheduler. Refer to the scheduler documentation to find out
129+ what container image is supported by the scheduler you want to use.
130+
131+ For ``local `` scheduler we can see that it supports both a local directory
132+ and docker as the image:
133+
134+ .. code-block :: shell-session
135+
136+ $ torchx runopts local
137+
138+ { 'image_type': { 'default': 'dir',
139+ 'help': 'image type. One of [dir, docker]',
140+ 'type': 'str'},
141+ ... <omitted for brevity> ...
142+
143+
144+ .. note :: Before proceeding, you will need docker installed. If you have not done so already
145+ follow the install instructions on: https://docs.docker.com/get-docker/
146+
147+ Now lets try running ``echo `` from a docker container. Modify echo's ``AppDef ``
148+ in ``~/test.py `` you created in the previous section to make the ``image="ubuntu:latest" ``.
149+
150+ ::
151+
152+ import torchx.specs as specs
153+
154+
155+ def echo(num_replicas: int, msg: str = "hello world") -> specs.AppDef:
156+ """
157+ Echos a message to stdout (calls /bin/echo)
158+
159+ Args:
160+ num_replicas: number of copies (in parallel) to run
161+ msg: message to echo
162+
163+ """
164+ return specs.AppDef(
165+ name="echo",
166+ roles=[
167+ specs.Role(
168+ name="echo",
169+ entrypoint="/bin/echo",
170+ image="ubuntu:latest", # IMAGE NOW POINTS TO THE UBUNTU DOCKER IMAGE
171+ args=[f"replica #{specs.macros.replica_id}: {msg}"],
172+ num_replicas=num_replicas,
173+ )
174+ ],
175+ )
176+
177+ Try running the echo app
178+
179+ .. code-block :: shell-session
180+
181+ $ torchx run --scheduler local \
182+ --scheduler_args image_type=docker \
183+ ~/test.py:echo \
184+ --num_replicas 4 \
185+ --msg "foobar from docker!"
186+
113187 Running On Other Schedulers
114188-----------------------------
115189So far we've launched components locally. Lets take a look at how to run this on
0 commit comments