Skip to content

Commit fda6a86

Browse files
authored
Add missing builtin component docs
Differential Revision: D63643255 Pull Request resolved: #962
1 parent 4da5166 commit fda6a86

File tree

2 files changed

+66
-1
lines changed

2 files changed

+66
-1
lines changed

docs/source/_static/css/torchx.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ article.pytorch-article .py dt span.pre {
3737
.output_area.stderr.docutils.container {
3838
background-color: #fed !important;
3939
}
40-
.note .admonition-title > p {
40+
.note .admonition-title > p, .warning .admonition-title > p {
4141
margin: 0 !important;
4242
font: inherit;
4343
color: inherit;

docs/source/components/utils.rst

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,70 @@ Utils
99
.. autofunction:: sh
1010
.. autofunction:: copy
1111
.. autofunction:: python
12+
13+
Usage is very similar to just regular python, except that this supports remote launches. Example:
14+
15+
.. code-block:: bash
16+
17+
# locally (cmd)
18+
$ torchx run utils.python --image $FBPKG -c "import torch; print(torch.__version__)"
19+
20+
# locally (module)
21+
$ torchx run utils.python --image $FBPKG -m foo.bar.main
22+
23+
# remote (cmd)
24+
$ torchx run -s mast utils.python --image $FBPKG -c "import torch; print(torch.__version__)"
25+
26+
# remote (module)
27+
$ torchx run -s mast utils.python --image $FBPKG -m foo.bar.main
28+
29+
Notes:
30+
31+
* ``torchx run`` patches the current working directory (CWD) on top of ``$FBPKG`` for faster remote iteration.
32+
* Patch contents will contain all changes to local fbcode however, the patch building is only triggered if CWD is a subdirectory of fbcode. If you are running from the root of fbcode (e.g. ~/fbsource/fbcode) your job will NOT be patched!
33+
* Be careful not to abuse ``-c CMD``. Schedulers have a length limit on the arguments, hence don't try to pass long CMDs, use it sparingly.
34+
* In `-m MODULE`, the module needs to be rooted off of fbcode. Example: for ~/fbsource/fbcode/foo/bar/main.py the module is ``-m foo.bar.main``.
35+
* DO NOT override ``base_module`` in ``python_library`` buck rule. If you do, you are on your own, patching won't work.
36+
37+
Inline Script in Component
38+
39+
.. note::
40+
IMPORTANT: DO NOT ABUSE THIS FEATURE! This use be used sparringly and not abused! We reserve the right to remove this feature in the future.
41+
42+
A nice side effect of how TorchX and penv python is built is that you can do pretty much anything that you would normally do with python, with the added benefit that it auto patches your working directory and gives you the ability to run locally and remotely.
43+
This means that python ``-c CMD`` will also work. Here's an example illustrating this
44+
45+
.. code-block:: console
46+
47+
$ cd ~/fbsource/fbcode/torchx/examples/apps
48+
49+
$ ls
50+
component.py config main.py module README.md TARGETS
51+
52+
# lets try getting the version of torch from a prebuilt fbpkg or bento kernel
53+
$ torchx run utils.python --image bento_kernel_pytorch_lightning -c "import torch; print(torch.__version__)"
54+
torchx 2021-10-27 11:27:28 INFO loaded configs from /data/users/kiuk/fbsource/fbcode/torchx/fb/example/.torchxconfig
55+
2021-10-27 11:27:44,633 fbpkg.fetch INFO: completed download of bento_kernel_pytorch_lightning:405
56+
2021-10-27 11:27:44,634 fbpkg.fetch INFO: extracted bento_kernel_pytorch_lightning:405 to bento_kernel_pytorch_lightning
57+
2021-10-27 11:27:48,591 fbpkg.util WARNING: removing old version /home/kiuk/.torchx/fbpkg/bento_kernel_pytorch_lightning/403
58+
All packages downloaded successfully
59+
local_penv://torchx/torchx_utils_python_6effc4e2
60+
torchx 2021-10-27 11:27:49 INFO Waiting for the app to finish...
61+
1.11.0a0+fb
62+
torchx 2021-10-27 11:27:58 INFO Job finished: SUCCEEDED
63+
Now for a more interesting example, lets run a dumb all reduce of a 1-d tensor on 1 worker:
64+
$ torchx run utils.python --image torchx_fb_example \
65+
-c "import torch; import torch.distributed as dist; dist.init_process_group(backend='gloo', init_method='tcp://localhost:29500', rank=0, world_size=1); t=torch.tensor(1); dist.all_reduce(t); print(f'all reduce result: {t.item()}')"
66+
67+
torchx 2021-10-27 10:23:05 INFO loaded configs from /data/users/kiuk/fbsource/fbcode/torchx/fb/example/.torchxconfig
68+
2021-10-27 10:23:09,339 fbpkg.fetch INFO: checksums verified: torchx_fb_example:11
69+
All packages verified
70+
local_penv://torchx/torchx_utils_python_08a41456
71+
torchx 2021-10-27 10:23:09 INFO Waiting for the app to finish...
72+
all reduce result: 1
73+
torchx 2021-10-27 10:23:13 INFO Job finished: SUCCEEDED
74+
WARNING: Long inlined scripts won't work since schedulers typically have a character limit on the length of each argument.
75+
76+
1277
.. autofunction:: booth
1378
.. autofunction:: binary

0 commit comments

Comments
 (0)