# Buggy code
def resnet_train(
    project_id,
    output,
    region="us-central1",
    model="bolts",
    version="beta1",
    tf_version="1.12",
    train_csv="gs://bolts_image_dataset/bolt_images_train.csv",
    validation_csv="gs://bolts_image_dataset/bolt_images_validate.csv",
    labels="gs://bolts_image_dataset/labels.txt",
    depth=50,
    train_batch_size=1024,
    eval_batch_size=1024,
    steps_per_eval=250,
    train_steps=10000,
    num_train_images=218593,
    num_eval_images=54648,
    num_label_classes=10,
):
    output_dir = os.path.join(str(output), "{{workflow.name}}")
    preprocess_staging = os.path.join(output_dir, "staging")
    preprocess_output = os.path.join(output_dir, "preprocessed_output")
    train_output = os.path.join(output_dir, "model")
    preprocess = resnet_preprocess_op(
        project_id,
        preprocess_output,
        preprocess_staging,
        train_csv,
        validation_csv,
        labels,
        train_batch_size,
        eval_batch_size,
    ).apply(gcp.use_gcp_secret())
    train = resnet_train_op(
        project_id,
        preprocess_output,
        train_output,
        region,
        depth,
        train_batch_size,
        eval_batch_size,
        steps_per_eval,
        train_steps,
        num_train_images,
        num_eval_images,
        num_label_classes,
        tf_version,
    ).apply(gcp.use_gcp_secret())
    train.after(preprocess)
    export_output = os.path.join(str(train.outputs["job-dir"]), "export")
    deploy = resnet_deploy_op(
        export_output, model, version, project_id, region, tf_version
    ).apply(gcp.use_gcp_secret())


# Traceback (KeyError)
Step 20/31 : RUN  find . -maxdepth 2 -name '*.py' -type f | while read pipeline; do dsl-compile --py "$pipeline" --output "$pipeline.tar.gz"; done
---> Running in 3205bef0c5cb
Traceback (most recent call last):
File "/usr/local/bin/dsl-compile", line 10, in <module>
sys.exit(main())
File "/usr/local/lib/python3.5/site-packages/kfp/compiler/main.py", line 103, in main
compile_pyfile(args.py, args.function, args.output, not args.disable_type_check)
File "/usr/local/lib/python3.5/site-packages/kfp/compiler/main.py", line 92, in compile_pyfile
_compile_pipeline_function(function_name, output_path, type_check)
File "/usr/local/lib/python3.5/site-packages/kfp/compiler/main.py", line 72, in _compile_pipeline_function
kfp.compiler.Compiler().compile(pipeline_func, output_path, type_check)
File "/usr/local/lib/python3.5/site-packages/kfp/compiler/compiler.py", line 644, in compile
workflow = self._compile(pipeline_func)
File "/usr/local/lib/python3.5/site-packages/kfp/compiler/compiler.py", line 596, in _compile
pipeline_func(*args_list)
File "./resnet-cmle/resnet-train-pipeline.py", line 127, in resnet_train
export_output = os.path.join(str(train.outputs['job-dir']), 'export')
KeyError: 'job-dir'
The command '/bin/sh -c find . -maxdepth 2 -name '*.py' -type f | while read pipeline; do dsl-compile --py "$pipeline" --output "$pipeline.tar.gz"; done' returned a non-zero code: 1

# Fixed code
def resnet_train(
    project_id,
    output,
    region="us-central1",
    model="bolts",
    version="beta1",
    tf_version="1.12",
    train_csv="gs://bolts_image_dataset/bolt_images_train.csv",
    validation_csv="gs://bolts_image_dataset/bolt_images_validate.csv",
    labels="gs://bolts_image_dataset/labels.txt",
    depth=50,
    train_batch_size=1024,
    eval_batch_size=1024,
    steps_per_eval=250,
    train_steps=10000,
    num_train_images=218593,
    num_eval_images=54648,
    num_label_classes=10,
):
    output_dir = os.path.join(str(output), "{{workflow.name}}")
    preprocess_staging = os.path.join(output_dir, "staging")
    preprocess_output = os.path.join(output_dir, "preprocessed_output")
    train_output = os.path.join(output_dir, "model")
    preprocess = resnet_preprocess_op(
        project_id,
        preprocess_output,
        preprocess_staging,
        train_csv,
        validation_csv,
        labels,
        train_batch_size,
        eval_batch_size,
    ).apply(gcp.use_gcp_secret())
    train = resnet_train_op(
        project_id,
        preprocess_output,
        train_output,
        region,
        depth,
        train_batch_size,
        eval_batch_size,
        steps_per_eval,
        train_steps,
        num_train_images,
        num_eval_images,
        num_label_classes,
        tf_version,
    ).apply(gcp.use_gcp_secret())
    train.after(preprocess)
    export_output = os.path.join(str(train.outputs["job_dir"]), "export")
    deploy = resnet_deploy_op(
        export_output, model, version, project_id, region, tf_version
    ).apply(gcp.use_gcp_secret())