19
19
from truss .base .validation import (
20
20
validate_cpu_spec ,
21
21
validate_memory_spec ,
22
+ validate_node_count ,
22
23
validate_python_executable_path ,
23
24
validate_secret_name ,
24
25
validate_secret_to_path_mapping ,
43
44
DEFAULT_CPU = "1"
44
45
DEFAULT_MEMORY = "2Gi"
45
46
DEFAULT_USE_GPU = False
46
- DEFAULT_NODE_COUNT = 1
47
47
48
48
DEFAULT_BLOB_BACKEND = HTTP_PUBLIC_BLOB_BACKEND
49
49
@@ -261,7 +261,7 @@ class Resources:
261
261
memory : str = DEFAULT_MEMORY
262
262
use_gpu : bool = DEFAULT_USE_GPU
263
263
accelerator : AcceleratorSpec = field (default_factory = AcceleratorSpec )
264
- node_count : int = DEFAULT_NODE_COUNT
264
+ node_count : Optional [ int ] = None
265
265
266
266
@staticmethod
267
267
def from_dict (d ):
@@ -273,24 +273,27 @@ def from_dict(d):
273
273
use_gpu = d .get ("use_gpu" , DEFAULT_USE_GPU )
274
274
if accelerator .accelerator is not None :
275
275
use_gpu = True
276
- # TODO[rcano]: add validation for node count
277
- node_count = d . get ( "node_count" , DEFAULT_NODE_COUNT )
278
-
279
- return Resources (
280
- cpu = cpu ,
281
- memory = memory ,
282
- use_gpu = use_gpu ,
283
- accelerator = accelerator ,
284
- node_count = node_count ,
285
- )
276
+
277
+ r = Resources ( cpu = cpu , memory = memory , use_gpu = use_gpu , accelerator = accelerator )
278
+
279
+ # only add node_count if not None. This helps keep
280
+ # config generated by truss init concise.
281
+ node_count = d . get ( "node_count" )
282
+ validate_node_count ( node_count )
283
+ r . node_count = node_count
284
+
285
+ return r
286
286
287
287
def to_dict (self ):
288
- return {
288
+ d = {
289
289
"cpu" : self .cpu ,
290
290
"memory" : self .memory ,
291
291
"use_gpu" : self .use_gpu ,
292
292
"accelerator" : self .accelerator .to_str (),
293
293
}
294
+ if self .node_count is not None :
295
+ d ["node_count" ] = self .node_count
296
+ return d
294
297
295
298
296
299
@dataclass
@@ -775,7 +778,7 @@ def _handle_env_vars(env_vars: Dict[str, Any]) -> Dict[str, str]:
775
778
776
779
777
780
DATACLASS_TO_REQ_KEYS_MAP = {
778
- Resources : {"accelerator" , "cpu" , "memory" , "use_gpu" , "node_count" },
781
+ Resources : {"accelerator" , "cpu" , "memory" , "use_gpu" },
779
782
Runtime : {"predict_concurrency" },
780
783
Build : {"model_server" },
781
784
TrussConfig : {
0 commit comments