Shortcuts

Custom Components

This is a guide on how to build a simple app and custom component spec and launch it via two different schedulers.

See the Quickstart Guide for installation and basic usage.

Hello World

Lets start off with writing a simple “Hello World” python app. This is just a normal python program and can contain anything you’d like.

Note

This example uses Jupyter Notebook %%writefile to create local files for example purposes. Under normal usage you would have these as standalone files.

[1]:
%%writefile my_app.py

import sys
import argparse

def main(user: str) -> None:
    print(f"Hello, {user}!")

if __name__ == "__main__":
    parser = argparse.ArgumentParser(
        description="Hello world app"
    )
    parser.add_argument(
        "--user",
        type=str,
        help="the person to greet",
        required=True,
    )
    args = parser.parse_args(sys.argv[1:])

    main(args.user)
Writing my_app.py

Now that we have an app we can write the component file for it. This function allows us to reuse and share our app in a user friendly way.

We can use this component from the torchx cli or programmatically as part of a pipeline.

[2]:
%%writefile my_component.py

import torchx.specs as specs

def greet(user: str, image: str = "my_app:latest") -> specs.AppDef:
    return specs.AppDef(
        name="hello_world",
        roles=[
            specs.Role(
                name="greeter",
                image=image,
                entrypoint="python",
                args=[
                    "-m", "my_app",
                    "--user", user,
                ],
            )
        ],
    )
Writing my_component.py

We can execute our component via torchx run. The local_cwd scheduler executes the component relative to the current directory.

[3]:
%%sh
torchx run --scheduler local_cwd my_component.py:greet --user "your name"
torchx 2024-05-17 17:51:02 INFO     Tracker configurations: {}
torchx 2024-05-17 17:51:02 INFO     Log directory not set in scheduler cfg. Creating a temporary log dir that will be deleted on exit. To preserve log directory set the `log_dir` cfg option
torchx 2024-05-17 17:51:02 INFO     Log directory is: /tmp/torchx_wad7vlto
torchx 2024-05-17 17:51:02 INFO     Waiting for the app to finish...
greeter/0 Hello, your name!
torchx 2024-05-17 17:51:03 INFO     Job finished: SUCCEEDED
local_cwd://torchx/hello_world-jkq420gtq7q0bd

If we want to run in other environments, we can build a Docker container so we can run our component in Docker enabled environments such as Kubernetes or via the local Docker scheduler.

Note

This requires Docker installed and won’t work in environments such as Google Colab. If you have not done so already follow the install instructions on: https://docs.docker.com/get-docker/

[4]:
%%writefile Dockerfile.custom

FROM ghcr.io/pytorch/torchx:0.1.0rc1

ADD my_app.py .
Writing Dockerfile.custom

Once we have the Dockerfile created we can create our docker image.

[5]:
%%sh
docker build -t my_app:latest -f Dockerfile.custom .
#0 building with "default" instance using docker driver

#1 [internal] load .dockerignore
#1 transferring context: 2B 0.0s done
#1 DONE 0.0s

#2 [internal] load build definition from Dockerfile.custom
#2 transferring dockerfile: 99B 0.0s done
#2 DONE 0.0s

#3 [internal] load metadata for ghcr.io/pytorch/torchx:0.1.0rc1
#3 DONE 0.8s

#4 [internal] load build context
#4 transferring context: 425B done
#4 DONE 0.0s

#5 [1/2] FROM ghcr.io/pytorch/torchx:0.1.0rc1@sha256:a738949601d82e7f100fa1efeb8dde0c35ce44c66726cf38596f96d78dcd7ad3
#5 resolve ghcr.io/pytorch/torchx:0.1.0rc1@sha256:a738949601d82e7f100fa1efeb8dde0c35ce44c66726cf38596f96d78dcd7ad3 done
#5 sha256:4bbfd2c87b7524455f144a03bf387c88b6d4200e5e0df9139a9d5e79110f89ca 0B / 26.70MB 0.1s
#5 sha256:d2e110be24e168b42c1a2ddbc4a476a217b73cccdba69cdcb212b812a88f5726 0B / 857B 0.1s
#5 sha256:889a7173dcfeb409f9d88054a97ab2445f5a799a823f719a5573365ee3662b6f 0B / 189B 0.1s
#5 sha256:3dbec59e804974689ff0739216fb012d3e1cd6694632cd3a85b74b572266ec5c 7.21kB / 7.21kB done
#5 sha256:a738949601d82e7f100fa1efeb8dde0c35ce44c66726cf38596f96d78dcd7ad3 3.25kB / 3.25kB done
#5 sha256:d2e110be24e168b42c1a2ddbc4a476a217b73cccdba69cdcb212b812a88f5726 857B / 857B 0.2s done
#5 sha256:889a7173dcfeb409f9d88054a97ab2445f5a799a823f719a5573365ee3662b6f 189B / 189B 0.2s done
#5 sha256:6009a622672af862e3a3979ffd58a348f95208a4bc3b6f6cea2efda4e8390203 0B / 9.94MB 0.2s
#5 sha256:143f801954310499daa44a8499a49797d2f282b5d56be601557ebe6cbf796907 0B / 2.00GB 0.2s
#5 sha256:4bbfd2c87b7524455f144a03bf387c88b6d4200e5e0df9139a9d5e79110f89ca 8.39MB / 26.70MB 0.4s
#5 sha256:6009a622672af862e3a3979ffd58a348f95208a4bc3b6f6cea2efda4e8390203 2.10MB / 9.94MB 0.4s
#5 sha256:4bbfd2c87b7524455f144a03bf387c88b6d4200e5e0df9139a9d5e79110f89ca 12.58MB / 26.70MB 0.5s
#5 sha256:6009a622672af862e3a3979ffd58a348f95208a4bc3b6f6cea2efda4e8390203 4.19MB / 9.94MB 0.5s
#5 sha256:4bbfd2c87b7524455f144a03bf387c88b6d4200e5e0df9139a9d5e79110f89ca 26.21MB / 26.70MB 0.7s
#5 sha256:4bbfd2c87b7524455f144a03bf387c88b6d4200e5e0df9139a9d5e79110f89ca 26.70MB / 26.70MB 0.8s done
#5 sha256:6009a622672af862e3a3979ffd58a348f95208a4bc3b6f6cea2efda4e8390203 7.34MB / 9.94MB 0.8s
#5 sha256:eccbe17c44e1b27c836dddc42f204bde06f73568b50833556b50324146bd43aa 0B / 132B 0.8s
#5 extracting sha256:4bbfd2c87b7524455f144a03bf387c88b6d4200e5e0df9139a9d5e79110f89ca
#5 sha256:6009a622672af862e3a3979ffd58a348f95208a4bc3b6f6cea2efda4e8390203 9.94MB / 9.94MB 0.8s done
#5 sha256:d4c7af0d4fa735e6727a24afcea4022492c7f29ac85e31ddf3d385bfbf704f71 0B / 21.46MB 0.9s
#5 sha256:eccbe17c44e1b27c836dddc42f204bde06f73568b50833556b50324146bd43aa 132B / 132B 0.9s done
#5 sha256:06b5edd6bf524455a7c5a54cb27ced3ecc540414ecf38c24c80ba4368ebc77de 0B / 257B 1.0s
#5 sha256:d4c7af0d4fa735e6727a24afcea4022492c7f29ac85e31ddf3d385bfbf704f71 4.19MB / 21.46MB 1.2s
#5 sha256:06b5edd6bf524455a7c5a54cb27ced3ecc540414ecf38c24c80ba4368ebc77de 257B / 257B 1.1s done
#5 sha256:f18d016c4ccc1c57c9e34cb119e1e1966287b08aa9b4d52a38b30815a56574b6 0B / 1.71GB 1.2s
#5 sha256:d4c7af0d4fa735e6727a24afcea4022492c7f29ac85e31ddf3d385bfbf704f71 9.44MB / 21.46MB 1.5s
#5 extracting sha256:4bbfd2c87b7524455f144a03bf387c88b6d4200e5e0df9139a9d5e79110f89ca 0.8s done
#5 sha256:d4c7af0d4fa735e6727a24afcea4022492c7f29ac85e31ddf3d385bfbf704f71 21.46MB / 21.46MB 1.7s done
#5 sha256:c0ad16d9fa05dbf708784e8aa10d69153465bae391345020be52cbe0a1701932 0B / 92B 1.7s
#5 sha256:c0ad16d9fa05dbf708784e8aa10d69153465bae391345020be52cbe0a1701932 92B / 92B 1.9s done
#5 extracting sha256:d2e110be24e168b42c1a2ddbc4a476a217b73cccdba69cdcb212b812a88f5726 done
#5 sha256:143f801954310499daa44a8499a49797d2f282b5d56be601557ebe6cbf796907 105.91MB / 2.00GB 2.0s
#5 extracting sha256:889a7173dcfeb409f9d88054a97ab2445f5a799a823f719a5573365ee3662b6f done
#5 extracting sha256:6009a622672af862e3a3979ffd58a348f95208a4bc3b6f6cea2efda4e8390203 0.1s
#5 sha256:30587ba7fd6bcbd1c883125d84517055b2d7f2d35a13faedbc8b15f94b900cc2 0B / 352B 2.0s
#5 sha256:30587ba7fd6bcbd1c883125d84517055b2d7f2d35a13faedbc8b15f94b900cc2 352B / 352B 2.1s done
#5 sha256:909695be1d5003de345714eec2ca3020a48dd8f407fe918cbd47a8db73d7a233 0B / 341.29MB 2.2s
#5 extracting sha256:6009a622672af862e3a3979ffd58a348f95208a4bc3b6f6cea2efda4e8390203 0.6s done
#5 sha256:909695be1d5003de345714eec2ca3020a48dd8f407fe918cbd47a8db73d7a233 22.02MB / 341.29MB 2.9s
#5 sha256:f18d016c4ccc1c57c9e34cb119e1e1966287b08aa9b4d52a38b30815a56574b6 91.23MB / 1.71GB 3.0s
#5 sha256:909695be1d5003de345714eec2ca3020a48dd8f407fe918cbd47a8db73d7a233 39.85MB / 341.29MB 3.2s
#5 sha256:143f801954310499daa44a8499a49797d2f282b5d56be601557ebe6cbf796907 206.57MB / 2.00GB 3.5s
#5 sha256:909695be1d5003de345714eec2ca3020a48dd8f407fe918cbd47a8db73d7a233 68.16MB / 341.29MB 3.7s
#5 sha256:909695be1d5003de345714eec2ca3020a48dd8f407fe918cbd47a8db73d7a233 90.18MB / 341.29MB 4.1s
#5 sha256:f18d016c4ccc1c57c9e34cb119e1e1966287b08aa9b4d52a38b30815a56574b6 181.40MB / 1.71GB 4.4s
#5 sha256:909695be1d5003de345714eec2ca3020a48dd8f407fe918cbd47a8db73d7a233 111.15MB / 341.29MB 4.6s
#5 sha256:909695be1d5003de345714eec2ca3020a48dd8f407fe918cbd47a8db73d7a233 128.97MB / 341.29MB 4.9s
#5 sha256:143f801954310499daa44a8499a49797d2f282b5d56be601557ebe6cbf796907 308.28MB / 2.00GB 5.1s
#5 sha256:909695be1d5003de345714eec2ca3020a48dd8f407fe918cbd47a8db73d7a233 156.24MB / 341.29MB 5.3s
#5 sha256:909695be1d5003de345714eec2ca3020a48dd8f407fe918cbd47a8db73d7a233 183.50MB / 341.29MB 5.7s
#5 sha256:f18d016c4ccc1c57c9e34cb119e1e1966287b08aa9b4d52a38b30815a56574b6 271.58MB / 1.71GB 5.8s
#5 sha256:909695be1d5003de345714eec2ca3020a48dd8f407fe918cbd47a8db73d7a233 206.57MB / 341.29MB 6.1s
#5 sha256:909695be1d5003de345714eec2ca3020a48dd8f407fe918cbd47a8db73d7a233 225.44MB / 341.29MB 6.4s
#5 sha256:143f801954310499daa44a8499a49797d2f282b5d56be601557ebe6cbf796907 415.24MB / 2.00GB 6.7s
#5 sha256:909695be1d5003de345714eec2ca3020a48dd8f407fe918cbd47a8db73d7a233 247.46MB / 341.29MB 6.9s
#5 sha256:f18d016c4ccc1c57c9e34cb119e1e1966287b08aa9b4d52a38b30815a56574b6 357.56MB / 1.71GB 7.1s
#5 sha256:909695be1d5003de345714eec2ca3020a48dd8f407fe918cbd47a8db73d7a233 269.48MB / 341.29MB 7.3s
#5 sha256:909695be1d5003de345714eec2ca3020a48dd8f407fe918cbd47a8db73d7a233 288.36MB / 341.29MB 7.7s
#5 sha256:909695be1d5003de345714eec2ca3020a48dd8f407fe918cbd47a8db73d7a233 306.18MB / 341.29MB 8.1s
#5 sha256:143f801954310499daa44a8499a49797d2f282b5d56be601557ebe6cbf796907 523.24MB / 2.00GB 8.4s
#5 sha256:f18d016c4ccc1c57c9e34cb119e1e1966287b08aa9b4d52a38b30815a56574b6 443.55MB / 1.71GB 8.4s
#5 sha256:909695be1d5003de345714eec2ca3020a48dd8f407fe918cbd47a8db73d7a233 327.16MB / 341.29MB 8.4s
#5 sha256:909695be1d5003de345714eec2ca3020a48dd8f407fe918cbd47a8db73d7a233 341.29MB / 341.29MB 9.1s done
#5 sha256:f119a6d0a466a041afbcb08344ff624b5c5ac5f68b93d33af4827529ea1a6800 0B / 563.38kB 9.3s
#5 sha256:f119a6d0a466a041afbcb08344ff624b5c5ac5f68b93d33af4827529ea1a6800 563.38kB / 563.38kB 9.3s done
#5 sha256:88d87059c913e67971846680d4032b75f96f599f8a67062f668fed6471fc2968 0B / 556.96kB 9.5s
#5 sha256:88d87059c913e67971846680d4032b75f96f599f8a67062f668fed6471fc2968 556.96kB / 556.96kB 9.6s done
#5 sha256:f18d016c4ccc1c57c9e34cb119e1e1966287b08aa9b4d52a38b30815a56574b6 537.92MB / 1.71GB 9.8s
#5 sha256:143f801954310499daa44a8499a49797d2f282b5d56be601557ebe6cbf796907 630.19MB / 2.00GB 10.0s
#5 sha256:f18d016c4ccc1c57c9e34cb119e1e1966287b08aa9b4d52a38b30815a56574b6 631.24MB / 1.71GB 11.2s
#5 sha256:143f801954310499daa44a8499a49797d2f282b5d56be601557ebe6cbf796907 730.86MB / 2.00GB 11.5s
#5 sha256:f18d016c4ccc1c57c9e34cb119e1e1966287b08aa9b4d52a38b30815a56574b6 719.32MB / 1.71GB 12.5s
#5 sha256:143f801954310499daa44a8499a49797d2f282b5d56be601557ebe6cbf796907 831.52MB / 2.00GB 13.0s
#5 sha256:f18d016c4ccc1c57c9e34cb119e1e1966287b08aa9b4d52a38b30815a56574b6 809.50MB / 1.71GB 13.8s
#5 sha256:143f801954310499daa44a8499a49797d2f282b5d56be601557ebe6cbf796907 932.18MB / 2.00GB 14.5s
#5 sha256:f18d016c4ccc1c57c9e34cb119e1e1966287b08aa9b4d52a38b30815a56574b6 898.63MB / 1.71GB 15.1s
#5 sha256:143f801954310499daa44a8499a49797d2f282b5d56be601557ebe6cbf796907 1.03GB / 2.00GB 16.0s
#5 sha256:f18d016c4ccc1c57c9e34cb119e1e1966287b08aa9b4d52a38b30815a56574b6 988.81MB / 1.71GB 16.4s
#5 sha256:f18d016c4ccc1c57c9e34cb119e1e1966287b08aa9b4d52a38b30815a56574b6 1.09GB / 1.71GB 17.8s
#5 sha256:143f801954310499daa44a8499a49797d2f282b5d56be601557ebe6cbf796907 1.14GB / 2.00GB 17.9s
#5 sha256:f18d016c4ccc1c57c9e34cb119e1e1966287b08aa9b4d52a38b30815a56574b6 1.19GB / 1.71GB 19.2s
#5 sha256:143f801954310499daa44a8499a49797d2f282b5d56be601557ebe6cbf796907 1.25GB / 2.00GB 19.5s
#5 sha256:f18d016c4ccc1c57c9e34cb119e1e1966287b08aa9b4d52a38b30815a56574b6 1.28GB / 1.71GB 20.5s
#5 sha256:143f801954310499daa44a8499a49797d2f282b5d56be601557ebe6cbf796907 1.35GB / 2.00GB 21.0s
#5 sha256:f18d016c4ccc1c57c9e34cb119e1e1966287b08aa9b4d52a38b30815a56574b6 1.36GB / 1.71GB 21.7s
#5 sha256:143f801954310499daa44a8499a49797d2f282b5d56be601557ebe6cbf796907 1.45GB / 2.00GB 22.5s
#5 sha256:f18d016c4ccc1c57c9e34cb119e1e1966287b08aa9b4d52a38b30815a56574b6 1.45GB / 1.71GB 23.2s
#5 sha256:143f801954310499daa44a8499a49797d2f282b5d56be601557ebe6cbf796907 1.55GB / 2.00GB 24.0s
#5 sha256:f18d016c4ccc1c57c9e34cb119e1e1966287b08aa9b4d52a38b30815a56574b6 1.55GB / 1.71GB 24.5s
#5 sha256:143f801954310499daa44a8499a49797d2f282b5d56be601557ebe6cbf796907 1.65GB / 2.00GB 25.5s
#5 sha256:f18d016c4ccc1c57c9e34cb119e1e1966287b08aa9b4d52a38b30815a56574b6 1.63GB / 1.71GB 25.7s
#5 sha256:143f801954310499daa44a8499a49797d2f282b5d56be601557ebe6cbf796907 1.76GB / 2.00GB 27.1s
#5 sha256:f18d016c4ccc1c57c9e34cb119e1e1966287b08aa9b4d52a38b30815a56574b6 1.71GB / 1.71GB 27.2s done
#5 sha256:143f801954310499daa44a8499a49797d2f282b5d56be601557ebe6cbf796907 1.86GB / 2.00GB 28.6s
#5 sha256:143f801954310499daa44a8499a49797d2f282b5d56be601557ebe6cbf796907 1.96GB / 2.00GB 30.4s
#5 sha256:143f801954310499daa44a8499a49797d2f282b5d56be601557ebe6cbf796907 2.00GB / 2.00GB 32.2s done
#5 extracting sha256:143f801954310499daa44a8499a49797d2f282b5d56be601557ebe6cbf796907 0.1s
#5 extracting sha256:143f801954310499daa44a8499a49797d2f282b5d56be601557ebe6cbf796907 5.1s
#5 extracting sha256:143f801954310499daa44a8499a49797d2f282b5d56be601557ebe6cbf796907 10.2s
#5 extracting sha256:143f801954310499daa44a8499a49797d2f282b5d56be601557ebe6cbf796907 15.3s
#5 extracting sha256:143f801954310499daa44a8499a49797d2f282b5d56be601557ebe6cbf796907 20.3s
#5 extracting sha256:143f801954310499daa44a8499a49797d2f282b5d56be601557ebe6cbf796907 25.4s
#5 extracting sha256:143f801954310499daa44a8499a49797d2f282b5d56be601557ebe6cbf796907 30.5s
#5 extracting sha256:143f801954310499daa44a8499a49797d2f282b5d56be601557ebe6cbf796907 30.8s done
#5 extracting sha256:eccbe17c44e1b27c836dddc42f204bde06f73568b50833556b50324146bd43aa
#5 extracting sha256:eccbe17c44e1b27c836dddc42f204bde06f73568b50833556b50324146bd43aa done
#5 extracting sha256:d4c7af0d4fa735e6727a24afcea4022492c7f29ac85e31ddf3d385bfbf704f71 0.1s
#5 extracting sha256:d4c7af0d4fa735e6727a24afcea4022492c7f29ac85e31ddf3d385bfbf704f71 0.7s done
#5 extracting sha256:06b5edd6bf524455a7c5a54cb27ced3ecc540414ecf38c24c80ba4368ebc77de done
#5 extracting sha256:f18d016c4ccc1c57c9e34cb119e1e1966287b08aa9b4d52a38b30815a56574b6
#5 extracting sha256:f18d016c4ccc1c57c9e34cb119e1e1966287b08aa9b4d52a38b30815a56574b6 5.1s
#5 extracting sha256:f18d016c4ccc1c57c9e34cb119e1e1966287b08aa9b4d52a38b30815a56574b6 10.2s
#5 extracting sha256:f18d016c4ccc1c57c9e34cb119e1e1966287b08aa9b4d52a38b30815a56574b6 15.2s
#5 extracting sha256:f18d016c4ccc1c57c9e34cb119e1e1966287b08aa9b4d52a38b30815a56574b6 18.0s done
#5 extracting sha256:c0ad16d9fa05dbf708784e8aa10d69153465bae391345020be52cbe0a1701932
#5 extracting sha256:c0ad16d9fa05dbf708784e8aa10d69153465bae391345020be52cbe0a1701932 done
#5 extracting sha256:30587ba7fd6bcbd1c883125d84517055b2d7f2d35a13faedbc8b15f94b900cc2 done
#5 extracting sha256:909695be1d5003de345714eec2ca3020a48dd8f407fe918cbd47a8db73d7a233 0.1s
#5 extracting sha256:909695be1d5003de345714eec2ca3020a48dd8f407fe918cbd47a8db73d7a233 5.5s
#5 extracting sha256:909695be1d5003de345714eec2ca3020a48dd8f407fe918cbd47a8db73d7a233 10.5s
#5 extracting sha256:909695be1d5003de345714eec2ca3020a48dd8f407fe918cbd47a8db73d7a233 12.0s done
#5 extracting sha256:f119a6d0a466a041afbcb08344ff624b5c5ac5f68b93d33af4827529ea1a6800
#5 extracting sha256:f119a6d0a466a041afbcb08344ff624b5c5ac5f68b93d33af4827529ea1a6800 0.0s done
#5 extracting sha256:88d87059c913e67971846680d4032b75f96f599f8a67062f668fed6471fc2968 0.0s done
#5 DONE 102.0s

#6 [2/2] ADD my_app.py .
#6 DONE 0.1s

#7 exporting to image
#7 exporting layers
#7 exporting layers 2.6s done
#7 writing image sha256:065f976d0192d271c2bbbfcee11437701f08bbf430e07d1aa0350c33b6d8cb69 done
#7 naming to docker.io/library/my_app:latest done
#7 DONE 2.6s

We can then launch it on the local scheduler.

[6]:
%%sh
torchx run --scheduler local_docker my_component.py:greet --image "my_app:latest" --user "your name"
torchx 2024-05-17 17:53:04 INFO     Tracker configurations: {}
torchx 2024-05-17 17:53:04 INFO     Checking for changes in workspace `file:///home/runner/work/torchx/torchx/docs/source`...
torchx 2024-05-17 17:53:04 INFO     To disable workspaces pass: --workspace="" from CLI or workspace=None programmatically.
torchx 2024-05-17 17:53:04 INFO     Workspace `file:///home/runner/work/torchx/torchx/docs/source` resolved to filesystem path `/home/runner/work/torchx/torchx/docs/source`
torchx 2024-05-17 17:53:05 WARNING  failed to pull image my_app:latest, falling back to local: 404 Client Error for http+docker://localhost/v1.43/images/create?tag=latest&fromImage=my_app: Not Found ("pull access denied for my_app, repository does not exist or may require 'docker login': denied: requested access to the resource is denied")
torchx 2024-05-17 17:53:05 INFO     Building workspace docker image (this may take a while)...
torchx 2024-05-17 17:53:05 INFO     Step 1/4 : ARG IMAGE
torchx 2024-05-17 17:53:05 INFO     Step 2/4 : FROM $IMAGE
torchx 2024-05-17 17:53:05 INFO      ---> 065f976d0192
torchx 2024-05-17 17:53:05 INFO     Step 3/4 : COPY . .
torchx 2024-05-17 17:53:08 INFO      ---> bd0b75df1f4a
torchx 2024-05-17 17:53:08 INFO     Step 4/4 : LABEL torchx.pytorch.org/version=0.7.0dev0
torchx 2024-05-17 17:53:08 INFO      ---> Running in 2e29a1840b3e
torchx 2024-05-17 17:53:11 INFO     Removing intermediate container 2e29a1840b3e
torchx 2024-05-17 17:53:11 INFO      ---> 5cd0ae9dae6e
torchx 2024-05-17 17:53:11 INFO     [Warning] One or more build-args [WORKSPACE] were not consumed
torchx 2024-05-17 17:53:11 INFO     Successfully built 5cd0ae9dae6e
torchx 2024-05-17 17:53:11 INFO     Built new image `sha256:5cd0ae9dae6e8ffb4c42dc05060170e788c94dbf8a22ef911e247cb00f9b3051` based on original image `my_app:latest` and changes in workspace `file:///home/runner/work/torchx/torchx/docs/source` for role[0]=greeter.
torchx 2024-05-17 17:53:13 INFO     Waiting for the app to finish...
greeter/0 Hello, your name!
torchx 2024-05-17 17:53:14 INFO     Job finished: SUCCEEDED
local_docker://torchx/hello_world-fd45ntspm65nr

If you have a Kubernetes cluster you can use the Kubernetes scheduler to launch this on the cluster instead.

$ docker push my_app:latest
$ torchx run --scheduler kubernetes my_component.py:greet --image "my_app:latest" --user "your name"

Builtins

TorchX also provides a number of builtin components with premade images. You can discover them via:

[7]:
%%sh
torchx builtins
Found 11 builtin components:
  1. dist.ddp
  2. dist.spmd
  3. metrics.tensorboard
  4. serve.torchserve
  5. utils.binary
  6. utils.booth
  7. utils.copy
  8. utils.echo
  9. utils.python
 10. utils.sh
 11. utils.touch

You can use these either from the CLI, from a pipeline or programmatically like you would any other component.

[8]:
%%sh
torchx run utils.echo --msg "Hello :)"
torchx 2024-05-17 17:53:16 INFO     Tracker configurations: {}
torchx 2024-05-17 17:53:16 INFO     Checking for changes in workspace `file:///home/runner/work/torchx/torchx/docs/source`...
torchx 2024-05-17 17:53:16 INFO     To disable workspaces pass: --workspace="" from CLI or workspace=None programmatically.
torchx 2024-05-17 17:53:16 INFO     Workspace `file:///home/runner/work/torchx/torchx/docs/source` resolved to filesystem path `/home/runner/work/torchx/torchx/docs/source`
torchx 2024-05-17 17:56:13 INFO     Building workspace docker image (this may take a while)...
torchx 2024-05-17 17:56:13 INFO     Step 1/4 : ARG IMAGE
torchx 2024-05-17 17:56:13 INFO     Step 2/4 : FROM $IMAGE
torchx 2024-05-17 17:56:13 INFO      ---> 6ed774f35b4f
torchx 2024-05-17 17:56:13 INFO     Step 3/4 : COPY . .
torchx 2024-05-17 17:56:17 INFO      ---> b311147c1fd6
torchx 2024-05-17 17:56:17 INFO     Step 4/4 : LABEL torchx.pytorch.org/version=0.7.0dev0
torchx 2024-05-17 17:56:17 INFO      ---> Running in ee4d4c31059f
torchx 2024-05-17 17:56:21 INFO     Removing intermediate container ee4d4c31059f
torchx 2024-05-17 17:56:21 INFO      ---> 036bbddfd704
torchx 2024-05-17 17:56:21 INFO     [Warning] One or more build-args [WORKSPACE] were not consumed
torchx 2024-05-17 17:56:21 INFO     Successfully built 036bbddfd704
torchx 2024-05-17 17:56:21 INFO     Built new image `sha256:036bbddfd7042dbf8f55d850ce03f1c7e09ea6a79173f7fadef58b66a0a50920` based on original image `ghcr.io/pytorch/torchx:0.7.0dev0` and changes in workspace `file:///home/runner/work/torchx/torchx/docs/source` for role[0]=echo.
torchx 2024-05-17 17:56:22 INFO     Waiting for the app to finish...
torchx 2024-05-17 17:56:22 INFO     Job finished: SUCCEEDED
echo/0 Hello :)
local_docker://torchx/echo-p425hmsr64g0j

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources