Compile a Pipeline

Define and compile a basic pipeline using the KFP SDK.

Overview

To submit a pipeline for execution, you must compile it to YAML with the KFP SDK compiler.

In the following example, the compiler creates a file called pipeline.yaml, which contains a hermetic representation of your pipeline. The output is called an Intermediate Representation (IR) YAML, which is a serialized PipelineSpec protocol buffer message.

from kfp import compiler, dsl

@dsl.component
def comp(message: str) -> str:
    print(message)
    return message

@dsl.pipeline
def my_pipeline(message: str) -> str:
    """My ML pipeline."""
    return comp(message=message).output

compiler.Compiler().compile(my_pipeline, package_path='pipeline.yaml')

Because components are actually pipelines, you may also compile them to IR YAML:

@dsl.component
def comp(message: str) -> str:
    print(message)
    return message

compiler.Compiler().compile(comp, package_path='component.yaml')

You can view an example of IR YAML on GitHub. The contents of the file are not intended to be human-readable, however the comments at the top of the file provide a summary of the pipeline:

# PIPELINE DEFINITION
# Name: my-pipeline
# Description: My ML pipeline.
# Inputs:
#    message: str
# Outputs:
#    Output: str
...

Type checking

By default, the DSL compiler statically type checks your pipeline to ensure type consistency between components that pass data between one another. Static type checking helps identify component I/O inconsistencies without having to run the pipeline, shortening development iterations.

Specifically, the type checker checks for type equality between the type of data a component input expects and the type of the data provided. See Data Types for more information about KFP data types.

For example, for parameters, a list input may only be passed to parameters with a typing.List annotation. Similarly, a float may only be passed to parameters with a float annotation.

Input data types and annotations must also match for artifacts, with one exception: the Artifact type is compatible with all other artifact types. In this sense, the Artifact type is both the default artifact type and an artifact “any” type.

As described in the following section, you can disable type checking.

Compiler arguments

The Compiler.compile method accepts the following arguments:

NameTypeDescription
pipeline_funcfunctionRequired
Pipeline function constructed with the @dsl.pipeline or component constructed with the @dsl.component decorator.
package_pathstringRequired
Output YAML file path. For example, ~/my_pipeline.yaml or ~/my_component.yaml.
pipeline_namestringOptional
If specified, sets the name of the pipeline template in the pipelineInfo.name field in the compiled IR YAML output. Overrides the name of the pipeline or component specified by the name parameter in the @dsl.pipeline decorator.
pipeline_parametersDict[str, Any]Optional
Map of parameter names to argument values. This lets you provide default values for pipeline or component parameters. You can override these default values during pipeline submission.
type_checkboolOptional
Indicates whether static type checking is enabled during compilation.

Feedback

Was this page helpful?