@@ -39,6 +39,7 @@ def echo(
3939 entrypoint = "echo" ,
4040 args = [msg ],
4141 num_replicas = num_replicas ,
42+ resource = specs .Resource (cpu = 1 , gpu = 0 , memMB = 1024 ),
4243 )
4344 ],
4445 )
@@ -62,12 +63,21 @@ def touch(file: str, image: str = torchx.IMAGE) -> specs.AppDef:
6263 entrypoint = "touch" ,
6364 args = [file ],
6465 num_replicas = 1 ,
66+ resource = specs .Resource (cpu = 1 , gpu = 0 , memMB = 1024 ),
6567 )
6668 ],
6769 )
6870
6971
70- def sh (* args : str , image : str = torchx .IMAGE , num_replicas : int = 1 ) -> specs .AppDef :
72+ def sh (
73+ * args : str ,
74+ image : str = torchx .IMAGE ,
75+ num_replicas : int = 1 ,
76+ cpu : int = 1 ,
77+ gpu : int = 0 ,
78+ memMB : int = 1024 ,
79+ h : Optional [str ] = None ,
80+ ) -> specs .AppDef :
7181 """
7282 Runs the provided command via sh. Currently sh does not support
7383 environment variable substitution.
@@ -76,7 +86,10 @@ def sh(*args: str, image: str = torchx.IMAGE, num_replicas: int = 1) -> specs.Ap
7686 args: bash arguments
7787 image: image to use
7888 num_replicas: number of replicas to run
79-
89+ cpu: number of cpus per replica
90+ gpu: number of gpus per replica
91+ memMB: cpu memory in MB per replica
92+ h: a registered named resource (if specified takes precedence over cpu, gpu, memMB)
8093 """
8194
8295 escaped_args = " " .join (shlex .quote (arg ) for arg in args )
@@ -90,6 +103,7 @@ def sh(*args: str, image: str = torchx.IMAGE, num_replicas: int = 1) -> specs.Ap
90103 entrypoint = "sh" ,
91104 args = ["-c" , escaped_args ],
92105 num_replicas = num_replicas ,
106+ resource = specs .resource (cpu = cpu , gpu = gpu , memMB = memMB , h = h ),
93107 )
94108 ],
95109 )
@@ -102,7 +116,7 @@ def python(
102116 script : Optional [str ] = None ,
103117 image : str = torchx .IMAGE ,
104118 name : str = "torchx_utils_python" ,
105- cpu : int = 2 ,
119+ cpu : int = 1 ,
106120 gpu : int = 0 ,
107121 memMB : int = 1024 ,
108122 h : Optional [str ] = None ,
@@ -164,8 +178,12 @@ def python(
164178def binary (
165179 * args : str ,
166180 entrypoint : str ,
167- name : str = "torchx_utils_python " ,
181+ name : str = "torchx_utils_binary " ,
168182 num_replicas : int = 1 ,
183+ cpu : int = 1 ,
184+ gpu : int = 0 ,
185+ memMB : int = 1024 ,
186+ h : Optional [str ] = None ,
169187) -> specs .AppDef :
170188 """
171189 Test component
@@ -174,6 +192,10 @@ def binary(
174192 args: arguments passed to the program in sys.argv[1:] (ignored with `--c`)
175193 name: name of the job
176194 num_replicas: number of copies to run (each on its own container)
195+ cpu: number of cpus per replica
196+ gpu: number of gpus per replica
197+ memMB: cpu memory in MB per replica
198+ h: a registered named resource (if specified takes precedence over cpu, gpu, memMB)
177199 :return:
178200 """
179201 return specs .AppDef (
@@ -184,8 +206,8 @@ def binary(
184206 image = "<NONE>" ,
185207 entrypoint = entrypoint ,
186208 num_replicas = num_replicas ,
187- resource = specs .Resource (cpu = 2 , gpu = 0 , memMB = 4096 ),
188209 args = [* args ],
210+ resource = specs .resource (cpu = cpu , gpu = gpu , memMB = memMB , h = h ),
189211 )
190212 ],
191213 )
@@ -219,6 +241,7 @@ def copy(src: str, dst: str, image: str = torchx.IMAGE) -> specs.AppDef:
219241 "--dst" ,
220242 dst ,
221243 ],
244+ resource = specs .Resource (cpu = 1 , gpu = 0 , memMB = 1024 ),
222245 ),
223246 ],
224247 )
@@ -261,6 +284,7 @@ def booth(
261284 "--tracker_base" ,
262285 tracker_base ,
263286 ],
287+ resource = specs .Resource (cpu = 1 , gpu = 0 , memMB = 1024 ),
264288 )
265289 ],
266290 )
0 commit comments