Files
katib/examples/v1beta1/sdk/nas-with-darts.ipynb
Ayush GuptaandGitHub 1c19d3a6eb Fix Istio sidecar injection by moving from annotations to labels (#2527)
* Fix Istio sidecar injection by moving from annotations to labels

Signed-off-by: madmecodes <[email protected]>

* Update Istio sidecar injection from annotations to labels across the codebase
Replace annotations with labels for Istio sidecar injection according to Istio recommendations. Update conformance tests, examples, constants, composers, and utilities to use the new label-based approach consistently.

Signed-off-by: madmecodes <[email protected]>

* fix: Update SuggestionLabels function and composer implementation for Istio label injection

Signed-off-by: madmecodes <[email protected]>

* Fix linting issues in mpi-job-horovod.py

Signed-off-by: madmecodes <[email protected]>

* update: function moved from annotations to labels

Signed-off-by: madmecodes <[email protected]>

---------

Signed-off-by: madmecodes <[email protected]>
2025-05-09 17:52:41 +00:00

38 KiB

Neural Architecture Search with DARTS

In this example you will deploy Katib Experiment with Differentiable Architecture Search (DARTS) algorithm using Jupyter Notebook and Katib SDK. Your Kubernetes cluster must have at least one GPU for this example.

You can read more about how we use DARTS in Katib here.

The notebook shows how to create, get, check status and delete an Experiment.

In [1]:
# Install required package (Katib SDK).
# TODO (andreyvelich): Update this example with the latest SDK.
!pip install kubeflow-katib==0.13.0
Requirement already satisfied: kubeflow-katib==0.13.0 in /opt/conda/lib/python3.8/site-packages (0.13.0)
Requirement already satisfied: kubernetes>=12.0.0 in /opt/conda/lib/python3.8/site-packages (from kubeflow-katib==0.13.0) (12.0.1)
Requirement already satisfied: six>=1.10 in /opt/conda/lib/python3.8/site-packages (from kubeflow-katib==0.13.0) (1.16.0)
Requirement already satisfied: certifi>=14.05.14 in /opt/conda/lib/python3.8/site-packages (from kubeflow-katib==0.13.0) (2021.5.30)
Requirement already satisfied: urllib3>=1.15.1 in /opt/conda/lib/python3.8/site-packages (from kubeflow-katib==0.13.0) (1.26.5)
Requirement already satisfied: setuptools>=21.0.0 in /opt/conda/lib/python3.8/site-packages (from kubeflow-katib==0.13.0) (49.6.0.post20210108)
Requirement already satisfied: pyyaml>=3.12 in /opt/conda/lib/python3.8/site-packages (from kubernetes>=12.0.0->kubeflow-katib==0.13.0) (5.4.1)
Requirement already satisfied: requests in /opt/conda/lib/python3.8/site-packages (from kubernetes>=12.0.0->kubeflow-katib==0.13.0) (2.25.1)
Requirement already satisfied: google-auth>=1.0.1 in /opt/conda/lib/python3.8/site-packages (from kubernetes>=12.0.0->kubeflow-katib==0.13.0) (1.35.0)
Requirement already satisfied: websocket-client!=0.40.0,!=0.41.*,!=0.42.*,>=0.32.0 in /opt/conda/lib/python3.8/site-packages (from kubernetes>=12.0.0->kubeflow-katib==0.13.0) (1.0.1)
Requirement already satisfied: requests-oauthlib in /opt/conda/lib/python3.8/site-packages (from kubernetes>=12.0.0->kubeflow-katib==0.13.0) (1.3.1)
Requirement already satisfied: python-dateutil>=2.5.3 in /opt/conda/lib/python3.8/site-packages (from kubernetes>=12.0.0->kubeflow-katib==0.13.0) (2.8.1)
Requirement already satisfied: rsa<5,>=3.1.4 in /opt/conda/lib/python3.8/site-packages (from google-auth>=1.0.1->kubernetes>=12.0.0->kubeflow-katib==0.13.0) (4.8)
Requirement already satisfied: pyasn1-modules>=0.2.1 in /opt/conda/lib/python3.8/site-packages (from google-auth>=1.0.1->kubernetes>=12.0.0->kubeflow-katib==0.13.0) (0.2.8)
Requirement already satisfied: cachetools<5.0,>=2.0.0 in /opt/conda/lib/python3.8/site-packages (from google-auth>=1.0.1->kubernetes>=12.0.0->kubeflow-katib==0.13.0) (4.2.4)
Requirement already satisfied: pyasn1<0.5.0,>=0.4.6 in /opt/conda/lib/python3.8/site-packages (from pyasn1-modules>=0.2.1->google-auth>=1.0.1->kubernetes>=12.0.0->kubeflow-katib==0.13.0) (0.4.8)
Requirement already satisfied: chardet<5,>=3.0.2 in /opt/conda/lib/python3.8/site-packages (from requests->kubernetes>=12.0.0->kubeflow-katib==0.13.0) (4.0.0)
Requirement already satisfied: idna<3,>=2.5 in /opt/conda/lib/python3.8/site-packages (from requests->kubernetes>=12.0.0->kubeflow-katib==0.13.0) (2.10)
Requirement already satisfied: oauthlib>=3.0.0 in /opt/conda/lib/python3.8/site-packages (from requests-oauthlib->kubernetes>=12.0.0->kubeflow-katib==0.13.0) (3.2.0)

Import required packages

In [2]:
from kubeflow.katib import KatibClient
from kubernetes.client import V1ObjectMeta
from kubeflow.katib import V1beta1Experiment
from kubeflow.katib import V1beta1AlgorithmSpec
from kubeflow.katib import V1beta1AlgorithmSetting
from kubeflow.katib import V1beta1ObjectiveSpec
from kubeflow.katib import V1beta1MetricsCollectorSpec
from kubeflow.katib import V1beta1CollectorSpec
from kubeflow.katib import V1beta1SourceSpec
from kubeflow.katib import V1beta1FilterSpec
from kubeflow.katib import V1beta1FeasibleSpace
from kubeflow.katib import V1beta1ExperimentSpec
from kubeflow.katib import V1beta1NasConfig
from kubeflow.katib import V1beta1GraphConfig
from kubeflow.katib import V1beta1Operation
from kubeflow.katib import V1beta1ParameterSpec
from kubeflow.katib import V1beta1TrialTemplate
from kubeflow.katib import V1beta1TrialParameterSpec

Define your Experiment

You have to create your Experiment object before deploying it. This Experiment is similar to this example.

You can read more about DARTS algorithm settings here.

In [3]:
# Experiment name and namespace.
namespace = "kubeflow-user-example-com"
experiment_name = "darts-example"

metadata = V1ObjectMeta(
    name=experiment_name,
    namespace=namespace
)


# Algorithm specification.
algorithm_spec=V1beta1AlgorithmSpec(
    algorithm_name="darts",
    algorithm_settings=[
        V1beta1AlgorithmSetting(
            name="num_epochs",
            value="2"
        ),
        V1beta1AlgorithmSetting(
            name="stem_multiplier",
            value="1"
        ),
        V1beta1AlgorithmSetting(
            name="init_channels",
            value="4"
        ),
        V1beta1AlgorithmSetting(
            name="num_nodes",
            value="3"
        ),
        
    ]
)

# Objective specification. For DARTS Goal is omitted.
objective_spec=V1beta1ObjectiveSpec(
    type="maximize",
    objective_metric_name="Best-Genotype",
)

# Metrics collector specification.
# We should specify metrics format to get Genotype from training container.
metrics_collector_spec=V1beta1MetricsCollectorSpec(
    collector=V1beta1CollectorSpec(
        kind="StdOut"
    ),
    source=V1beta1SourceSpec(
        filter=V1beta1FilterSpec(
            metrics_format=[
                "([\\w-]+)=(Genotype.*)"
            ]
        )
    )
)

# Configuration for the Neural Network (NN).
# This NN contains 2 number of layers and 5 various operations with different parameters.
nas_config=V1beta1NasConfig(
    graph_config=V1beta1GraphConfig(
        num_layers=2
    ),
    operations=[
        V1beta1Operation(
            operation_type="separable_convolution",
            parameters=[
                V1beta1ParameterSpec(
                    name="filter_size",
                    parameter_type="categorical",
                    feasible_space=V1beta1FeasibleSpace(
                        list=["3"]
                    ),
                )
            ]
        ),
        V1beta1Operation(
            operation_type="dilated_convolution",
            parameters=[
                V1beta1ParameterSpec(
                    name="filter_size",
                    parameter_type="categorical",
                    feasible_space=V1beta1FeasibleSpace(
                        list=["3", "5"]
                    ),
                )
            ]
        ),
        V1beta1Operation(
            operation_type="avg_pooling",
            parameters=[
                V1beta1ParameterSpec(
                    name="filter_size",
                    parameter_type="categorical",
                    feasible_space=V1beta1FeasibleSpace(
                        list=["3"]
                    ),
                )
            ]
        ),
        V1beta1Operation(
            operation_type="max_pooling",
            parameters=[
                V1beta1ParameterSpec(
                    name="filter_size",
                    parameter_type="categorical",
                    feasible_space=V1beta1FeasibleSpace(
                        list=["3"]
                    ),
                )
            ]
        ),
        V1beta1Operation(
            operation_type="skip_connection",
        ),
    ]
)


# JSON template specification for the Trial's Worker Kubernetes Job.
trial_spec={
    "apiVersion": "batch/v1",
    "kind": "Job",
    "spec": {
        "template": {
            "metadata": {
                "labels": {
                    "sidecar.istio.io/inject": "false"
                }
            },
            "spec": {
                "containers": [
                    {
                        "name": "training-container",
                        "image": "docker.io/kubeflowkatib/darts-cnn-cifar10:v0.13.0",
                        "command": [
                            'python3',
                            'run_trial.py',
                            '--algorithm-settings="${trialParameters.algorithmSettings}"',
                            '--search-space="${trialParameters.searchSpace}"',
                            '--num-layers="${trialParameters.numberLayers}"'
                        ],
                        # Training container requires 1 GPU.
                        "resources": {
                            "limits": {
                                "nvidia.com/gpu": 1
                            }
                        }
                    }
                ],
                "restartPolicy": "Never"
            }
        }
    }
}

# Template with Trial parameters and Trial spec.
# Set retain to True to save trial resources after completion.
trial_template=V1beta1TrialTemplate(
    retain=True,
    primary_container_name="training-container",
    trial_parameters=[
        V1beta1TrialParameterSpec(
            name="algorithmSettings",
            description=" Algorithm settings of DARTS Experiment",
            reference="algorithm-settings"
        ),
        V1beta1TrialParameterSpec(
            name="searchSpace",
            description="Search Space of DARTS Experiment",
            reference="search-space"
        ),
        V1beta1TrialParameterSpec(
            name="numberLayers",
            description="Number of Neural Network layers",
            reference="num-layers"
        ),
    ],
    trial_spec=trial_spec
)


# Experiment object.
experiment = V1beta1Experiment(
    api_version="kubeflow.org/v1beta1",
    kind="Experiment",
    metadata=metadata,
    spec=V1beta1ExperimentSpec(
        max_trial_count=1,
        parallel_trial_count=1,
        max_failed_trial_count=1,
        algorithm=algorithm_spec,
        objective=objective_spec,
        metrics_collector_spec=metrics_collector_spec,
        nas_config=nas_config,
        trial_template=trial_template,
    )
)

You can print the Experiment's info to verify it before submission.

In [4]:
# Print the Trial template container info.
print(experiment.spec.trial_template.trial_spec["spec"]["template"]["spec"]["containers"][0])
{'name': 'training-container', 'image': 'docker.io/kubeflowkatib/darts-cnn-cifar10:v0.13.0', 'command': ['python3', 'run_trial.py', '--algorithm-settings="${trialParameters.algorithmSettings}"', '--search-space="${trialParameters.searchSpace}"', '--num-layers="${trialParameters.numberLayers}"'], 'resources': {'limits': {'nvidia.com/gpu': 1}}}

Create your Experiment

You have to create Katib client to use the SDK

TODO (andreyvelich): Current Experiment link for NAS is incorrect.

In [5]:
# Create client.
kclient = KatibClient()

# Create your Experiment.
kclient.create_experiment(experiment,namespace=namespace)
Out [5]:
Katib Experiment darts-example link here
{'apiVersion': 'kubeflow.org/v1beta1',
 'kind': 'Experiment',
 'metadata': {'creationTimestamp': '2021-10-05T23:49:49Z',
  'generation': 1,
  'managedFields': [{'apiVersion': 'kubeflow.org/v1beta1',
    'fieldsType': 'FieldsV1',
    'fieldsV1': {'f:spec': {'.': {},
      'f:algorithm': {'.': {},
       'f:algorithmName': {},
       'f:algorithmSettings': {}},
      'f:maxFailedTrialCount': {},
      'f:maxTrialCount': {},
      'f:metricsCollectorSpec': {'.': {},
       'f:collector': {'.': {}, 'f:kind': {}},
       'f:source': {'.': {}, 'f:filter': {'.': {}, 'f:metricsFormat': {}}}},
      'f:nasConfig': {'.': {},
       'f:graphConfig': {'.': {}, 'f:numLayers': {}},
       'f:operations': {}},
      'f:objective': {'.': {}, 'f:objectiveMetricName': {}, 'f:type': {}},
      'f:parallelTrialCount': {},
      'f:trialTemplate': {'.': {},
       'f:primaryContainerName': {},
       'f:retain': {},
       'f:trialParameters': {},
       'f:trialSpec': {'.': {},
        'f:apiVersion': {},
        'f:kind': {},
        'f:spec': {'.': {},
         'f:template': {'.': {},
          'f:metadata': {'.': {},
           'f:annotations': {'.': {}, 'f:sidecar.istio.io/inject': {}}},
          'f:spec': {'.': {}, 'f:containers': {}, 'f:restartPolicy': {}}}}}}}},
    'manager': 'OpenAPI-Generator',
    'operation': 'Update',
    'time': '2021-10-05T23:49:49Z'}],
  'name': 'darts-example',
  'namespace': 'kubeflow-user-example-com',
  'resourceVersion': '393947521',
  'uid': '3fbda962-64c0-4474-b1de-03b390f96369'},
 'spec': {'algorithm': {'algorithmName': 'darts',
   'algorithmSettings': [{'name': 'num_epochs', 'value': '2'},
    {'name': 'stem_multiplier', 'value': '1'},
    {'name': 'init_channels', 'value': '4'},
    {'name': 'num_nodes', 'value': '3'}]},
  'maxFailedTrialCount': 1,
  'maxTrialCount': 1,
  'metricsCollectorSpec': {'collector': {'kind': 'StdOut'},
   'source': {'filter': {'metricsFormat': ['([\\w-]+)=(Genotype.*)']}}},
  'nasConfig': {'graphConfig': {'numLayers': 2},
   'operations': [{'operationType': 'separable_convolution',
     'parameters': [{'feasibleSpace': {'list': ['3']},
       'name': 'filter_size',
       'parameterType': 'categorical'}]},
    {'operationType': 'dilated_convolution',
     'parameters': [{'feasibleSpace': {'list': ['3', '5']},
       'name': 'filter_size',
       'parameterType': 'categorical'}]},
    {'operationType': 'avg_pooling',
     'parameters': [{'feasibleSpace': {'list': ['3']},
       'name': 'filter_size',
       'parameterType': 'categorical'}]},
    {'operationType': 'max_pooling',
     'parameters': [{'feasibleSpace': {'list': ['3']},
       'name': 'filter_size',
       'parameterType': 'categorical'}]},
    {'operationType': 'skip_connection'}]},
  'objective': {'metricStrategies': [{'name': 'Best-Genotype',
     'value': 'max'}],
   'objectiveMetricName': 'Best-Genotype',
   'type': 'maximize'},
  'parallelTrialCount': 1,
  'resumePolicy': 'Never',
  'trialTemplate': {'failureCondition': 'status.conditions.#(type=="Failed")#|#(status=="True")#',
   'primaryContainerName': 'training-container',
   'retain': True,
   'successCondition': 'status.conditions.#(type=="Complete")#|#(status=="True")#',
   'trialParameters': [{'description': ' Algorithm settings of DARTS Experiment',
     'name': 'algorithmSettings',
     'reference': 'algorithm-settings'},
    {'description': 'Search Space of DARTS Experiment',
     'name': 'searchSpace',
     'reference': 'search-space'},
    {'description': 'Number of Neural Network layers',
     'name': 'numberLayers',
     'reference': 'num-layers'}],
   'trialSpec': {'apiVersion': 'batch/v1',
    'kind': 'Job',
    'spec': {'template': {'metadata': {'annotations': {'sidecar.istio.io/inject': 'false'}},
      'spec': {'containers': [{'command': ['python3',
          'run_trial.py',
          '--algorithm-settings="${trialParameters.algorithmSettings}"',
          '--search-space="${trialParameters.searchSpace}"',
          '--num-layers="${trialParameters.numberLayers}"'],
         'image': 'docker.io/kubeflowkatib/darts-cnn-cifar10:v0.13.0',
         'name': 'training-container',
         'resources': {'limits': {'nvidia.com/gpu': 1}}}],
       'restartPolicy': 'Never'}}}}}}}

Get your Experiment

You can get your Experiment by name and receive required data.

In [6]:
exp = kclient.get_experiment(name=experiment_name, namespace=namespace)
print(exp)
print("-----------------\n")

# Get the latest status.
print(exp["status"]["conditions"][-1])
{'apiVersion': 'kubeflow.org/v1beta1', 'kind': 'Experiment', 'metadata': {'creationTimestamp': '2021-10-05T23:49:49Z', 'finalizers': ['update-prometheus-metrics'], 'generation': 1, 'managedFields': [{'apiVersion': 'kubeflow.org/v1beta1', 'fieldsType': 'FieldsV1', 'fieldsV1': {'f:spec': {'.': {}, 'f:algorithm': {'.': {}, 'f:algorithmName': {}, 'f:algorithmSettings': {}}, 'f:maxFailedTrialCount': {}, 'f:maxTrialCount': {}, 'f:metricsCollectorSpec': {'.': {}, 'f:collector': {'.': {}, 'f:kind': {}}, 'f:source': {'.': {}, 'f:filter': {'.': {}, 'f:metricsFormat': {}}}}, 'f:nasConfig': {'.': {}, 'f:graphConfig': {'.': {}, 'f:numLayers': {}}, 'f:operations': {}}, 'f:objective': {'.': {}, 'f:objectiveMetricName': {}, 'f:type': {}}, 'f:parallelTrialCount': {}, 'f:trialTemplate': {'.': {}, 'f:primaryContainerName': {}, 'f:retain': {}, 'f:trialParameters': {}, 'f:trialSpec': {'.': {}, 'f:apiVersion': {}, 'f:kind': {}, 'f:spec': {'.': {}, 'f:template': {'.': {}, 'f:metadata': {'.': {}, 'f:annotations': {'.': {}, 'f:sidecar.istio.io/inject': {}}}, 'f:spec': {'.': {}, 'f:containers': {}, 'f:restartPolicy': {}}}}}}}}, 'manager': 'OpenAPI-Generator', 'operation': 'Update', 'time': '2021-10-05T23:49:49Z'}, {'apiVersion': 'kubeflow.org/v1beta1', 'fieldsType': 'FieldsV1', 'fieldsV1': {'f:metadata': {'f:finalizers': {'.': {}, 'v:"update-prometheus-metrics"': {}}}, 'f:status': {'.': {}, 'f:conditions': {}, 'f:currentOptimalTrial': {'.': {}, 'f:bestTrialName': {}, 'f:observation': {'.': {}, 'f:metrics': {}}, 'f:parameterAssignments': {}}, 'f:runningTrialList': {}, 'f:startTime': {}, 'f:trials': {}, 'f:trialsRunning': {}}}, 'manager': 'katib-controller', 'operation': 'Update', 'time': '2021-10-05T23:50:31Z'}], 'name': 'darts-example', 'namespace': 'kubeflow-user-example-com', 'resourceVersion': '393948698', 'uid': '3fbda962-64c0-4474-b1de-03b390f96369'}, 'spec': {'algorithm': {'algorithmName': 'darts', 'algorithmSettings': [{'name': 'num_epochs', 'value': '2'}, {'name': 'stem_multiplier', 'value': '1'}, {'name': 'init_channels', 'value': '4'}, {'name': 'num_nodes', 'value': '3'}]}, 'maxFailedTrialCount': 1, 'maxTrialCount': 1, 'metricsCollectorSpec': {'collector': {'kind': 'StdOut'}, 'source': {'filter': {'metricsFormat': ['([\\w-]+)=(Genotype.*)']}}}, 'nasConfig': {'graphConfig': {'numLayers': 2}, 'operations': [{'operationType': 'separable_convolution', 'parameters': [{'feasibleSpace': {'list': ['3']}, 'name': 'filter_size', 'parameterType': 'categorical'}]}, {'operationType': 'dilated_convolution', 'parameters': [{'feasibleSpace': {'list': ['3', '5']}, 'name': 'filter_size', 'parameterType': 'categorical'}]}, {'operationType': 'avg_pooling', 'parameters': [{'feasibleSpace': {'list': ['3']}, 'name': 'filter_size', 'parameterType': 'categorical'}]}, {'operationType': 'max_pooling', 'parameters': [{'feasibleSpace': {'list': ['3']}, 'name': 'filter_size', 'parameterType': 'categorical'}]}, {'operationType': 'skip_connection'}]}, 'objective': {'metricStrategies': [{'name': 'Best-Genotype', 'value': 'max'}], 'objectiveMetricName': 'Best-Genotype', 'type': 'maximize'}, 'parallelTrialCount': 1, 'resumePolicy': 'Never', 'trialTemplate': {'failureCondition': 'status.conditions.#(type=="Failed")#|#(status=="True")#', 'primaryContainerName': 'training-container', 'retain': True, 'successCondition': 'status.conditions.#(type=="Complete")#|#(status=="True")#', 'trialParameters': [{'description': ' Algorithm settings of DARTS Experiment', 'name': 'algorithmSettings', 'reference': 'algorithm-settings'}, {'description': 'Search Space of DARTS Experiment', 'name': 'searchSpace', 'reference': 'search-space'}, {'description': 'Number of Neural Network layers', 'name': 'numberLayers', 'reference': 'num-layers'}], 'trialSpec': {'apiVersion': 'batch/v1', 'kind': 'Job', 'spec': {'template': {'metadata': {'annotations': {'sidecar.istio.io/inject': 'false'}}, 'spec': {'containers': [{'command': ['python3', 'run_trial.py', '--algorithm-settings="${trialParameters.algorithmSettings}"', '--search-space="${trialParameters.searchSpace}"', '--num-layers="${trialParameters.numberLayers}"'], 'image': 'docker.io/kubeflowkatib/darts-cnn-cifar10:v0.13.0', 'name': 'training-container', 'resources': {'limits': {'nvidia.com/gpu': 1}}}], 'restartPolicy': 'Never'}}}}}}, 'status': {'conditions': [{'lastTransitionTime': '2021-10-05T23:49:49Z', 'lastUpdateTime': '2021-10-05T23:49:49Z', 'message': 'Experiment is created', 'reason': 'ExperimentCreated', 'status': 'True', 'type': 'Created'}, {'lastTransitionTime': '2021-10-05T23:50:30Z', 'lastUpdateTime': '2021-10-05T23:50:30Z', 'message': 'Experiment is running', 'reason': 'ExperimentRunning', 'status': 'True', 'type': 'Running'}], 'currentOptimalTrial': {'bestTrialName': '', 'observation': {'metrics': None}, 'parameterAssignments': None}, 'runningTrialList': ['darts-example-n4fpnxlm'], 'startTime': '2021-10-05T23:49:49Z', 'trials': 1, 'trialsRunning': 1}}
-----------------

{'lastTransitionTime': '2021-10-05T23:50:30Z', 'lastUpdateTime': '2021-10-05T23:50:30Z', 'message': 'Experiment is running', 'reason': 'ExperimentRunning', 'status': 'True', 'type': 'Running'}

Get the current Experiment status

You can check the current Experiment status.

In [7]:
kclient.get_experiment_status(name=experiment_name, namespace=namespace)
Out [7]:
'Succeeded'

You can check if your Experiment is succeeded.

In [8]:
kclient.is_experiment_succeeded(name=experiment_name, namespace=namespace)
Out [8]:
True

Get the best Genotype

Best Genotype is located in the optimal Trial currently. The latest Genotype is the best.

Check your Trial logs to get more information about the training process.

In [9]:
opt_trial = kclient.get_optimal_hyperparameters(name=experiment_name, namespace=namespace)

best_genotype = opt_trial["currentOptimalTrial"]["observation"]["metrics"][0]["latest"]
print(best_genotype)
Genotype(normal=[[('separable_convolution_3x3',0),('dilated_convolution_3x3',1)],[('dilated_convolution_3x3',2),('dilated_convolution_5x5',1)],[('dilated_convolution_5x5',2),('separable_convolution_3x3',3)]],normal_concat=range(2,5),reduce=[[('separable_convolution_3x3',1),('separable_convolution_3x3',0)],[('max_pooling_3x3',2),('max_pooling_3x3',1)],[('max_pooling_3x3',2),('max_pooling_3x3',3)]],reduce_concat=range(2,5))

Delete your Experiments

You can delete your Experiments.

In [10]:
kclient.delete_experiment(name=experiment_name, namespace=namespace)
Out [10]:
{'apiVersion': 'kubeflow.org/v1beta1',
 'kind': 'Experiment',
 'metadata': {'creationTimestamp': '2021-10-05T23:49:49Z',
  'deletionGracePeriodSeconds': 0,
  'deletionTimestamp': '2021-10-05T23:58:39Z',
  'finalizers': ['update-prometheus-metrics'],
  'generation': 2,
  'managedFields': [{'apiVersion': 'kubeflow.org/v1beta1',
    'fieldsType': 'FieldsV1',
    'fieldsV1': {'f:spec': {'.': {},
      'f:algorithm': {'.': {},
       'f:algorithmName': {},
       'f:algorithmSettings': {}},
      'f:maxFailedTrialCount': {},
      'f:maxTrialCount': {},
      'f:metricsCollectorSpec': {'.': {},
       'f:collector': {'.': {}, 'f:kind': {}},
       'f:source': {'.': {}, 'f:filter': {'.': {}, 'f:metricsFormat': {}}}},
      'f:nasConfig': {'.': {},
       'f:graphConfig': {'.': {}, 'f:numLayers': {}},
       'f:operations': {}},
      'f:objective': {'.': {}, 'f:objectiveMetricName': {}, 'f:type': {}},
      'f:parallelTrialCount': {},
      'f:trialTemplate': {'.': {},
       'f:primaryContainerName': {},
       'f:retain': {},
       'f:trialParameters': {},
       'f:trialSpec': {'.': {},
        'f:apiVersion': {},
        'f:kind': {},
        'f:spec': {'.': {},
         'f:template': {'.': {},
          'f:metadata': {'.': {},
           'f:annotations': {'.': {}, 'f:sidecar.istio.io/inject': {}}},
          'f:spec': {'.': {}, 'f:containers': {}, 'f:restartPolicy': {}}}}}}}},
    'manager': 'OpenAPI-Generator',
    'operation': 'Update',
    'time': '2021-10-05T23:49:49Z'},
   {'apiVersion': 'kubeflow.org/v1beta1',
    'fieldsType': 'FieldsV1',
    'fieldsV1': {'f:metadata': {'f:finalizers': {'.': {},
       'v:"update-prometheus-metrics"': {}}},
     'f:status': {'.': {},
      'f:completionTime': {},
      'f:conditions': {},
      'f:currentOptimalTrial': {'.': {},
       'f:bestTrialName': {},
       'f:observation': {'.': {}, 'f:metrics': {}},
       'f:parameterAssignments': {}},
      'f:startTime': {},
      'f:succeededTrialList': {},
      'f:trials': {},
      'f:trialsSucceeded': {}}},
    'manager': 'katib-controller',
    'operation': 'Update',
    'time': '2021-10-05T23:54:31Z'}],
  'name': 'darts-example',
  'namespace': 'kubeflow-user-example-com',
  'resourceVersion': '393962398',
  'uid': '3fbda962-64c0-4474-b1de-03b390f96369'},
 'spec': {'algorithm': {'algorithmName': 'darts',
   'algorithmSettings': [{'name': 'num_epochs', 'value': '2'},
    {'name': 'stem_multiplier', 'value': '1'},
    {'name': 'init_channels', 'value': '4'},
    {'name': 'num_nodes', 'value': '3'}]},
  'maxFailedTrialCount': 1,
  'maxTrialCount': 1,
  'metricsCollectorSpec': {'collector': {'kind': 'StdOut'},
   'source': {'filter': {'metricsFormat': ['([\\w-]+)=(Genotype.*)']}}},
  'nasConfig': {'graphConfig': {'numLayers': 2},
   'operations': [{'operationType': 'separable_convolution',
     'parameters': [{'feasibleSpace': {'list': ['3']},
       'name': 'filter_size',
       'parameterType': 'categorical'}]},
    {'operationType': 'dilated_convolution',
     'parameters': [{'feasibleSpace': {'list': ['3', '5']},
       'name': 'filter_size',
       'parameterType': 'categorical'}]},
    {'operationType': 'avg_pooling',
     'parameters': [{'feasibleSpace': {'list': ['3']},
       'name': 'filter_size',
       'parameterType': 'categorical'}]},
    {'operationType': 'max_pooling',
     'parameters': [{'feasibleSpace': {'list': ['3']},
       'name': 'filter_size',
       'parameterType': 'categorical'}]},
    {'operationType': 'skip_connection'}]},
  'objective': {'metricStrategies': [{'name': 'Best-Genotype',
     'value': 'max'}],
   'objectiveMetricName': 'Best-Genotype',
   'type': 'maximize'},
  'parallelTrialCount': 1,
  'resumePolicy': 'Never',
  'trialTemplate': {'failureCondition': 'status.conditions.#(type=="Failed")#|#(status=="True")#',
   'primaryContainerName': 'training-container',
   'retain': True,
   'successCondition': 'status.conditions.#(type=="Complete")#|#(status=="True")#',
   'trialParameters': [{'description': ' Algorithm settings of DARTS Experiment',
     'name': 'algorithmSettings',
     'reference': 'algorithm-settings'},
    {'description': 'Search Space of DARTS Experiment',
     'name': 'searchSpace',
     'reference': 'search-space'},
    {'description': 'Number of Neural Network layers',
     'name': 'numberLayers',
     'reference': 'num-layers'}],
   'trialSpec': {'apiVersion': 'batch/v1',
    'kind': 'Job',
    'spec': {'template': {'metadata': {'annotations': {'sidecar.istio.io/inject': 'false'}},
      'spec': {'containers': [{'command': ['python3',
          'run_trial.py',
          '--algorithm-settings="${trialParameters.algorithmSettings}"',
          '--search-space="${trialParameters.searchSpace}"',
          '--num-layers="${trialParameters.numberLayers}"'],
         'image': 'docker.io/kubeflowkatib/darts-cnn-cifar10:v0.13.0',
         'name': 'training-container',
         'resources': {'limits': {'nvidia.com/gpu': 1}}}],
       'restartPolicy': 'Never'}}}}}},
 'status': {'completionTime': '2021-10-05T23:54:31Z',
  'conditions': [{'lastTransitionTime': '2021-10-05T23:49:49Z',
    'lastUpdateTime': '2021-10-05T23:49:49Z',
    'message': 'Experiment is created',
    'reason': 'ExperimentCreated',
    'status': 'True',
    'type': 'Created'},
   {'lastTransitionTime': '2021-10-05T23:54:31Z',
    'lastUpdateTime': '2021-10-05T23:54:31Z',
    'message': 'Experiment is running',
    'reason': 'ExperimentRunning',
    'status': 'False',
    'type': 'Running'},
   {'lastTransitionTime': '2021-10-05T23:54:31Z',
    'lastUpdateTime': '2021-10-05T23:54:31Z',
    'message': 'Experiment has succeeded because max trial count has reached',
    'reason': 'ExperimentMaxTrialsReached',
    'status': 'True',
    'type': 'Succeeded'}],
  'currentOptimalTrial': {'bestTrialName': 'darts-example-n4fpnxlm',
   'observation': {'metrics': [{'latest': "Genotype(normal=[[('separable_convolution_3x3',0),('dilated_convolution_3x3',1)],[('dilated_convolution_3x3',2),('dilated_convolution_5x5',1)],[('dilated_convolution_5x5',2),('separable_convolution_3x3',3)]],normal_concat=range(2,5),reduce=[[('separable_convolution_3x3',1),('separable_convolution_3x3',0)],[('max_pooling_3x3',2),('max_pooling_3x3',1)],[('max_pooling_3x3',2),('max_pooling_3x3',3)]],reduce_concat=range(2,5))",
      'max': 'unavailable',
      'min': 'unavailable',
      'name': 'Best-Genotype'}]},
   'parameterAssignments': [{'name': 'algorithm-settings',
     'value': "{'num_epochs': '2', 'w_lr': 0.025, 'w_lr_min': 0.001, 'w_momentum': 0.9, 'w_weight_decay': 0.0003, 'w_grad_clip': 5.0, 'alpha_lr': 0.0003, 'alpha_weight_decay': 0.001, 'batch_size': 128, 'num_workers': 4, 'init_channels': '4', 'print_step': 50, 'num_nodes': '3', 'stem_multiplier': '1'}"},
    {'name': 'search-space',
     'value': "['separable_convolution_3x3', 'dilated_convolution_3x3', 'dilated_convolution_5x5', 'avg_pooling_3x3', 'max_pooling_3x3', 'skip_connection']"},
    {'name': 'num-layers', 'value': '2'}]},
  'startTime': '2021-10-05T23:49:49Z',
  'succeededTrialList': ['darts-example-n4fpnxlm'],
  'trials': 1,
  'trialsSucceeded': 1}}
In [ ]: