I am getting a TypeCheckError when running context.run(statistics_gen). I have followed the instructions, including restarting the runtime. Please advice.
TypeCheckError: Output type hint violation at WriteStatsOutput[train]: expected <class ‘apache_beam.pvalue.PDone’>, got <class ‘str’>
Full type hint:
IOTypeHints[inputs=((<class ‘tensorflow_metadata.proto.v0.statistics_pb2.DatasetFeatureStatisticsList’>,), {}), outputs=((<class ‘apache_beam.pvalue.PDone’>,), {})]
File “”, line 677, in _load_unlocked
File “”, line 728, in exec_module
File “”, line 219, in _call_with_frames_removed
File “/usr/local/lib/python3.7/dist-packages/tensorflow_data_validation/api/stats_api.py”, line 113, in
class WriteStatisticsToBinaryFile(beam.PTransform):
File “/usr/local/lib/python3.7/dist-packages/apache_beam/typehints/decorators.py”, line 776, in annotate_input_types
*converted_positional_hints, **converted_keyword_hints)
based on:
IOTypeHints[inputs=None, outputs=((<class ‘apache_beam.pvalue.PDone’>,), {})]
File “”, line 677, in _load_unlocked
File “”, line 728, in exec_module
File “”, line 219, in _call_with_frames_removed
File “/usr/local/lib/python3.7/dist-packages/tensorflow_data_validation/api/stats_api.py”, line 113, in
class WriteStatisticsToBinaryFile(beam.PTransform):
File “/usr/local/lib/python3.7/dist-packages/apache_beam/typehints/decorators.py”, line 863, in annotate_output_types
f._type_hints = th.with_output_types(return_type_hint) # pylint: disable=protected-access
Check you might not be defining the statistics_gen above it properly, or any of its previous dependencies.
I have the same problem, also in W1 Lab 2 with TFX / Tuner + Trainer. I’ve double-checked things a few times to no avail (and have also restarted the runtime, etc.).
Hi @gent.spah,
Thanks for your reply.
I’ve tried running this lab several times, but the result is the same. I’ve double and triple checked all of the code above the context.run(). I’ll keep researching what the issues might be and would appreciate hearing from anyone else that experiences this issue. And thank you @Tapani_Honkanen for your input.
Hi @gent.spah,
This is the condition in ptransform.py
from the Apache Beam package that raises the exception:
if hint and not typehints.is_consistent_with(pvalue_.element_type, hint):
Could it be that the Beam version is not consistent with this TFX version with regard to pvalue_.element_type
hints?
Hi @Alvaro_Henriquez I am not sure where the problem might be here, when i did the course a few weeks ago it was fine for me. I thought from the original post might be something wrong with statistics_gen or previous dependencies. You got to trace the error back to where it leads or maybe a mentor of this course familiar with it could help.
Thanks @gent.spah
Yes, that’s what I’m attempting to do. I’ve been going over the Apache Beam code related to the error. There is obviously a type hinting error and what’s causing that is what I’m trying to understand. The exception indicates that a str
is being returned in the output when there should be a pvalue
. So, it makes sense to try to understand how that pvalue
is created and how many element types there are. Then see whether the appropriate element type for the example is defined. Just a lot of stuff to do.
So, if I come up with anything, I’ll post it. If not, hopefully, a mentor will pick up the thread and help.
2 Likes
I’ve faced a similar issue when practicing course2_week4_lab_3 on Colab notebook. After refer https://github.com/tensorflow/tfx/releases I resolve by re-install packages:
TensorFlow version: 2.8.2
TFX version: 1.8.0
Beam version: 2.38
Python version: 3.7.13
1 Like
Thank you @tannguyen,
!pip install -U pip
!pip install -U tfx==1.8.0
!pip install -U TensorFlow==2.8.2
!pip install -U Beam==2.38
!pip install -U apache-beam==2.38
Installing these packages has gotten me most of the way. However, when I run the trainer a second time in order to have the evaluator compare the two models, this occurs:
AlreadyExistsError: Given node already exists: type_id: 25
Tensorflow explains this error as:
For example, running an operation that saves a file (e.g. tf.train.Saver.save
) could potentially raise this exception if an explicit filename for an existing file was passed.
So I’ll look through the trainer code.
Adding pip install apache-beam==2.39.0 to the start of the notebook solved the problem for me. More here.
Hi everyone! Thank you for reporting! We escalated this yesterday to our partners and as Marcus mentioned, we should downgrade apache beam till TFX v1.9 is released. Will be updating the notebooks today with this workaround. Thank you!
Thank you @chris.favila, @Marcus_Streips, @tannguyen, @gent.spah, and @Tapani_Honkanen. I greatly appreciate everyone’s efforts in addressing the issue.
2 Likes
Hello again! The notebooks have now been updated. Kindly re-open it from the classroom to see the changes. Hope it also works on your end!
Hi @chris.favila,
Just ran the notebook and can confirm that all of the cells ran without fail. Thank you again. Really am impressed by how promptly everyone responded, and how quickly this was resolved.
1 Like
Thank you Alvaro! Glad it works now! Enjoy the rest of the course!