@@ -42,22 +42,40 @@ def generate_click_command(
4242
4343 def decorator (func : Callable ) -> Callable :
4444 # build resources from CPU/memory options
45- def _build_resources (cpu , memory , gpu ):
46- if cpu is None and memory is None and gpu is None :
45+ def _build_resources (cpu , cpu_limit , memory , memory_limit , gpu , gpu_limit ,
46+ accelerator_partition_type , accelerator_partition_count ):
47+ if not any ([cpu , cpu_limit , memory , memory_limit , gpu , gpu_limit ,
48+ accelerator_partition_type , accelerator_partition_count ]):
4749 return None
50+
51+ if (accelerator_partition_type is None ) ^ (accelerator_partition_count is None ):
52+ raise click .UsageError (
53+ "Both accelerator-partition-type and accelerator-partition-count must be specified together"
54+ )
4855
4956 # Build requests dictionary
5057 requests = {}
58+ limits = {}
5159 if cpu is not None :
5260 requests ["cpu" ] = cpu
61+ if cpu_limit is not None :
62+ limits ["cpu" ] = cpu_limit
5363 if memory is not None :
5464 requests ["memory" ] = memory
65+ if memory_limit is not None :
66+ limits ["memory" ] = memory_limit
5567 if gpu is not None :
5668 requests ["nvidia.com/gpu" ] = gpu
69+ if gpu_limit is not None :
70+ limits ["nvidia.com/gpu" ] = gpu_limit
71+ if accelerator_partition_type is not None and accelerator_partition_count is not None :
72+ requests [f"nvidia.com/{ accelerator_partition_type } " ] = accelerator_partition_count
73+ limits [f"nvidia.com/{ accelerator_partition_type } " ] = accelerator_partition_count
5774
5875 # Return ResourceRequirements structure
5976 return {
60- "requests" : requests
77+ "requests" : requests ,
78+ "limits" : limits ,
6179 }
6280
6381 def _parse_volume_param (ctx , param , value ):
@@ -140,7 +158,16 @@ def wrapped_func(*args, **kwargs):
140158 if Model is None :
141159 raise click .ClickException (f"Unsupported schema version: { version } " )
142160
143- resources = _build_resources (kwargs .pop ("cpu" , None ), kwargs .pop ("memory" , None ), kwargs .pop ("gpu" , None ))
161+ resources = _build_resources (
162+ kwargs .pop ("cpu" , None ),
163+ kwargs .pop ("cpu_limit" , None ),
164+ kwargs .pop ("memory" , None ),
165+ kwargs .pop ("memory_limit" , None ),
166+ kwargs .pop ("gpu" , None ),
167+ kwargs .pop ("gpu_limit" , None ),
168+ kwargs .pop ("accelerator_partition_type" , None ),
169+ kwargs .pop ("accelerator_partition_count" , None ),
170+ )
144171 if resources is not None :
145172 kwargs ["resources" ] = resources
146173
@@ -210,21 +237,56 @@ def wrapped_func(*args, **kwargs):
210237 "--cpu" ,
211238 type = str ,
212239 default = None ,
213- help = "CPU resource, e.g. '250m'" ,
240+ help = "CPU resource request, e.g. '250m'" ,
241+ )(wrapped_func )
242+
243+ wrapped_func = click .option (
244+ "--cpu-limit" ,
245+ type = str ,
246+ default = None ,
247+ help = "CPU resource limit, e.g. '250m'" ,
214248 )(wrapped_func )
215249
216250 wrapped_func = click .option (
217251 "--memory" ,
218252 type = str ,
219253 default = None ,
220- help = "Memory resource, e.g. '256Mi'" ,
254+ help = "Memory resource request, e.g. '256Mi'" ,
255+ )(wrapped_func )
256+
257+ wrapped_func = click .option (
258+ "--memory-limit" ,
259+ type = str ,
260+ default = None ,
261+ help = "Memory resource limit, e.g. '256Mi'" ,
221262 )(wrapped_func )
222263
223264 wrapped_func = click .option (
224265 "--gpu" ,
225266 type = str ,
226267 default = None ,
227- help = "Gpu resource, e.g. '1'" ,
268+ help = "Gpu resource request, e.g. '1'" ,
269+ )(wrapped_func )
270+
271+ wrapped_func = click .option (
272+ "--gpu-limit" ,
273+ type = str ,
274+ default = None ,
275+ help = "Gpu resource limit, e.g. '1'" ,
276+ )(wrapped_func )
277+
278+ wrapped_func = click .option (
279+ "--accelerator-partition-type" ,
280+ type = str ,
281+ default = None ,
282+ help = "Fractional GPU parition type" ,
283+ )(wrapped_func )
284+
285+ wrapped_func = click .option (
286+ "--accelerator-partition-count" ,
287+ type = str ,
288+ default = None ,
289+ help = "Fractional GPU parition count" ,
228290 )(wrapped_func )
229291
230292 wrapped_func = click .option (
0 commit comments