tensorflow / tfx

TFX is an end-to-end platform for deploying production ML pipelines
https://tensorflow.org/tfx
Apache License 2.0
2.12k stars 708 forks source link

ValueError: Unable to handle tensor pickup_latitude with rep dense_tensor #3188

Closed nroberts1 closed 1 year ago

nroberts1 commented 3 years ago

It appears the Evaluator component has an issue when I don't rename the transformed inputs.

I've managed to reproduce the error with the smallest of changes. If you run the colab for the Keras TFX tutorial from here - https://www.tensorflow.org/tfx/tutorials/tfx/components_keras Everything works fine all the way through to the Evaluator.

In the colab I've changed the transform_name function in the constants file to:

def transformed_name(key):
  return key

Here's a link to the edited colab - https://colab.research.google.com/drive/1KYcdmHxfY9URgAIKI1_rx4DVty5d-f5o?usp=sharing

As the transform starts with outputs = {} and then adds to this using

outputs[_transformed_name(key)] = tft...

this can't be caused by left over additional fields from the transform function inputs.

Run the edited colab and the Evaluator fails with:

INFO:absl:Request was made to ignore the baseline ModelSpec and any change thresholds. This is likely because a baseline model was not provided: updated_config=
model_specs {
  label_key: "tips"
}
slicing_specs {
}
slicing_specs {
  feature_keys: "trip_start_hour"
}
metrics_specs {
  metrics {
    class_name: "ExampleCount"
  }
  metrics {
    class_name: "BinaryAccuracy"
    threshold {
      value_threshold {
        lower_bound {
          value: 0.5
        }
      }
    }
  }
  model_names: ""
}

WARNING:tensorflow:5 out of the last 5 calls to <function recreate_function.<locals>.restored_function_body at 0x7f14a6ba00d0> triggered tf.function retracing. Tracing is expensive and the excessive number of tracings could be due to (1) creating @tf.function repeatedly in a loop, (2) passing tensors with different shapes, (3) passing Python objects instead of tensors. For (1), please define your @tf.function outside of the loop. For (2), @tf.function has experimental_relax_shapes=True option that relaxes argument shapes that can avoid unnecessary retracing. For (3), please refer to https://www.tensorflow.org/tutorials/customization/performance#python_or_tensor_args and https://www.tensorflow.org/api_docs/python/tf/function for  more details.
WARNING:absl:Large batch_size 1 failed with error Error raised when handling tensor pickup_latitude: Unable to convert ListArray [
  []
] to TensorSpec(shape=(None,), dtype=tf.float32, name=None): size mismatch. expected 1 elements but got 0. Attempting to run batch through serially. Note that this will significantly affect the performance.
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/tfx_bsl/tfxio/tensor_adapter.py in ToBatchTensors(self, record_batch, produce_eager_tensors)
    154         result[tensor_name] = handler.GetTensor(record_batch,
--> 155                                                 produce_eager_tensors)
    156       except Exception as e:

131 frames
ValueError: Unable to convert ListArray [
  []
] to TensorSpec(shape=(None,), dtype=tf.float32, name=None): size mismatch. expected 1 elements but got 0

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
ValueError: Error raised when handling tensor pickup_latitude: Unable to convert ListArray [
  []
] to TensorSpec(shape=(None,), dtype=tf.float32, name=None): size mismatch. expected 1 elements but got 0

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
ValueError: Unable to convert ListArray [
  []
] to TensorSpec(shape=(None,), dtype=tf.float32, name=None): size mismatch. expected 1 elements but got 0

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
ValueError: Error raised when handling tensor pickup_latitude: Unable to convert ListArray [
  []
] to TensorSpec(shape=(None,), dtype=tf.float32, name=None): size mismatch. expected 1 elements but got 0

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/tfx_bsl/tfxio/tensor_adapter.py in ToBatchTensors(self, record_batch, produce_eager_tensors)
    156       except Exception as e:
    157         raise ValueError("Error raised when handling tensor {}: {}"
--> 158                          .format(tensor_name, e))
    159 
    160     return result

ValueError: Error raised when handling tensor pickup_latitude: Unable to convert ListArray [
  []
] to TensorSpec(shape=(None,), dtype=tf.float32, name=None): size mismatch. expected 1 elements but got 0 [while running 'ExtractEvaluateAndWriteResults/ExtractAndEvaluate/ExtractPredictions/Predict']

When running this locally with the BeamDagRunner the error is as below, I'm guessing the underlying issie will be the same?

BeamDagRunner().run(tfx_pipeline)
  File ".../.pyenv/versions/_ml_tfx/lib/python3.7/site-packages/tfx/orchestration/beam/beam_dag_runner.py", line 327, in run
    logging.info('Node %s is scheduled.', node_id)
  File ".../.pyenv/versions/_ml_tfx/lib/python3.7/site-packages/apache_beam/pipeline.py", line 568, in __exit__
    self.result = self.run()
  File ".../.pyenv/versions/_ml_tfx/lib/python3.7/site-packages/apache_beam/pipeline.py", line 547, in run
    return self.runner.run_pipeline(self, self._options)
  File ".../.pyenv/versions/_ml_tfx/lib/python3.7/site-packages/apache_beam/runners/direct/direct_runner.py", line 119, in run_pipeline
    return runner.run_pipeline(pipeline, options)
  File ".../.pyenv/versions/_ml_tfx/lib/python3.7/site-packages/apache_beam/runners/portability/fn_api_runner/fn_runner.py", line 176, in run_pipeline
    pipeline.to_runner_api(default_environment=self._default_environment))
  File ".../.pyenv/versions/_ml_tfx/lib/python3.7/site-packages/apache_beam/runners/portability/fn_api_runner/fn_runner.py", line 186, in run_via_runner_api
    return self.run_stages(stage_context, stages)
  File ".../.pyenv/versions/_ml_tfx/lib/python3.7/site-packages/apache_beam/runners/portability/fn_api_runner/fn_runner.py", line 346, in run_stages
    bundle_context_manager,
  File ".../.pyenv/versions/_ml_tfx/lib/python3.7/site-packages/apache_beam/runners/portability/fn_api_runner/fn_runner.py", line 534, in _run_stage
    bundle_manager)
  File ".../.pyenv/versions/_ml_tfx/lib/python3.7/site-packages/apache_beam/runners/portability/fn_api_runner/fn_runner.py", line 572, in _run_bundle
    data_input, data_output, input_timers, expected_timer_output)
  File ".../.pyenv/versions/_ml_tfx/lib/python3.7/site-packages/apache_beam/runners/portability/fn_api_runner/fn_runner.py", line 852, in process_bundle
    result_future = self._worker_handler.control_conn.push(process_bundle_req)
  File ".../.pyenv/versions/_ml_tfx/lib/python3.7/site-packages/apache_beam/runners/portability/fn_api_runner/worker_handlers.py", line 353, in push
    response = self.worker.do_instruction(request)
  File ".../.pyenv/versions/_ml_tfx/lib/python3.7/site-packages/apache_beam/runners/worker/sdk_worker.py", line 484, in do_instruction
    getattr(request, request_type), request.instruction_id)
  File ".../.pyenv/versions/_ml_tfx/lib/python3.7/site-packages/apache_beam/runners/worker/sdk_worker.py", line 519, in process_bundle
    bundle_processor.process_bundle(instruction_id))
  File ".../.pyenv/versions/_ml_tfx/lib/python3.7/site-packages/apache_beam/runners/worker/bundle_processor.py", line 985, in process_bundle
    element.data)
  File ".../.pyenv/versions/_ml_tfx/lib/python3.7/site-packages/apache_beam/runners/worker/bundle_processor.py", line 221, in process_encoded
    self.output(decoded_value)
  File "apache_beam/runners/worker/operations.py", line 354, in apache_beam.runners.worker.operations.Operation.output
  File "apache_beam/runners/worker/operations.py", line 356, in apache_beam.runners.worker.operations.Operation.output
  File "apache_beam/runners/worker/operations.py", line 218, in apache_beam.runners.worker.operations.SingletonConsumerSet.receive
  File "apache_beam/runners/worker/operations.py", line 703, in apache_beam.runners.worker.operations.DoOperation.process
  File "apache_beam/runners/worker/operations.py", line 704, in apache_beam.runners.worker.operations.DoOperation.process
  File "apache_beam/runners/common.py", line 1215, in apache_beam.runners.common.DoFnRunner.process
  File "apache_beam/runners/common.py", line 1279, in apache_beam.runners.common.DoFnRunner._reraise_augmented
  File "apache_beam/runners/common.py", line 1213, in apache_beam.runners.common.DoFnRunner.process
  File "apache_beam/runners/common.py", line 742, in apache_beam.runners.common.PerWindowInvoker.invoke_process
  File "apache_beam/runners/common.py", line 867, in apache_beam.runners.common.PerWindowInvoker._invoke_process_per_window
  File ".../.pyenv/versions/_ml_tfx/lib/python3.7/site-packages/tfx/orchestration/beam/beam_dag_runner.py", line 88, in process
    self._run_component()
  File ".../.pyenv/versions/_ml_tfx/lib/python3.7/site-packages/tfx/orchestration/beam/beam_dag_runner.py", line 103, in _run_component
    custom_driver_spec=self._custom_driver_spec).launch()
  File ".../.pyenv/versions/_ml_tfx/lib/python3.7/site-packages/tfx/orchestration/portable/launcher.py", line 378, in launch
    executor_output = self._run_executor(execution_info)
  File ".../.pyenv/versions/_ml_tfx/lib/python3.7/site-packages/tfx/orchestration/portable/launcher.py", line 285, in _run_executor
    executor_output = self._executor_operator.run_executor(execution_info)
  File ".../.pyenv/versions/_ml_tfx/lib/python3.7/site-packages/tfx/orchestration/portable/python_executor_operator.py", line 111, in run_executor
    execution_info.exec_properties)
  File ".../.pyenv/versions/_ml_tfx/lib/python3.7/site-packages/tfx/components/evaluator/executor.py", line 259, in Do
    tensor_adapter_config=tensor_adapter_config))
  File ".../.pyenv/versions/_ml_tfx/lib/python3.7/site-packages/apache_beam/pipeline.py", line 568, in __exit__
    self.result = self.run()
  File ".../.pyenv/versions/_ml_tfx/lib/python3.7/site-packages/apache_beam/pipeline.py", line 547, in run
    return self.runner.run_pipeline(self, self._options)
  File ".../.pyenv/versions/_ml_tfx/lib/python3.7/site-packages/apache_beam/runners/portability/fn_api_runner/fn_runner.py", line 176, in run_pipeline
    pipeline.to_runner_api(default_environment=self._default_environment))
  File ".../.pyenv/versions/_ml_tfx/lib/python3.7/site-packages/apache_beam/runners/portability/fn_api_runner/fn_runner.py", line 186, in run_via_runner_api
    return self.run_stages(stage_context, stages)
  File ".../.pyenv/versions/_ml_tfx/lib/python3.7/site-packages/apache_beam/runners/portability/fn_api_runner/fn_runner.py", line 346, in run_stages
    bundle_context_manager,
  File ".../.pyenv/versions/_ml_tfx/lib/python3.7/site-packages/apache_beam/runners/portability/fn_api_runner/fn_runner.py", line 534, in _run_stage
    bundle_manager)
  File ".../.pyenv/versions/_ml_tfx/lib/python3.7/site-packages/apache_beam/runners/portability/fn_api_runner/fn_runner.py", line 572, in _run_bundle
    data_input, data_output, input_timers, expected_timer_output)
  File ".../.pyenv/versions/_ml_tfx/lib/python3.7/site-packages/apache_beam/runners/portability/fn_api_runner/fn_runner.py", line 852, in process_bundle
    result_future = self._worker_handler.control_conn.push(process_bundle_req)
  File ".../.pyenv/versions/_ml_tfx/lib/python3.7/site-packages/apache_beam/runners/portability/fn_api_runner/worker_handlers.py", line 353, in push
    response = self.worker.do_instruction(request)
  File ".../.pyenv/versions/_ml_tfx/lib/python3.7/site-packages/apache_beam/runners/worker/sdk_worker.py", line 484, in do_instruction
    getattr(request, request_type), request.instruction_id)
  File ".../.pyenv/versions/_ml_tfx/lib/python3.7/site-packages/apache_beam/runners/worker/sdk_worker.py", line 519, in process_bundle
    bundle_processor.process_bundle(instruction_id))
  File ".../.pyenv/versions/_ml_tfx/lib/python3.7/site-packages/apache_beam/runners/worker/bundle_processor.py", line 985, in process_bundle
    element.data)
  File ".../.pyenv/versions/_ml_tfx/lib/python3.7/site-packages/apache_beam/runners/worker/bundle_processor.py", line 221, in process_encoded
    self.output(decoded_value)
  File "apache_beam/runners/worker/operations.py", line 354, in apache_beam.runners.worker.operations.Operation.output
  File "apache_beam/runners/worker/operations.py", line 356, in apache_beam.runners.worker.operations.Operation.output
  File "apache_beam/runners/worker/operations.py", line 218, in apache_beam.runners.worker.operations.SingletonConsumerSet.receive
  File "apache_beam/runners/worker/operations.py", line 809, in apache_beam.runners.worker.operations.SdfProcessSizedElements.process
  File "apache_beam/runners/worker/operations.py", line 818, in apache_beam.runners.worker.operations.SdfProcessSizedElements.process
  File "apache_beam/runners/common.py", line 1221, in apache_beam.runners.common.DoFnRunner.process_with_sized_restriction
  File "apache_beam/runners/common.py", line 722, in apache_beam.runners.common.PerWindowInvoker.invoke_process
  File "apache_beam/runners/common.py", line 860, in apache_beam.runners.common.PerWindowInvoker._invoke_process_per_window
  File "apache_beam/runners/common.py", line 1374, in apache_beam.runners.common._OutputProcessor.process_outputs
  File "apache_beam/runners/worker/operations.py", line 218, in apache_beam.runners.worker.operations.SingletonConsumerSet.receive
  File "apache_beam/runners/worker/operations.py", line 1069, in apache_beam.runners.worker.operations.FlattenOperation.process
  File "apache_beam/runners/worker/operations.py", line 1072, in apache_beam.runners.worker.operations.FlattenOperation.process
  File "apache_beam/runners/worker/operations.py", line 356, in apache_beam.runners.worker.operations.Operation.output
  File "apache_beam/runners/worker/operations.py", line 218, in apache_beam.runners.worker.operations.SingletonConsumerSet.receive
  File "apache_beam/runners/worker/operations.py", line 703, in apache_beam.runners.worker.operations.DoOperation.process
  File "apache_beam/runners/worker/operations.py", line 704, in apache_beam.runners.worker.operations.DoOperation.process
  File "apache_beam/runners/common.py", line 1215, in apache_beam.runners.common.DoFnRunner.process
  File "apache_beam/runners/common.py", line 1279, in apache_beam.runners.common.DoFnRunner._reraise_augmented
  File "apache_beam/runners/common.py", line 1213, in apache_beam.runners.common.DoFnRunner.process
  File "apache_beam/runners/common.py", line 569, in apache_beam.runners.common.SimpleInvoker.invoke_process
  File "apache_beam/runners/common.py", line 1374, in apache_beam.runners.common._OutputProcessor.process_outputs
  File "apache_beam/runners/worker/operations.py", line 218, in apache_beam.runners.worker.operations.SingletonConsumerSet.receive
  File "apache_beam/runners/worker/operations.py", line 703, in apache_beam.runners.worker.operations.DoOperation.process
  File "apache_beam/runners/worker/operations.py", line 704, in apache_beam.runners.worker.operations.DoOperation.process
  File "apache_beam/runners/common.py", line 1215, in apache_beam.runners.common.DoFnRunner.process
  File "apache_beam/runners/common.py", line 1279, in apache_beam.runners.common.DoFnRunner._reraise_augmented
  File "apache_beam/runners/common.py", line 1213, in apache_beam.runners.common.DoFnRunner.process
  File "apache_beam/runners/common.py", line 569, in apache_beam.runners.common.SimpleInvoker.invoke_process
  File "apache_beam/runners/common.py", line 1374, in apache_beam.runners.common._OutputProcessor.process_outputs
  File "apache_beam/runners/worker/operations.py", line 218, in apache_beam.runners.worker.operations.SingletonConsumerSet.receive
  File "apache_beam/runners/worker/operations.py", line 703, in apache_beam.runners.worker.operations.DoOperation.process
  File "apache_beam/runners/worker/operations.py", line 704, in apache_beam.runners.worker.operations.DoOperation.process
  File "apache_beam/runners/common.py", line 1215, in apache_beam.runners.common.DoFnRunner.process
  File "apache_beam/runners/common.py", line 1279, in apache_beam.runners.common.DoFnRunner._reraise_augmented
  File "apache_beam/runners/common.py", line 1213, in apache_beam.runners.common.DoFnRunner.process
  File "apache_beam/runners/common.py", line 569, in apache_beam.runners.common.SimpleInvoker.invoke_process
  File "apache_beam/runners/common.py", line 1374, in apache_beam.runners.common._OutputProcessor.process_outputs
  File "apache_beam/runners/worker/operations.py", line 218, in apache_beam.runners.worker.operations.SingletonConsumerSet.receive
  File "apache_beam/runners/worker/operations.py", line 703, in apache_beam.runners.worker.operations.DoOperation.process
  File "apache_beam/runners/worker/operations.py", line 704, in apache_beam.runners.worker.operations.DoOperation.process
  File "apache_beam/runners/common.py", line 1215, in apache_beam.runners.common.DoFnRunner.process
  File "apache_beam/runners/common.py", line 1279, in apache_beam.runners.common.DoFnRunner._reraise_augmented
  File "apache_beam/runners/common.py", line 1213, in apache_beam.runners.common.DoFnRunner.process
  File "apache_beam/runners/common.py", line 569, in apache_beam.runners.common.SimpleInvoker.invoke_process
  File "apache_beam/runners/common.py", line 1374, in apache_beam.runners.common._OutputProcessor.process_outputs
  File "apache_beam/runners/worker/operations.py", line 218, in apache_beam.runners.worker.operations.SingletonConsumerSet.receive
  File "apache_beam/runners/worker/operations.py", line 1069, in apache_beam.runners.worker.operations.FlattenOperation.process
  File "apache_beam/runners/worker/operations.py", line 1072, in apache_beam.runners.worker.operations.FlattenOperation.process
  File "apache_beam/runners/worker/operations.py", line 356, in apache_beam.runners.worker.operations.Operation.output
  File "apache_beam/runners/worker/operations.py", line 218, in apache_beam.runners.worker.operations.SingletonConsumerSet.receive
  File "apache_beam/runners/worker/operations.py", line 703, in apache_beam.runners.worker.operations.DoOperation.process
  File "apache_beam/runners/worker/operations.py", line 704, in apache_beam.runners.worker.operations.DoOperation.process
  File "apache_beam/runners/common.py", line 1215, in apache_beam.runners.common.DoFnRunner.process
  File "apache_beam/runners/common.py", line 1279, in apache_beam.runners.common.DoFnRunner._reraise_augmented
  File "apache_beam/runners/common.py", line 1213, in apache_beam.runners.common.DoFnRunner.process
  File "apache_beam/runners/common.py", line 569, in apache_beam.runners.common.SimpleInvoker.invoke_process
  File "apache_beam/runners/common.py", line 1374, in apache_beam.runners.common._OutputProcessor.process_outputs
  File "apache_beam/runners/worker/operations.py", line 218, in apache_beam.runners.worker.operations.SingletonConsumerSet.receive
  File "apache_beam/runners/worker/operations.py", line 703, in apache_beam.runners.worker.operations.DoOperation.process
  File "apache_beam/runners/worker/operations.py", line 704, in apache_beam.runners.worker.operations.DoOperation.process
  File "apache_beam/runners/common.py", line 1215, in apache_beam.runners.common.DoFnRunner.process
  File "apache_beam/runners/common.py", line 1279, in apache_beam.runners.common.DoFnRunner._reraise_augmented
  File "apache_beam/runners/common.py", line 1213, in apache_beam.runners.common.DoFnRunner.process
  File "apache_beam/runners/common.py", line 569, in apache_beam.runners.common.SimpleInvoker.invoke_process
  File "apache_beam/runners/common.py", line 1374, in apache_beam.runners.common._OutputProcessor.process_outputs
  File "apache_beam/runners/worker/operations.py", line 218, in apache_beam.runners.worker.operations.SingletonConsumerSet.receive
  File "apache_beam/runners/worker/operations.py", line 703, in apache_beam.runners.worker.operations.DoOperation.process
  File "apache_beam/runners/worker/operations.py", line 704, in apache_beam.runners.worker.operations.DoOperation.process
  File "apache_beam/runners/common.py", line 1215, in apache_beam.runners.common.DoFnRunner.process
  File "apache_beam/runners/common.py", line 1279, in apache_beam.runners.common.DoFnRunner._reraise_augmented
  File "apache_beam/runners/common.py", line 1213, in apache_beam.runners.common.DoFnRunner.process
  File "apache_beam/runners/common.py", line 569, in apache_beam.runners.common.SimpleInvoker.invoke_process
  File "apache_beam/runners/common.py", line 1374, in apache_beam.runners.common._OutputProcessor.process_outputs
  File "apache_beam/runners/worker/operations.py", line 218, in apache_beam.runners.worker.operations.SingletonConsumerSet.receive
  File "apache_beam/runners/worker/operations.py", line 703, in apache_beam.runners.worker.operations.DoOperation.process
  File "apache_beam/runners/worker/operations.py", line 704, in apache_beam.runners.worker.operations.DoOperation.process
  File "apache_beam/runners/common.py", line 1215, in apache_beam.runners.common.DoFnRunner.process
  File "apache_beam/runners/common.py", line 1279, in apache_beam.runners.common.DoFnRunner._reraise_augmented
  File "apache_beam/runners/common.py", line 1213, in apache_beam.runners.common.DoFnRunner.process
  File "apache_beam/runners/common.py", line 569, in apache_beam.runners.common.SimpleInvoker.invoke_process
  File "apache_beam/runners/common.py", line 1374, in apache_beam.runners.common._OutputProcessor.process_outputs
  File "apache_beam/runners/worker/operations.py", line 218, in apache_beam.runners.worker.operations.SingletonConsumerSet.receive
  File "apache_beam/runners/worker/operations.py", line 703, in apache_beam.runners.worker.operations.DoOperation.process
  File "apache_beam/runners/worker/operations.py", line 704, in apache_beam.runners.worker.operations.DoOperation.process
  File "apache_beam/runners/common.py", line 1215, in apache_beam.runners.common.DoFnRunner.process
  File "apache_beam/runners/common.py", line 1279, in apache_beam.runners.common.DoFnRunner._reraise_augmented
  File "apache_beam/runners/common.py", line 1213, in apache_beam.runners.common.DoFnRunner.process
  File "apache_beam/runners/common.py", line 569, in apache_beam.runners.common.SimpleInvoker.invoke_process
  File "apache_beam/runners/common.py", line 1374, in apache_beam.runners.common._OutputProcessor.process_outputs
  File "apache_beam/runners/worker/operations.py", line 218, in apache_beam.runners.worker.operations.SingletonConsumerSet.receive
  File "apache_beam/runners/worker/operations.py", line 703, in apache_beam.runners.worker.operations.DoOperation.process
  File "apache_beam/runners/worker/operations.py", line 704, in apache_beam.runners.worker.operations.DoOperation.process
  File "apache_beam/runners/common.py", line 1215, in apache_beam.runners.common.DoFnRunner.process
  File "apache_beam/runners/common.py", line 1294, in apache_beam.runners.common.DoFnRunner._reraise_augmented
  File ".../.pyenv/versions/_ml_tfx/lib/python3.7/site-packages/future/utils/__init__.py", line 446, in raise_with_traceback
    raise exc.with_traceback(traceback)
  File "apache_beam/runners/common.py", line 1213, in apache_beam.runners.common.DoFnRunner.process
  File "apache_beam/runners/common.py", line 570, in apache_beam.runners.common.SimpleInvoker.invoke_process
  File ".../.pyenv/versions/_ml_tfx/lib/python3.7/site-packages/tensorflow_model_analysis/model_util.py", line 682, in process
    result.extend(self._batch_reducible_process(unbatched_element))
  File ".../.pyenv/versions/_ml_tfx/lib/python3.7/site-packages/tensorflow_model_analysis/model_util.py", line 811, in _batch_reducible_process
    adapter = tensor_adapter.TensorAdapter(tensor_adapter_config)
  File ".../.pyenv/versions/_ml_tfx/lib/python3.7/site-packages/tfx_bsl/tfxio/tensor_adapter.py", line 89, in __init__
    config.tensor_representations, config.arrow_schema)
  File ".../.pyenv/versions/_ml_tfx/lib/python3.7/site-packages/tfx_bsl/tfxio/tensor_adapter.py", line 619, in _BuildTypeHandlers
    arrow_schema))
ValueError: Unable to handle tensor pickup_latitude with rep dense_tensor {
  column_name: "pickup_latitude"
}
 against schema: big_tipper: large_list<item: float>
  child 0, item: float
company: large_list<item: large_binary>
  child 0, item: large_binary
dropoff_census_tract: null
dropoff_latitude: null
dropoff_longitude: null
fare: large_list<item: float>
  child 0, item: float
payment_type: large_list<item: large_binary>
  child 0, item: large_binary
pickup_community_area: null
pickup_latitude: null
pickup_longitude: null
tips: large_list<item: float>
  child 0, item: float
trip_miles: large_list<item: float>
  child 0, item: float
trip_seconds: large_list<item: int64>
  child 0, item: int64
trip_start_day: large_list<item: int64>
  child 0, item: int64
trip_start_hour: large_list<item: int64>
  child 0, item: int64
trip_start_month: large_list<item: int64>
  child 0, item: int64
trip_start_timestamp: large_list<item: int64>
  child 0, item: int64
__raw_record__: large_list<item: large_binary>
  child 0, item: large_binary [while running 'ExtractEvaluateAndWriteResults/ExtractAndEvaluate/ExtractPredictions/Predict']
arghyaganguly commented 3 years ago

@nroberts1 , transformed_name is a small helper function that appends _xf to each feature name. This is used in the transform module to differentiate transformed features from raw features. This is not a bug but a practice that is followed in tfx. More information can be found in :-

1)Building Machine Learning Pipelines by Hannes Hapke, Catherine Nelson

nroberts1 commented 3 years ago

On the tfx tutorial page under Tutorials - Transform - Process data (advanced), the tranform_fn does not use this rename approach, suggesting it should not be necessary:

def preprocessing_fn(inputs):
  """Preprocess input columns into transformed columns."""
  # Since we are modifying some features and leaving others unchanged, we
  # start by setting `outputs` to a copy of `inputs.
  outputs = inputs.copy()

As TFMA outside of TFX works fine using the code below then the encompassing framework (TFX) should not alter the requirements of this / the transform process. I do think this should at the least be considered as an improvement if not a bug.

eval_shared_model = tfma.default_eval_shared_model(
            eval_saved_model_path=model_path,
            tags=[tf.saved_model.SERVING]
        )

        train_output_path = os.path.join(self.pipe_config.get_pipeline_path(), 'Evaluator',
                                         'train')
        os.makedirs(train_output_path)
        train_data_path = os.path.join(self.pipe_config.get_pipeline_path(),
                                       'ImportExampleGen', 'examples', item_number, 'train', '*')

        eval_output_path = os.path.join(self.pipe_config.get_pipeline_path(), 'Evaluator', 'eval')
        os.makedirs(eval_output_path)
        eval_data_path = os.path.join(self.pipe_config.get_pipeline_path(),
                                      'ImportExampleGen', 'examples', item_number, 'eval', '*')

        test_output_path = os.path.join(self.pipe_config.get_pipeline_path(), 'Evaluator', 'test')
        os.makedirs(test_output_path)
        test_data_path = os.path.join(self.pipe_config.get_pipeline_path(),
                                      'ImportExampleGen', 'examples', item_number, 'test', '*')

        train_result = tfma.run_model_analysis(
            eval_shared_model=eval_shared_model,
            eval_config=eval_config,
            data_location=train_data_path,
            output_path=train_output_path,
            file_format='tfrecords',
            slice_spec=[tfma.slicer.SingleSliceSpec()]
        )
        eval_result = tfma.run_model_analysis(
            eval_shared_model=eval_shared_model,
            eval_config=eval_config,
            data_location=eval_data_path,
            output_path=eval_output_path,
            file_format='tfrecords',
            slice_spec=[tfma.slicer.SingleSliceSpec()]
        )
        test_result = tfma.run_model_analysis(
            eval_shared_model=eval_shared_model,
            eval_config=eval_config,
            data_location=test_data_path,
            output_path=test_output_path,
            file_format='tfrecords',
            slice_spec=[tfma.slicer.SingleSliceSpec()]
        )
nroberts1 commented 3 years ago

Using the TFX material led me to this problem and I expect others will follow. The error message does not say 'rename the inputs during the transform process' and I lost many development hours narrowing down the issue before reporting it. It will be common for people to disregard TFX as an option if faced with this and similar issues. This paints TFX as a product in poor light if this is the level of acceptable functionality.

mdreves commented 3 years ago

You should be allowed to rename the inputs. I haven't looked closely, but I wonder if updating to use TFMA with the newly added TFT support will work. Just change your config so that you have the following:

  eval_config = tfma.EvalConfig(
      model_specs=[
          tfma.ModelSpec(
              signature_name='serving_default', 
              label_key='tips',
              preprocessing_function_names=['tft_layer'])
      ],
      ...
   )
arghyaganguly commented 3 years ago

@nroberts1 , please confirm whether you are satisfied with the workaround from the previous comment by @mdreves.

nroberts1 commented 3 years ago

No, this isn't a workaround from what I can tell. The issue is for names "not" to have to be renamed and even though TFMA works the need is for TFX's evaluation step to work so you can benefit from TFX's complete ML pipeline functionality.

The workaround is to rename the inputs, then it all works. The improvement would be preferably get it to work when inputs are not renamed, or failing that making the need to rename clear in the documentation and providing a clear error or warning message when they are not i.e. "input are not renamed, this can cause issues during the TFX evalution step"

jiyongjung0 commented 2 years ago

Sorry for the late follow-up. I think that it makes sense and we need to add more documentation and early-warnings about the shape of input / transformed-inputs.

@mdreves Do you have any ideas on this?

mdreves commented 2 years ago

TFMA is moving away from supporting using the keras model directly for inference. Instead all the inputs need to be defined via signatures. The transformations themselves also need to be defined using signatures. There are examples for how to export a model with proper signatures in the penguin example:

https://github.com/tensorflow/tfx/blob/78cfa243d9da756ddd2597fed27eaf15578e4f98/tfx/examples/penguin/penguin_utils_base.py#L92

With this setup, the TFMA code would look something like the following:

 eval_config = tfma.EvalConfig(
      model_specs=[
          tfma.ModelSpec(
              signature_name='serving_default', 
              label_key='<your label>',
              preprocessing_function_names=['transform_features'])
      ],
      ...
   )

When set up with this configuration there shouldn't be any issues with what names you use for the inputs.

github-actions[bot] commented 1 year ago

This issue has been marked stale because it has no recent activity since 7 days. It will be closed if no further activity occurs. Thank you.

github-actions[bot] commented 1 year ago

This issue was closed due to lack of activity after being marked stale for past 7 days.

google-ml-butler[bot] commented 1 year ago

Are you satisfied with the resolution of your issue? Yes No