25
25
from kubeflow .katib .constants import constants
26
26
from kubeflow .katib .utils import utils
27
27
from kubernetes import client , config
28
+ from kubernetes .client .models import V1EnvVar , V1EnvFromSource
28
29
29
30
30
31
class KatibClient (object ):
@@ -140,6 +141,8 @@ def tune(
140
141
parameters : Dict [str , Any ],
141
142
base_image : str = constants .BASE_IMAGE_TENSORFLOW ,
142
143
namespace : Optional [str ] = None ,
144
+ env : Union [Dict [str , str ], List [V1EnvVar ], None ] = None ,
145
+ env_from : Union [V1EnvFromSource , List [V1EnvFromSource ], None ] = None ,
143
146
algorithm_name : str = "random" ,
144
147
algorithm_settings : Union [dict , List [models .V1beta1AlgorithmSetting ], None ] = None ,
145
148
objective_metric_name : str = None ,
@@ -172,6 +175,13 @@ def tune(
172
175
objective function.
173
176
base_image: Image to use when executing the objective function.
174
177
namespace: Namespace for the Experiment.
178
+ env: Environment variable(s) to be attached to each trial container. You can either specifiy
179
+ a list of kubernetes.client.models.V1EnvVar (documented here:
180
+ https://github.com/kubernetes-client/python/blob/master/kubernetes/docs/V1EnvVar.md) or a dictionary
181
+ corresponding to the environment variable name and value pair(s).
182
+ env_from: Source(s) of environment variables to be populated in each trial container. You can either specify
183
+ a kubernetes.client.models.V1EnvFromSource (documented here:
184
+ https://github.com/kubernetes-client/python/blob/master/kubernetes/docs/V1EnvFromSource.md) or a list of such a type.
175
185
algorithm_name: Search algorithm for the HyperParameter tuning.
176
186
algorithm_settings: Settings for the search algorithm given.
177
187
For available fields, check this doc: https://www.kubeflow.org/docs/components/katib/experiment/#search-algorithms-in-detail.
@@ -319,6 +329,12 @@ def tune(
319
329
limits = resources_per_trial ,
320
330
)
321
331
332
+ if isinstance (env , dict ):
333
+ env = [V1EnvVar (name = str (k ), value = str (v )) for k , v in env .items ()]
334
+
335
+ if isinstance (env_from , V1EnvFromSource ):
336
+ env_from = [env_from ]
337
+
322
338
# Create Trial specification.
323
339
trial_spec = client .V1Job (
324
340
api_version = "batch/v1" ,
@@ -336,6 +352,8 @@ def tune(
336
352
image = base_image ,
337
353
command = ["bash" , "-c" ],
338
354
args = [exec_script ],
355
+ env = env ,
356
+ env_from = env_from ,
339
357
resources = resources_per_trial ,
340
358
)
341
359
],
0 commit comments