Kubeflow Katib Documentation

repository·master·Indexed 23 days ago

https://github.com/kubeflow/katib

A Kubernetes-native AutoML system for automating hyperparameter tuning, neural architecture search, and early stopping for machine learning models. It includes a Python API (kubeflow_katib_api), OpenAPI specifications, and support for custom CRDs via TrialTemplate. The system also provides specialized capabilities for LLM hyperparameter optimization using KatibClient.tune(), integrating with HuggingFace and S3 for model and dataset management.

Tokens
38.6K
Snippets
68
Records
187
Agent score
82%

What's inside Kubeflow Katib

  1. Overview of Kubeflow Katib

    master

    Kubeflow Katib is a Kubernetes-native project designed for automated machine learning (AutoML). It provides capabilities for:

    • Hyperparameter Tuning: Optimizing the parameters of ML models.
    • Neural Architecture Search (NAS): Automatically searching for optimal neural network architectures.
    • Early Stopping: Terminating poorly performing trials early to save resources.

    Katib is framework-agnostic, meaning it can tune applications written in any language. It natively supports popular ML frameworks like TensorFlow, PyTorch, and XGBoost. It can execute training jobs using various Kubernetes Custom Resources, including the Kubeflow Training Operator, Argo Workflows, and Tekton Pipelines.

  2. Access the Kubeflow Katib OpenAPI Specification

    master
    The Kubeflow Katib APIs are defined using the OpenAPI specification. You can find the full specification in the api/openapi-spec/ directory of the repository to understand the available endpoints, request/response schemas, and authentication requirements for interacting with Katib programmatically.
  3. Configure hyperparameter distributions in Katib

    master

    Katib supports various statistical distributions for hyperparameters via the distribution field in the FeasibleSpace configuration. This allows for more precise optimization than simple uniform distributions, such as using logUniform for learning rates or normal for parameters centered around a specific value.

    Supported Distributions

    NameValueDescription
    UNIFORM0Continuous uniform distribution. Samples values evenly between min and max. Use step for quantization (q).
    LOG_UNIFORM1Samples values such that their logarithm is uniformly distributed. Use min and max. Use step for quantization (q).
    NORMAL2Normal (Gaussian) distribution. Samples values according to a mean and standard deviation. Use min and max. Use step for quantization (q).
    LOG_NORMAL3Log-normal distribution. Samples values such that their logarithm is normally distributed. Use min and max. Use step for quantization (q).

    FeasibleSpace Configuration Fields

    When defining a FeasibleSpace, use the following fields:

    • max: Maximum value (for continuous/integer types).
    • min: Minimum value (for continuous/integer types).
    • list: A list of values (for Discrete or Categorical types).
    • step: Defines the quantization step (e.g., q for quantized distributions).
    • distribution: The type of distribution to apply (e.g., uniform, logUniform, normal, logNormal).
  4. Understand the V1beta1Suggestion resource structure

    master

    The V1beta1Suggestion object represents a single suggestion generated during a hyperparameter tuning experiment in Katib. It follows the standard Kubernetes resource pattern, consisting of api_version, kind, metadata, a spec defining the suggestion's parameters, and a status indicating its current state.

    Key components include:

    • metadata: Standard Kubernetes object metadata (e.g., name, namespace, labels).
    • spec: A V1beta1SuggestionSpec object containing the actual hyperparameter values suggested.
    • status: A V1beta1SuggestionStatus object providing information about the suggestion's lifecycle.
  5. Understand the V1beta1OptimalTrial model

    master

    The V1beta1OptimalTrial model represents the metrics and hyperparameter assignments of the best trial found during a Katib experiment. It is used to identify which specific configuration yielded the optimal result.

    Key components include:

    • best_trial_name: The name of the trial that achieved the best result.
    • observation: An object of type V1beta1Observation containing the metrics observed in the best trial.
    • parameter_assignments: A list of V1beta1ParameterAssignment objects containing the key-value pairs for the hyperparameters used in the best trial.
  6. How LLM Fine-Tuning Hyperparameter Optimization works

    master

    The KEP-2339 API automates hyperparameter optimization (HPO) for Large Language Models (LLMs) by integrating with the Training Python SDK. The workflow follows these core principles:

    1. Model and Dataset Management: It uses the storage_initializer from the Training Python SDK to download pretrained models and datasets (from sources like HuggingFace or S3) into a shared PersistentVolumeClaim (PVC). This prevents redundant downloads across different trials.
    2. Hyperparameter Configuration: Users define tunable hyperparameters within trainer_parameters.training_parameters and trainer_parameters.lora_config. The API identifies these tunable parameters and injects them as args into the worker container specification.
    3. Orchestration: The API creates a Katib Experiment that defines the search space and objective. This experiment generates Trials, where each trial is implemented as a Kubernetes PyTorchJob. The trialTemplate within the experiment specifies the container configurations for master and worker nodes to enable parallel execution.
    4. Feedback Loop: Trial results are fed back to the Experiment, which evaluates them to find the optimal hyperparameter configuration.
  7. Understand the Best Genotype representation

    master

    The Best Genotype represents the optimal cell structure for each neural network layer generated by the DARTS algorithm. It is structured into normal cells, reduce cells, and their respective concatenation ranges.

    • normal: Cells located in the majority of the neural network layers.
    • reduce: Cells located at the 1/3 and 2/3 marks of the total layers, representing reduction cells where operations adjacent to input nodes have a stride of two.
    • normal_concat / reduce_concat: Define the range of intermediate nodes to be concatenated.

    Node Structure: Each element in the normal or reduce arrays represents a node with two edges. The format is (operation, connection_index).

    • connection_index 0 refers to the $C_{k-2}$ node.
    • connection_index 1 refers to the $C_{k-1}$ node.

    Example: [('max_pooling_3x3',0),('max_pooling_3x3',1)] means the $C_{k-2}$ node connects to the first node via max_pooling_3x3, and the $C_{k-1}$ node also connects to the first node via max_pooling_3x3.

    Genotype(
      normal=[
          [('max_pooling_3x3',0),('max_pooling_3x3',1)],
          [('max_pooling_3x3',0),('max_pooling_3x3',1)],
          [('max_pooling_3x3',0),('dilated_convolution_3x3',3)],
          [('max_pooling_3x3',0),('max_pooling_3x3',1)]
        ],
        normal_concat=range(2,6),
        reduce=[
          [('dilated_convolution_5x5',1),('separable_convolution_3x3',0)],
          [('max_pooling_3x3',2),('dilated_convolution_5x5',1)],
          [('dilated_convolution_5x5',3),('dilated_convolution_5x5',2)],
          [('dilated_convolution_5x5',3),('dilated_convolution_5x5',4)]
        ],
        reduce_concat=range(2,6)
    )