Skip to content

Failure to create MobileBertSquad artifacts due to tf.Const incompatibility #4865

Closed

Description

@jjohnson-arm

According to your current docs - https://google.github.io/iree/developing-iree/e2e-benchmarking - this might just be because you are still refactoring things, but I thought I would raise it as its partially working (for TF and TFLite).

Describe the bug
After following the instructions for building a python environment I have successfully built the e2e integrations for imagenet via the applications.py script, but when trying to use the mobile_bert_squad_test.py I get failures. I have tried building for iree_vmla, iree_llvmaot and iree_vulkan (both float and quantized versions) and they all give me the same error about tf.Const:

< Python traceback from raise CompilerToolError(stage.completed) omitted >
pyiree.compiler2.tools.CompilerToolError: Error invoking IREE compiler tool iree-tf-import
Diagnostics:
2021-02-10 11:00:30.910542: I external/org_tensorflow/tensorflow/cc/saved_model/reader.cc:32] Reading SavedModel from: /home/jjohnson/.keras/datasets/mobilebert_squad_savedmodels/float
2021-02-10 11:00:30.958606: I external/org_tensorflow/tensorflow/cc/saved_model/reader.cc:55] Reading meta graph with tags { serve }
2021-02-10 11:00:30.967015: I external/org_tensorflow/tensorflow/cc/saved_model/reader.cc:93] Reading SavedModel debug info (if present) from: /home/jjohnson/.keras/datasets/mobilebert_squad_savedmodels/float
2021-02-10 11:00:30.971313: I external/org_tensorflow/tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  SSE3 SSE4.1 SSE4.2 AVX AVX2 FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2021-02-10 11:00:31.119514: I external/org_tensorflow/tensorflow/cc/saved_model/loader.cc:206] Restoring SavedModel bundle.
2021-02-10 11:00:31.172361: I external/org_tensorflow/tensorflow/core/platform/profile_utils/cpu_utils.cc:114] CPU Frequency: 3192235000 Hz
2021-02-10 11:00:31.839933: I external/org_tensorflow/tensorflow/cc/saved_model/loader.cc:190] Running initialization op on SavedModel bundle at path: /home/jjohnson/.keras/datasets/mobilebert_squad_savedmodels/float
2021-02-10 11:00:31.904658: I external/org_tensorflow/tensorflow/cc/saved_model/loader.cc:277] SavedModel load for tags { serve }; Status: success: OK. Took 994130 microseconds.
2021-02-10 11:00:32.372562: I external/org_tensorflow/tensorflow/compiler/mlir/tensorflow/utils/dump_mlir_util.cc:210] disabling MLIR crash reproducer, set env var `MLIR_CRASH_REPRODUCER_DIRECTORY` to enable.
loc("bert/embeddings/assert_less_equal/Assert/Assert/data_0"): error: 'tf.Const' op inferred type(s) 'tensor<!tf.string>' are incompatible with return type(s) of operation '!tf_strings.string'
error: A failure has been detected while processing the MLIR module, a reproducer has been generated in '/tmp/iree/modules/MobileBertSquad/reproducer__iree_llvmaot.mlir.import-tf'
Running iree-tf-import pass pipeline failed (see diagnostics)

Invoked with:
  /home/jjohnson/ml/mlir/iree-build-python/bindings/python/pyiree/tools/tf/iree-tf-import /home/jjohnson/.keras/datasets/mobilebert_squad_savedmodels/float --tf-import-type=savedmodel_v1 --tf-savedmodel-exported-names=serving_default --tf-savedmodel-tags=serve --save-temp-tf-input=/tmp/iree/modules/MobileBertSquad/tf_input.mlir --save-temp-iree-input=/tmp/iree/modules/MobileBertSquad/iree_input.mlir --pass-pipeline-crash-reproducer=/tmp/iree/modules/MobileBertSquad/reproducer__iree_llvmaot.mlir.import-tf

This same script works fine for the tf or tflite backends.
It has created various reproducer files (as mentioned above) which I can supply if needed.

To Reproduce
Followed https://google.github.io/iree/developing-iree/e2e-benchmarking including setting up the Python environment and successfully running the bindings tests and a few of the e2e tests as well as the imagenet applications.py.
Then tried:
python3 ../iree/integrations/tensorflow/e2e/mobile_bert_squad_test.py --target_backends=iree_llvmaot

Activity

  1. rsuderman commented on Feb 26, 2021

    @rsuderman
    Collaborator

    So it appears you model has some embedded string constants via tf.Const. I still have not implemented their support in the strings module so you will have to remove them from the model.

  2. stellaraccident commented on Feb 26, 2021

    @stellaraccident
    Collaborator

    The strings are coming from the assertions, which contain string payloads and are thus not presently supported (also, typically, people authoring models disable assertions for serving, etc, so it is a low priority feature for us).

    What I can't see is that this is from one of our examples/unit tests and I wouldn't expect it to be behaving differently for you as an end user. @rsuderman (or someone on the team): can you please try to repro the user flow and find out why the assertions are being enabled?

  3. jjohnson-arm commented on Mar 2, 2021

    @jjohnson-arm
    Author

    Thanks for the info. I don't think I can fix the problem by removing the assert strings as the integrations/tensorflow/e2e/mobile_bert_squad_test.py test is downloading the mobilebert model as a protobuf which is contained in https://storage.googleapis.com/cloud-tpu-checkpoints/mobilebert/mobilebert_squad_savedmodels.tar.gz. This model presumably contains the asserts, so removing them doesn't sound easy.
    I have just cleared my downloads folded - ~/.keras and downloaded the model again and it still happens. Maybe you have a previously cached version without asserts?

  4. added
    bug 🐞
    integrations/tensorflow
    on Mar 2, 2021
  5. stellaraccident commented on Mar 2, 2021

    @stellaraccident
    Collaborator

    Hi @jjohnson-arm : I'm trying to repro this issue and can do more digging, but can I confirm that you are experiencing the issue when running: python ../iree/integrations/tensorflow/e2e/mobile_bert_squad_test.py --target_backends=iree_llvmaot (or equiv for your paths)? I'm running that and not encountering the issue.

    To forestall back and forth, the only salient thing on my machine is that I just installed a fresh pip install tf-nightly for this repro. All of my python deps are here (pip freeze):

    absl-py==0.11.0
    astunparse==1.6.3
    cachetools==4.2.1
    certifi==2020.12.5
    chardet==4.0.0
    cmake==3.18.4.post1
    flatbuffers==1.12
    gast==0.4.0
    google-auth==1.27.0
    google-auth-oauthlib==0.4.2
    google-pasta==0.2.0
    grpcio==1.34.1
    h5py==3.1.0
    idna==2.10
    Keras-Preprocessing==1.1.2
    Markdown==3.3.4
    ninja==1.10.0.post2
    numpy==1.19.5
    oauthlib==3.1.0
    opt-einsum==3.3.0
    protobuf==3.15.3
    pyasn1==0.4.8
    pyasn1-modules==0.2.8
    pybind11==2.6.2
    requests==2.25.1
    requests-oauthlib==1.3.0
    rsa==4.7.2
    six==1.15.0
    tb-nightly==2.5.0a20210302
    tensorboard-data-server==0.3.0
    tensorboard-plugin-wit==1.8.0
    termcolor==1.1.0
    tf-estimator-nightly==2.5.0.dev2021030201
    tf-nightly==2.5.0.dev20210302
    typing-extensions==3.7.4.3
    urllib3==1.26.3
    Werkzeug==1.0.1
    wrapt==1.12.1
    
  6. jjohnson-arm commented on Mar 3, 2021

    @jjohnson-arm
    Author

    Hi @stellaraccident - yes, that is the command line I am using. I have just updated my tf-nightly from previous version 2.5.0.dev20210119 and now can't see much difference in my pip/versions to yours. It still fails after installing the new tf-nightly version, though I haven't done a rebuild (yet), just re-issued the test command.

    absl-py==0.11.0
    astunparse==1.6.3
    cachetools==4.2.0
    certifi==2020.12.5
    chardet==4.0.0
    flatbuffers==1.12
    gast==0.4.0
    google-auth==1.24.0
    google-auth-oauthlib==0.4.2
    google-pasta==0.2.0
    grpcio==1.34.1
    h5py==3.1.0
    idna==2.10
    Keras-Preprocessing==1.1.2
    Markdown==3.3.3
    numpy==1.19.5
    oauthlib==3.1.0
    opt-einsum==3.3.0
    pkg-resources==0.0.0
    protobuf==3.14.0
    pyasn1==0.4.8
    pyasn1-modules==0.2.8
    requests==2.25.1
    requests-oauthlib==1.3.0
    rsa==4.7
    six==1.15.0
    tb-nightly==2.5.0a20210120
    tensorboard-plugin-wit==1.8.0
    termcolor==1.1.0
    tf-estimator-nightly==2.5.0.dev2021012001
    tf-nightly==2.5.0.dev20210303
    typing-extensions==3.7.4.3
    urllib3==1.26.2
    Werkzeug==1.0.1
    wrapt==1.12.1
    (.venv) jjohnson:iree-build-python:$ ninja --version
    1.10.0
    (.venv) jjohnson:iree-build-python:$ cmake --version
    cmake version 3.16.3
    
  7. stellaraccident commented on Mar 3, 2021

    @stellaraccident
    Collaborator

    This is bizarre: on the one hand, I can attest that we do not support tf asserts but I can't see yet how you are getting a model that has them and I am not. Let me try to create a more dedicated reproducer you can run. For what you have built, can you verify approximately where you are synced to/built? Weeks or months behind? (Just trying to scope where to look for the needle)

  8. benvanik commented on Mar 3, 2021

    @benvanik
    Collaborator

    It's still really good to figure out why as I'm sure there are other effects of this debug mode, but if you find this is something easy for people to trip into then we could add an iree-import-tf pass for stripping the assertions (if they are strippable) that would allow people to move forward. I wouldn't want it enabled by default (as the real solution will be whatever you find to not output them in the first place), but a flag that could be added to at least get something runnable would reduce the blocking nature of the problem.

  9. stellaraccident commented on Mar 3, 2021

    @stellaraccident
    Collaborator

    Indeed - my first thought when I went to triage this was "I'll add a pass to strip asserts". That then morphed into "why am I not getting a model with asserts".

    The tensorflow story for asserts is quite poor and I would consider stripping them by default and having a switch to enable them. Since there is no consistency in tf codebases on this and no flag at that level, it is just a bunch of special case python level conditions that people have added so they can have test only asserts -- usually when they find out that their training is slow.

  10. benvanik commented on Mar 3, 2021

    @benvanik
    Collaborator

    Haha that makes sense - asserts should by nature not be load-bearing so stripping them should always be safe - but like you say who knows what kind of behavior is being used in tf-land :)

  11. jjohnson-arm commented on Mar 3, 2021

    @jjohnson-arm
    Author

    I have had 2 builds that I have tried and they both have the same problems (checking out a later version was the first thing I tried):

    commit 35d4b328ad8aebb84b43c7ffeaa5ddc86db9f0cb (HEAD -> main, origin/main, origin/HEAD)
    Date:   Wed Jan 6 14:24:26 2021 +0000
    

    and

    commit 46963f77832a4d5050e9a866c1044da950963dd8 (HEAD -> main, tag: snapshot-20210209.88, origin/main, origin/HEAD)
    Date:   Mon Feb 8 15:11:13 2021 -0800
    

    I can try building the latest version with the latest tf-nightly and get back to you.

    If it is a model problem, could you have a cached version?

    Update - these are the details from my .keras download:

    jjohnson:iree-Feb21:main$ ls -l ~/.keras/datasets/
    total 180408
    drwxr-x--- 4 jjohnson jjohnson      4096 Jun 22  2020 mobilebert_squad_savedmodels
    -rw-rw-r-- 1 jjohnson jjohnson 184730530 Mar  3 15:40 mobilebert_squad_savedmodels.tar.gz.tar.gz
    jjohnson:iree-Feb21:main$ md5sum ~/.keras/datasets/mobilebert_squad_savedmodels.tar.gz.tar.gz 
    9bbaf4015e54d91431dbbf72ba29d5c1  /home/jjohnson/.keras/datasets/mobilebert_squad_savedmodels.tar.gz.tar.gz
    
  12. stellaraccident commented on Apr 2, 2021

    @stellaraccident
    Collaborator

    I think that #5294 fixes this. Closing but feel free to re-open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bug 🐞integrations/tensorflow

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions