Skip to content

Commit cfab8a4

Browse files
authored
Fix: Vertex ML pipeline test failures (#7727)
* Update wheel build to include data files for Vertex tests * Fix Keras Tuner compatibility issue with the example Keras model * Update the taxi template model to avoid using deprecated Keras APIs * Restore exit handlers that were removed with KFP v1 support
1 parent e3fe5b1 commit cfab8a4

File tree

8 files changed

+29
-27
lines changed

8 files changed

+29
-27
lines changed

package_build/initialize.sh

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ do
2727
ln -sf $BASEDIR/setup.py $BASEDIR/package_build/$CONFIG_NAME/
2828
ln -sf $BASEDIR/dist $BASEDIR/package_build/$CONFIG_NAME/
2929
ln -sf $BASEDIR/tfx $BASEDIR/package_build/$CONFIG_NAME/
30+
ln -sf $BASEDIR/MANIFEST.in $BASEDIR/package_build/$CONFIG_NAME/
3031
ln -sf $BASEDIR/README*.md $BASEDIR/package_build/$CONFIG_NAME/
3132
ln -sf $BASEDIR/LICENSE $BASEDIR/package_build/$CONFIG_NAME/
3233

tfx/examples/chicago_taxi_pipeline/taxi_utils.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,6 @@ def _build_keras_model(
246246
output = tf.keras.layers.Dense(1, activation='sigmoid')(
247247
tf.keras.layers.concatenate([deep, wide])
248248
)
249-
output = tf.squeeze(output, -1)
250249

251250
model = tf.keras.Model(input_layers, output)
252251
model.compile(
@@ -371,4 +370,4 @@ def run_fn(fn_args: fn_args_utils.FnArgs):
371370
model, tf_transform_output
372371
),
373372
}
374-
model.save(fn_args.serving_model_dir, save_format='tf', signatures=signatures)
373+
tf.saved_model.save(model, fn_args.serving_model_dir, signatures=signatures)

tfx/experimental/templates/taxi/models/keras_model/model.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -215,4 +215,4 @@ def run_fn(fn_args):
215215
'transform_features':
216216
_get_transform_features_signature(model, tf_transform_output),
217217
}
218-
model.save(fn_args.serving_model_dir, save_format='tf', signatures=signatures)
218+
tf.saved_model.save(model, fn_args.serving_model_dir, signatures=signatures)

tfx/orchestration/kubeflow/v2/test_utils.py

+20-17
Original file line numberDiff line numberDiff line change
@@ -234,25 +234,28 @@ def create_pipeline_components(
234234
model_blessing=tfx.dsl.Channel(
235235
type=tfx.types.standard_artifacts.ModelBlessing)).with_id(
236236
'Resolver.latest_blessed_model_resolver')
237-
# Set the TFMA config for Model Evaluation and Validation.
237+
# Uses TFMA to compute a evaluation statistics over features of a model and
238+
# perform quality validation of a candidate model (compared to a baseline).
238239
eval_config = tfma.EvalConfig(
239-
model_specs=[tfma.ModelSpec(signature_name='eval')],
240-
metrics_specs=[
241-
tfma.MetricsSpec(
242-
metrics=[tfma.MetricConfig(class_name='ExampleCount')],
243-
thresholds={
244-
'binary_accuracy':
245-
tfma.MetricThreshold(
246-
value_threshold=tfma.GenericValueThreshold(
247-
lower_bound={'value': 0.5}),
248-
change_threshold=tfma.GenericChangeThreshold(
249-
direction=tfma.MetricDirection.HIGHER_IS_BETTER,
250-
absolute={'value': -1e-10}))
251-
})
240+
model_specs=[
241+
tfma.ModelSpec(
242+
signature_name='serving_default', label_key='tips_xf',
243+
preprocessing_function_names=['transform_features'])
252244
],
253-
slicing_specs=[
254-
tfma.SlicingSpec(),
255-
tfma.SlicingSpec(feature_keys=['trip_start_hour'])
245+
slicing_specs=[tfma.SlicingSpec()],
246+
metrics_specs=[
247+
tfma.MetricsSpec(metrics=[
248+
tfma.MetricConfig(
249+
class_name='BinaryAccuracy',
250+
threshold=tfma.MetricThreshold(
251+
value_threshold=tfma.GenericValueThreshold(
252+
lower_bound={'value': 0.6}),
253+
# Change threshold will be ignored if there is no
254+
# baseline model resolved from MLMD (first run).
255+
change_threshold=tfma.GenericChangeThreshold(
256+
direction=tfma.MetricDirection.HIGHER_IS_BETTER,
257+
absolute={'value': -1e-10})))
258+
])
256259
])
257260
evaluator = tfx.components.Evaluator(
258261
examples=example_gen.outputs['examples'],

tfx/orchestration/kubeflow/v2/testdata/expected_full_taxi_pipeline_job.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,7 @@
706706
"parameters": {
707707
"eval_config": {
708708
"runtimeValue": {
709-
"constant": "{\n \"metrics_specs\": [\n {\n \"metrics\": [\n {\n \"class_name\": \"ExampleCount\"\n }\n ],\n \"thresholds\": {\n \"binary_accuracy\": {\n \"change_threshold\": {\n \"absolute\": -1e-10,\n \"direction\": \"HIGHER_IS_BETTER\"\n },\n \"value_threshold\": {\n \"lower_bound\": 0.5\n }\n }\n }\n }\n ],\n \"model_specs\": [\n {\n \"signature_name\": \"eval\"\n }\n ],\n \"slicing_specs\": [\n {},\n {\n \"feature_keys\": [\n \"trip_start_hour\"\n ]\n }\n ]\n}"
709+
"constant": "{\n \"metrics_specs\": [\n {\n \"metrics\": [\n {\n \"class_name\": \"BinaryAccuracy\",\n \"threshold\": {\n \"change_threshold\": {\n \"absolute\": -1e-10,\n \"direction\": \"HIGHER_IS_BETTER\"\n },\n \"value_threshold\": {\n \"lower_bound\": 0.6\n }\n }\n }\n ]\n }\n ],\n \"model_specs\": [\n {\n \"label_key\": \"tips_xf\",\n \"preprocessing_function_names\": [\n \"transform_features\"\n ],\n \"signature_name\": \"serving_default\"\n }\n ],\n \"slicing_specs\": [\n {}\n ]\n}"
710710
}
711711
},
712712
"example_splits": {

tfx/orchestration/kubeflow/v2/testdata/legacy/expected_full_taxi_pipeline_job.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@
698698
"eval_config": {
699699
"runtimeValue": {
700700
"constantValue": {
701-
"stringValue": "{\n \"metrics_specs\": [\n {\n \"metrics\": [\n {\n \"class_name\": \"ExampleCount\"\n }\n ],\n \"thresholds\": {\n \"binary_accuracy\": {\n \"change_threshold\": {\n \"absolute\": -1e-10,\n \"direction\": \"HIGHER_IS_BETTER\"\n },\n \"value_threshold\": {\n \"lower_bound\": 0.5\n }\n }\n }\n }\n ],\n \"model_specs\": [\n {\n \"signature_name\": \"eval\"\n }\n ],\n \"slicing_specs\": [\n {},\n {\n \"feature_keys\": [\n \"trip_start_hour\"\n ]\n }\n ]\n}"
701+
"stringValue": "{\n \"metrics_specs\": [\n {\n \"metrics\": [\n {\n \"class_name\": \"BinaryAccuracy\",\n \"threshold\": {\n \"change_threshold\": {\n \"absolute\": -1e-10,\n \"direction\": \"HIGHER_IS_BETTER\"\n },\n \"value_threshold\": {\n \"lower_bound\": 0.6\n }\n }\n }\n ]\n }\n ],\n \"model_specs\": [\n {\n \"label_key\": \"tips_xf\",\n \"preprocessing_function_names\": [\n \"transform_features\"\n ],\n \"signature_name\": \"serving_default\"\n }\n ],\n \"slicing_specs\": [\n {}\n ]\n}"
702702
}
703703
}
704704
},

tfx/tools/docker/Dockerfile

+1-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ WORKDIR ${TFX_DIR}
2727
ARG TFX_DEPENDENCY_SELECTOR
2828
ENV TFX_DEPENDENCY_SELECTOR=${TFX_DEPENDENCY_SELECTOR}
2929

30-
RUN python -m pip install --upgrade pip wheel setuptools
31-
RUN python -m pip install tomli
30+
RUN python -m pip install --upgrade pip wheel setuptools tomli
3231

3332
# TODO(b/175089240): clean up conditional checks on whether ml-pipelines-sdk is
3433
# built after TFX versions <= 0.25 are no longer eligible for cherry-picks.

tfx/v1/orchestration/experimental/__init__.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
"""TFX orchestration.experimental module."""
1515

1616
try:
17+
from tfx.orchestration.kubeflow.decorators import exit_handler # pylint: disable=g-import-not-at-top
18+
from tfx.orchestration.kubeflow.decorators import FinalStatusStr # pylint: disable=g-import-not-at-top
19+
1720
from tfx.orchestration.kubeflow.v2.kubeflow_v2_dag_runner import (
1821
KubeflowV2DagRunner,
1922
KubeflowV2DagRunnerConfig,
@@ -24,11 +27,8 @@
2427

2528
__all__ = [
2629
"FinalStatusStr",
27-
"KubeflowDagRunner",
28-
"KubeflowDagRunnerConfig",
2930
"KubeflowV2DagRunner",
3031
"KubeflowV2DagRunnerConfig",
31-
"LABEL_KFP_SDK_ENV",
3232
"exit_handler",
3333
"get_default_kubeflow_metadata_config",
3434
]

0 commit comments

Comments
 (0)