Skip to content

Commit a54ddc4

Browse files
aivanoufacebook-github-bot
authored andcommitted
Move examples under torchx module (#224)
Summary: Pull Request resolved: #224 The diff moves `examples` under `torchx` namespace, also removes examples Dockerfile, and makes torchx image to use dev-requirements Reviewed By: kiukchung Differential Revision: D31464358 fbshipit-source-id: c56a92ce1fbf5b2881156e57152aa9d40af9eac8
1 parent f6d16cd commit a54ddc4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+45
-84
lines changed

.coveragerc

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ source =
44

55
omit =
66
*test*
7+
torchx/examples/*

dev-requirements.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ torchserve>=0.4.0
1414
captum>=0.3.1
1515
importlib-metadata
1616
ax-platform[mysql]>=0.2.2
17-
fsspec>=2021.09.0
17+
fsspec[s3]>=2021.09.0
18+
torch-model-archiver>=0.4.2

docs/source/conf.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,8 @@ def handle_item(fieldarg, content):
324324

325325
sphinx_gallery_conf = {
326326
"examples_dirs": [
327-
"../../examples/apps",
328-
"../../examples/pipelines",
327+
"../../torchx/examples/apps",
328+
"../../torchx/examples/pipelines",
329329
],
330330
"gallery_dirs": [
331331
"examples_apps",

examples/apps/Dockerfile

-12
This file was deleted.

scripts/component_integration_tests.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,10 @@ def get_local_docker_sched_info(image: str) -> SchedulerInfo:
5252
def main() -> None:
5353
print("Starting components integration tests")
5454
torchx_image = "dummy_image"
55-
examples_image = "dummy_image"
5655
dryrun: bool = False
5756
try:
5857
build = build_and_push_image()
5958
torchx_image = build.torchx_image
60-
examples_image = build.examples_image
6159
except MissingEnvError:
6260
dryrun = True
6361
print("Skip runnig tests, executed only docker buid step")
@@ -75,8 +73,8 @@ def main() -> None:
7573
test_suite.run_components(
7674
examples_app_defs_providers,
7775
scheduler_infos=[
78-
get_local_docker_sched_info(examples_image),
79-
get_k8s_sched_info(examples_image),
76+
get_local_docker_sched_info(torchx_image),
77+
get_k8s_sched_info(torchx_image),
8078
],
8179
dryrun=dryrun,
8280
)

scripts/example_app_defs.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
"""
1111

1212

13-
import examples.apps.datapreproc.component as dp_component
14-
import examples.apps.dist_cifar.component as dist_cifar_component
15-
import examples.apps.lightning_classy_vision.component as cv_component
13+
import torchx.examples.apps.datapreproc.component as dp_component
14+
import torchx.examples.apps.dist_cifar.component as dist_cifar_component
15+
import torchx.examples.apps.lightning_classy_vision.component as cv_component
1616
from torchx.components.integration_tests.component_provider import ComponentProvider
1717
from torchx.specs import AppDef
1818

scripts/integ_test_utils.py

-22
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
class BuildInfo:
1818
id: str
1919
torchx_image: str
20-
examples_image: str
2120

2221

2322
class MissingEnvError(AssertionError):
@@ -41,15 +40,6 @@ def run_in_bg(*args: str) -> "subprocess.Popen[str]":
4140
return subprocess.Popen(args)
4241

4342

44-
def build_examples_canary(id: str) -> str:
45-
examples_tag = "torchx_examples_canary"
46-
47-
print(f"building {examples_tag}")
48-
run("docker", "build", "-t", examples_tag, "examples/apps/")
49-
50-
return examples_tag
51-
52-
5343
def build_torchx_canary(id: str) -> str:
5444
torchx_tag = "torchx_canary"
5545

@@ -65,30 +55,18 @@ def torchx_container_tag(id: str) -> str:
6555
return f"{CONTAINER_REPO}:canary_{id}_torchx"
6656

6757

68-
def examples_container_tag(id: str) -> str:
69-
CONTAINER_REPO = getenv_asserts("CONTAINER_REPO")
70-
return f"{CONTAINER_REPO}:canary_{id}_examples"
71-
72-
7358
def build_images() -> BuildInfo:
7459
id = f"{getuser()}_{random_id()}"
75-
examples_image = build_examples_canary(id)
7660
torchx_image = build_torchx_canary(id)
7761
return BuildInfo(
7862
id=id,
7963
torchx_image=torchx_image,
80-
examples_image=examples_image,
8164
)
8265

8366

8467
def push_images(build: BuildInfo) -> None:
85-
examples_tag = examples_container_tag(build.id)
86-
run("docker", "tag", build.examples_image, examples_tag)
87-
build.examples_image = examples_tag
88-
8968
torchx_tag = torchx_container_tag(build.id)
9069
run("docker", "tag", build.torchx_image, torchx_tag)
9170
build.torchx_image = torchx_tag
9271

93-
run("docker", "push", examples_tag)
9472
run("docker", "push", torchx_tag)

scripts/kfpint.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
```
2525
export KFP_NAMESPACE=<kfp namespace>
2626
export INTEGRATION_TEST_STORAGE=<cloud storage path>
27-
export EXAMPLES_CONTAINER_REPO=<docker repo>
2827
export TORCHX_CONTAINER_REPO=<docker repo>
2928
```
3029
@@ -141,7 +140,6 @@ def save_advanced_pipeline_spec(path: str, build: BuildInfo) -> None:
141140

142141
id = build.id
143142
torchx_image = build.torchx_image
144-
examples_image = build.examples_image
145143

146144
STORAGE_PATH = os.getenv("INTEGRATION_TEST_STORAGE", "/tmp/storage")
147145
root = os.path.join(STORAGE_PATH, id)
@@ -153,8 +151,6 @@ def save_advanced_pipeline_spec(path: str, build: BuildInfo) -> None:
153151
"--output_path",
154152
output,
155153
"--image",
156-
examples_image,
157-
"--torchx_image",
158154
torchx_image,
159155
"--model_name",
160156
f"tiny_image_net_{id}",
@@ -165,7 +161,7 @@ def save_pipeline_spec(path: str, pipeline_file: str, *args: str) -> None:
165161
print(f"generating pipeline spec for {pipeline_file}")
166162

167163
with tempfile.TemporaryDirectory() as tmpdir:
168-
run(os.path.join("examples/pipelines/kfp", pipeline_file), *args)
164+
run(os.path.join("torchx/examples/pipelines/kfp", pipeline_file), *args)
169165
shutil.copy("pipeline.yaml", path)
170166

171167

@@ -202,7 +198,6 @@ def run_pipeline(build: BuildInfo, pipeline_file: str) -> object:
202198
except MaxRetryError:
203199
print(_connection_error_message())
204200
raise
205-
namespace = getenv_asserts("KFP_NAMESPACE")
206201
resp = client.create_run_from_pipeline_package(
207202
pipeline_file,
208203
arguments={},

scripts/kube_dist_trainer.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
import argparse
1313
import os
1414

15-
from examples.apps.dist_cifar.component import trainer
16-
1715
# pyre-ignore-all-errors[21] # Cannot find module utils
1816
# pyre-ignore-all-errors[11]
1917
from integ_test_utils import (
@@ -23,6 +21,7 @@
2321
BuildInfo,
2422
)
2523
from pyre_extensions import none_throws
24+
from torchx.examples.apps.dist_cifar.component import trainer
2625
from torchx.runner import get_runner
2726
from torchx.specs import Resource, named_resources, RunConfig, AppState
2827

@@ -48,7 +47,7 @@ def build_and_push_image() -> BuildInfo:
4847
def run_job(dryrun: bool = False) -> None:
4948
register_gpu_resource()
5049
build = build_and_push_image()
51-
image = build.examples_image
50+
image = build.torchx_image
5251
runner = get_runner("kubeflow-dist-runner")
5352

5453
storage_path = os.getenv("INTEGRATION_TEST_STORAGE", "/tmp/storage")

torchx/cli/cmd_run.py

+2
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ def _run(self, runner: Runner, args: argparse.Namespace) -> Optional[str]:
140140
return
141141
else:
142142
app_handle = cast(specs.AppHandle, result)
143+
# do not delete this line. It is used by slurm tests to retrieve the app id
144+
print(app_handle)
143145

144146
if args.scheduler.startswith("local"):
145147
self._wait_and_exit(runner, app_handle)
File renamed without changes.

examples/apps/datapreproc/component.py renamed to torchx/examples/apps/datapreproc/component.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
def data_preproc(
2121
image: str,
2222
output_path: str,
23-
entrypoint: str = "examples/apps/datapreproc/datapreproc.py",
23+
entrypoint: str = "torchx/examples/apps/datapreproc/datapreproc.py",
2424
input_path: str = "http://cs231n.stanford.edu/tiny-imagenet-200.zip",
2525
env: Optional[Dict[str, str]] = None,
2626
resource: Optional[str] = None,

examples/apps/datapreproc/test/component_test.py renamed to torchx/examples/apps/datapreproc/test/component_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# This source code is licensed under the BSD-style license found in the
55
# LICENSE file in the root directory of this source tree.
66

7-
import examples.apps.datapreproc.component as datapreproc
7+
import torchx.examples.apps.datapreproc.component as datapreproc
88
from torchx.components.component_test_base import ComponentTestCase
99

1010

examples/apps/dist_cifar/component.py renamed to torchx/examples/apps/dist_cifar/component.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def trainer(
5454
return ddp(
5555
*script_args,
5656
image=image,
57-
entrypoint="examples/apps/dist_cifar/train.py",
57+
entrypoint="torchx/examples/apps/dist_cifar/train.py",
5858
rdzv_backend=rdzv_backend,
5959
rdzv_endpoint=rdzv_endpoint,
6060
resource=resource,

examples/apps/dist_cifar/test/component_test.py renamed to torchx/examples/apps/dist_cifar/test/component_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# This source code is licensed under the BSD-style license found in the
55
# LICENSE file in the root directory of this source tree.
66

7-
import examples.apps.dist_cifar.component as dist_cifar
7+
import torchx.examples.apps.dist_cifar.component as dist_cifar
88
from torchx.components.component_test_base import ComponentTestCase
99

1010

examples/apps/lightning_classy_vision/component.py renamed to torchx/examples/apps/lightning_classy_vision/component.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def trainer(
2121
image: str,
2222
output_path: str,
2323
data_path: Optional[str] = None,
24-
entrypoint: str = "examples/apps/lightning_classy_vision/train.py",
24+
entrypoint: str = "torchx/examples/apps/lightning_classy_vision/train.py",
2525
load_path: str = "",
2626
log_path: str = "/logs",
2727
resource: Optional[str] = None,
@@ -84,7 +84,7 @@ def interpret(
8484
data_path: str,
8585
output_path: str,
8686
resource: Optional[str] = None,
87-
entrypoint: str = "examples/apps/lightning_classy_vision/interpret.py",
87+
entrypoint: str = "torchx/examples/apps/lightning_classy_vision/interpret.py",
8888
) -> torchx.AppDef:
8989
"""Runs the model interpretability app on the model outputted by the training
9090
component.

examples/apps/lightning_classy_vision/interpret.py renamed to torchx/examples/apps/lightning_classy_vision/interpret.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@
3232
# ensure data and module are on the path
3333
sys.path.append(".")
3434

35-
from examples.apps.lightning_classy_vision.data import (
35+
from torchx.examples.apps.lightning_classy_vision.data import (
3636
TinyImageNetDataModule,
3737
download_data,
3838
)
39-
from examples.apps.lightning_classy_vision.model import TinyImageNetModel
39+
from torchx.examples.apps.lightning_classy_vision.model import TinyImageNetModel
4040

4141

4242
# FIXME: captum must be imported after torch otherwise it causes python to crash

examples/apps/lightning_classy_vision/model.py renamed to torchx/examples/apps/lightning_classy_vision/model.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def export_inference_model(
109109
"--model-name",
110110
"tiny_image_net",
111111
"--handler",
112-
"examples/apps/lightning_classy_vision/handler/handler.py",
112+
"torchx/examples/apps/lightning_classy_vision/handler/handler.py",
113113
"--version",
114114
"1",
115115
"--serialized-file",

examples/apps/lightning_classy_vision/test/component_test.py renamed to torchx/examples/apps/lightning_classy_vision/test/component_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# This source code is licensed under the BSD-style license found in the
55
# LICENSE file in the root directory of this source tree.
66

7-
import examples.apps.lightning_classy_vision.component as lightning_classy_vision
7+
import torchx.examples.apps.lightning_classy_vision.component as lightning_classy_vision
88
from torchx.components.component_test_base import ComponentTestCase
99

1010

examples/apps/lightning_classy_vision/test/model_test.py renamed to torchx/examples/apps/lightning_classy_vision/test/model_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import unittest
88

99
import torch
10-
from examples.apps.lightning_classy_vision.model import (
10+
from torchx.examples.apps.lightning_classy_vision.model import (
1111
TinyImageNetModel,
1212
)
1313

examples/apps/lightning_classy_vision/train.py renamed to torchx/examples/apps/lightning_classy_vision/train.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,16 @@
3030
# ensure data and module are on the path
3131
sys.path.append(".")
3232

33-
from examples.apps.lightning_classy_vision.data import (
33+
from torchx.examples.apps.lightning_classy_vision.data import (
3434
TinyImageNetDataModule,
3535
download_data,
3636
create_random_data,
3737
)
38-
from examples.apps.lightning_classy_vision.model import (
38+
from torchx.examples.apps.lightning_classy_vision.model import (
3939
TinyImageNetModel,
4040
export_inference_model,
4141
)
42-
from examples.apps.lightning_classy_vision.profiler import (
42+
from torchx.examples.apps.lightning_classy_vision.profiler import (
4343
SimpleLoggingProfiler,
4444
)
4545

examples/pipelines/kfp/advanced_pipeline.py renamed to torchx/examples/pipelines/kfp/advanced_pipeline.py

+6-12
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,12 @@
3232
# the standard built in apps. If you modify the torchx example code you'll
3333
# need to rebuild the container before launching it on KFP
3434

35-
from torchx.version import TORCHX_IMAGE, EXAMPLES_IMAGE
35+
from torchx.version import TORCHX_IMAGE
3636

3737
parser.add_argument(
3838
"--image",
3939
type=str,
4040
help="docker image to use for the examples apps",
41-
default=EXAMPLES_IMAGE,
42-
)
43-
parser.add_argument(
44-
"--torchx_image",
45-
type=str,
46-
help="docker image to use for the builtin torchx apps",
4741
default=TORCHX_IMAGE,
4842
)
4943

@@ -113,7 +107,7 @@
113107
copy_app: specs.AppDef = copy(
114108
"http://cs231n.stanford.edu/tiny-imagenet-200.zip",
115109
data_path,
116-
image=args.torchx_image,
110+
image=args.image,
117111
)
118112

119113
# %%
@@ -124,7 +118,7 @@
124118
# specified ahead of time so we have a fully static pipeline.
125119

126120

127-
from examples.apps.datapreproc.component import data_preproc
121+
from torchx.examples.apps.datapreproc.component import data_preproc
128122

129123
processed_data_path: str = os.path.join(args.output_path, "processed")
130124
datapreproc_app: specs.AppDef = data_preproc(
@@ -144,7 +138,7 @@
144138
if "__file__" in globals():
145139
sys.path.append(os.path.join(os.path.dirname(__file__), "..", "..", ".."))
146140

147-
from examples.apps.lightning_classy_vision.component import trainer
141+
from torchx.examples.apps.lightning_classy_vision.component import trainer
148142

149143
logs_path: str = os.path.join(args.output_path, "logs")
150144
models_path: str = os.path.join(args.output_path, "models")
@@ -185,7 +179,7 @@
185179
serve_app: specs.AppDef = torchserve(
186180
model_path=os.path.join(models_path, "model.mar"),
187181
management_api=args.management_api,
188-
image=args.torchx_image,
182+
image=args.image,
189183
params={
190184
"model_name": args.model_name,
191185
# set this to allocate a worker
@@ -198,7 +192,7 @@
198192
# own component file. This component takes in the output from datapreproc and
199193
# train components and produces images with integrated gradient results.
200194

201-
from examples.apps.lightning_classy_vision.component import interpret
195+
from torchx.examples.apps.lightning_classy_vision.component import interpret
202196

203197
interpret_path: str = os.path.join(args.output_path, "interpret")
204198
interpret_app: specs.AppDef = interpret(

torchx/examples/pipelines/kfp/test/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)