Component Specification

Definition of a Kubeflow Pipelines component

This specification describes the container component data model for KubeflowPipelines. The data model is serialized to a file in YAML format for sharing.

Below are the main parts of the component definition:

  • Metadata: Name, description, and other metadata.
  • Interface (inputs and outputs): Name, type, default value.
  • Implementation: How to run the component, given the input arguments.

Example of a component specification

A component specification takes the form of a YAML file, component.yaml. Belowis an example:

  1. name: xgboost4j - Train classifier
  2. description: Trains a boosted tree ensemble classifier using xgboost4j
  3. inputs:
  4. - {name: Training data URI}
  5. - {name: Rounds, type: Integer, default: '30', help: Number of training rounds}
  6. outputs:
  7. - {name: Trained model, type: XGBoost model, help: Trained XGBoost model}
  8. implementation:
  9. container:
  10. image: gcr.io/ml-pipeline/xgboost-classifier-train@sha256:b3a64d57
  11. command: [
  12. /ml/train.py,
  13. --train-uri, {inputValue: Training data URI},
  14. --rounds, {inputValue: Rounds},
  15. --out-model, {outputPath: Trained model},
  16. ]

See some examples of real-worldcomponent specifications.

Detailed specification (ComponentSpec)

This section describes theComponentSpec.

Metadata

  • name: Human-readable name of the component.
  • description: Description of the component.
  • metadata: Standard object’s metadata:

    • annotations: An unstructured key value mapstored with a resource. External tools can set this property to store andretrieve arbitrary metadata. Annotations are not queryable and should bepreserved when modifying objects. See more information in theKubernetes user guide.

    • labels: A map of string keys and values that can be used toorganize and categorize (scope and select) objects. May match selectorsof replication controllers and services. See more information in theKubernetes user guide.

Interface

  • inputs and outputs:Specifies the list of inputs/outputs and their properties. Each input oroutput has the following properties:

    • name: Human-readable name of the input/output. Name must beunique inside the inputs or outputs section, but an output may have thesame name as an input.
    • description: Human-readable description of the input/output.
    • default: Specifies the default value for an input. Onlyvalid for inputs.
    • type: Specifies the type of input/output. The types are usedas hints for pipeline authors and can be used by the pipeline system/UIto validate arguments and connections between components. Basic typesare String, Integer, Float, and Bool. See the full listof typesdefined by the Kubeflow Pipelines SDK.

Implementation

  • implementation: Specifies how to execute the component instance.There are two implementation types, container and graph. (The latter isnot in scope for this document.) In future we may introduce moreimplementation types like daemon or K8sResource.

    • container:Describes the Docker container that implements the component. A portablesubset of the KubernetesContainer v1 spec.

      • image: Name of the Docker image.
      • command: Entrypoint array. The Docker image’sENTRYPOINT is used if this is not provided. Each item is either astring or a placeholder. The most common placeholders are{inputValue: Input name} and {outputPath: Output name}.
      • args: Arguments to the entrypoint. The Dockerimage’s CMD is used if this is not provided. Each item is either astring or a placeholder. The most common placeholders are{inputValue: Input name} and {outputPath: Output name}.
      • env: Map of environment variables to set in the container.
      • fileOutputs: Legacy property that is only needed incases where the container always stores the output data in somehard-coded non-configurable local location. This property specifiesa map between some outputs and local file paths where the programwrites the output data files. Only needed for components that havehard-coded output paths. Such containers need to be fixed bymodifying the program or adding a wrapper script that copies theoutput to a configurable location. Otherwise the component may beincompatible with future storage systems.

You can set all other Kubernetes container properties when youuse the component inside a pipeline.

Using placeholders for command-line arguments

Consuming input by value (parameter)

The placeholder is replaced by the value of the input argument:

  • In component.yaml:
  1. command: [program.py, --rounds, {inputValue: Rounds}]
  • In the pipeline code:
  1. task1 = component1(rounds=150)
  • Resulting command-line code (showing the value of the input argument thathas replaced the placeholder):
  1. program.py --rounds 150

Outputs

Output paths are filled in by the pipeline system. The outputPath placeholderis replaced by a path. (The path can point to a mounted output volume, forexample.) The parent directories of the path may or may not not exist. Yourprogram must handle both cases without error.

  • In component.yaml:
  1. command: [program.py, --out-model, {outputPath: trained_model}]
  • In the pipeline code:
  1. task1 = component1()
  • Resulting command-line code (the placeholder is replaced by thegenerated path):
  1. program.py --out-model /outputs/trained_model/data