Skip to content

Commit 53c8f50

Browse files
aivanoufacebook-github-bot
authored andcommitted
Remove binary_component (#175)
Summary: Pull Request resolved: #175 The diff replaces the usage of `binary_component` with directly instantiating `AppDef` Reviewed By: kiukchung Differential Revision: D30915931 fbshipit-source-id: 882dc8a4eebec7e7c40000ec6c5e5b05d654c57b
1 parent ea11197 commit 53c8f50

File tree

12 files changed

+67
-149
lines changed

12 files changed

+67
-149
lines changed

docs/source/components/base.rst

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ Base
44
.. automodule:: torchx.components.base
55
.. currentmodule:: torchx.components.base
66

7-
.. automodule:: torchx.components.base.binary_component
8-
.. currentmodule:: torchx.components.base.binary_component
9-
.. autofunction:: binary_component
10-
117
.. automodule:: torchx.components.base.roles
128
.. currentmodule:: torchx.components.base.roles
139
.. autofunction:: create_torch_dist_role

examples/apps/datapreproc/__init__.py

Whitespace-only changes.

examples/apps/datapreproc/component.py

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,15 @@
1515
from typing import Dict, Optional
1616

1717
import torchx.specs as specs
18-
from torchx.components.base.binary_component import binary_component
1918

2019

2120
def data_preproc(
2221
image: str,
23-
entrypoint: str,
2422
output_path: str,
23+
entrypoint: str = "examples/apps/datapreproc/datapreproc.py",
2524
input_path: str = "http://cs231n.stanford.edu/tiny-imagenet-200.zip",
26-
input_md5: str = "90528d7ca1a48142e341f4ef8d21d0de",
2725
env: Optional[Dict[str, str]] = None,
2826
resource: Optional[str] = None,
29-
name: str = "datapreproc",
3027
) -> specs.AppDef:
3128
"""Data PreProc app.
3229
@@ -37,10 +34,8 @@ def data_preproc(
3734
entrypoint: User script to launch
3835
output_path: Url-like path to save the processes compressed images
3936
input_path: Url-like path to fetch the imagenet dataset
40-
input_md5: Hash of the input imagenet dataset file
4137
env: Env variables to transfer to the user script
4238
resource: String representation of the resource
43-
name: Name of the worker
4439
4540
Returns:
4641
specs.AppDef: Torchx AppDef
@@ -50,21 +45,23 @@ def data_preproc(
5045
args = [
5146
"--input_path",
5247
input_path,
53-
"--input_md5",
54-
input_md5,
5548
"--output_path",
5649
output_path,
5750
]
5851
if resource:
5952
resource_def = specs.named_resources[resource]
6053
else:
6154
resource_def = specs.Resource(cpu=1, gpu=0, memMB=1024)
62-
63-
return binary_component(
64-
name="datapreproc_role",
65-
entrypoint=entrypoint,
66-
args=args,
67-
env=env,
68-
image=image,
69-
resource=resource_def,
55+
return specs.AppDef(
56+
name="datapreproc",
57+
roles=[
58+
specs.Role(
59+
name="worker",
60+
image=image,
61+
entrypoint=entrypoint,
62+
args=args,
63+
env=env,
64+
resource=resource_def,
65+
)
66+
],
7067
)

examples/apps/dist_cifar/__init__.py

Whitespace-only changes.

examples/apps/lightning_classy_vision/__init__.py

Whitespace-only changes.

examples/apps/lightning_classy_vision/component.py

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
from typing import Optional, Dict
1515

1616
import torchx.specs.api as torchx
17-
from torchx.components.base.binary_component import binary_component
1817
from torchx.specs import named_resources
1918

2019

@@ -59,15 +58,20 @@ def trainer(
5958
]
6059
if skip_export:
6160
args.append("--skip_export")
62-
return binary_component(
61+
return torchx.AppDef(
6362
name="examples-lightning_classy_vision-trainer",
64-
entrypoint=entrypoint,
65-
args=args,
66-
env=env,
67-
image=image,
68-
resource=named_resources[resource]
69-
if resource
70-
else torchx.Resource(cpu=1, gpu=0, memMB=1024),
63+
roles=[
64+
torchx.Role(
65+
name="worker",
66+
entrypoint=entrypoint,
67+
args=args,
68+
env=env,
69+
image=image,
70+
resource=named_resources[resource]
71+
if resource
72+
else torchx.Resource(cpu=1, gpu=0, memMB=1024),
73+
)
74+
],
7175
)
7276

7377

@@ -88,19 +92,24 @@ def interpret(
8892
output_path: output path for model checkpoints (e.g. file:///foo/bar)
8993
resource: the resources to use
9094
"""
91-
return binary_component(
95+
return torchx.AppDef(
9296
name="examples-lightning_classy_vision-interpret",
93-
entrypoint="examples/apps/lightning_classy_vision/interpret.py",
94-
args=[
95-
"--load_path",
96-
load_path,
97-
"--data_path",
98-
data_path,
99-
"--output_path",
100-
output_path,
97+
roles=[
98+
torchx.Role(
99+
name="worker",
100+
entrypoint="examples/apps/lightning_classy_vision/interpret.py",
101+
args=[
102+
"--load_path",
103+
load_path,
104+
"--data_path",
105+
data_path,
106+
"--output_path",
107+
output_path,
108+
],
109+
image=image,
110+
resource=named_resources[resource]
111+
if resource
112+
else torchx.Resource(cpu=1, gpu=0, memMB=1024),
113+
)
101114
],
102-
image=image,
103-
resource=named_resources[resource]
104-
if resource
105-
else torchx.Resource(cpu=1, gpu=0, memMB=1024),
106115
)

examples/pipelines/kfp/advanced_pipeline.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,12 @@
123123
# datapreproc outputs the data to a specified fsspec path. These paths are all
124124
# specified ahead of time so we have a fully static pipeline.
125125

126-
from torchx.components.base.binary_component import binary_component
126+
127+
from examples.apps.datapreproc.component import data_preproc
127128

128129
processed_data_path: str = os.path.join(args.output_path, "processed")
129-
datapreproc_app: specs.AppDef = binary_component(
130-
name="examples-datapreproc",
131-
entrypoint="examples/apps/datapreproc/datapreproc.py",
132-
args=["--input_path", data_path, "--output_path", processed_data_path],
133-
image=args.image,
130+
datapreproc_app: specs.AppDef = data_preproc(
131+
image=args.image, output_path=processed_data_path, input_path=data_path
134132
)
135133

136134
# %%

examples/pipelines/kfp/intro_pipeline.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,23 @@
2828

2929
import kfp
3030
from torchx import specs
31-
from torchx.components.base.binary_component import binary_component
3231
from torchx.pipelines.kfp.adapter import container_from_app
3332

3433

3534
def pipeline() -> None:
36-
# First we define our AppDef for the component. We use the binary_component
37-
# helper for making single node components. AppDef is a core part of TorchX
35+
# First we define our AppDef for the component. AppDef is a core part of TorchX
3836
# and can be used to describe complex distributed multi container apps or
3937
# just a single node component like here.
40-
echo_app: specs.AppDef = binary_component(
38+
echo_app: specs.AppDef = specs.AppDef(
4139
name="examples-intro",
42-
entrypoint="/bin/echo",
43-
args=["Hello TorchX!"],
44-
image="alpine",
40+
roles=[
41+
specs.Role(
42+
name="worker",
43+
entrypoint="/bin/echo",
44+
args=["Hello TorchX!"],
45+
image="alpine",
46+
)
47+
],
4548
)
4649

4750
# To convert the TorchX AppDef into a KFP container we use

torchx/components/base/binary_component.py

Lines changed: 0 additions & 52 deletions
This file was deleted.

torchx/components/base/test/binary_component_test.py

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)