1

I have zero experience in Tensorflow and recently started studying about NLP. Came across the Tensorflow implementation of the Transformer based on Attention is All You Need paper.

Tensor2Tensor package has a Quick Start section which has a colab link

Quick Start
This iPython notebook explains T2T and runs in your browser using a free VM from Google, no installation needed.

I wanted to run this and it gives the error

ValueError: Tensorflow 1 is unsupported in Colab.

Your notebook should be updated to use Tensorflow 2.
See the guide at https://www.tensorflow.org/guide/migrate#migrate-from-tensorflow-1x-to-tensorflow-2.

Have no clue on what to change.

I'm I not supposed to run the colab but just observe the already printed results. Is there a Tensorflow 2 version which I can run and see.

cmgchess
  • 7,996
  • 37
  • 44
  • 62

2 Answers2

2

From the error it looks like that the code you want to use is based on Tensorflow 1. You should know that Colab recently removed support for Tf1. You can still install it manually though. Just remove the previous Tf2 installation and replace it with the previous version like this:

!pip uninstall tensorflow
!pip install tensorflow-gpu==1.15

This is almost always enough (you could be asked to restart the runtime for the change to take effect). However, if you experience errors due to the version of Cuda, you could try to re-install cuda and libcudnn too with:

!apt install --allow-change-held-packages libcudnn7=7.4.1.5-1+cuda10.0

Update:

After manually installing tensorflow 1 you can remove the instruction %tensorflow_version 1.x, which is called a magic. Before tf1 got discontinued in Colab, that instruction could have been used to activate it instead of doing the installation by hand.

Also inside the QuickStart of the repo, it says that you should also install two packages. So after the installation of tensorflow add:

!pip install tensor2tensor 
!pip install t2t-trainer 
ClaudiaR
  • 3,108
  • 2
  • 13
  • 27
  • 1
    i added the `!pip uninstall tensorflow !pip install tensorflow-gpu==1.15` in top of the `#Install deps` block but still it gves error. so I removed `if 'google.colab' in sys.modules: # Colab-only TensorFlow version selector %tensorflow_version 1.x` part. but now it gives error in line `from tensor2tensor import models` – cmgchess Aug 26 '22 at 13:47
  • Yes, you correctly removed `%tensorflow_version 1.x`. That instruction is called a "magic" and it was needed to actually activate that version. Now that tf1 has got discontinued is generating error. About the new error... I had a look at the repo you linked, and in the QuickStart it says that you should also install two packages. So after the installation of tensorflow just do: `!pip install tensor2tensor` and `!pip install t2t-trainer` – ClaudiaR Aug 26 '22 at 13:53
  • I still cant get it to work. I cloned it with the changes I did and edit access https://colab.research.google.com/drive/1Saoi4tIc6LXoMPSAo1o694DlYqfKb5o_?usp=sharing. can you help me where to change – cmgchess Aug 26 '22 at 14:37
  • Alright, try installing this specific versions: `tensorflow==1.15.2` and `tensor2tensor==1.5.4`. This should fix the import errors at least – ClaudiaR Aug 26 '22 at 15:03
  • 2
    now it gives error in the line `tfe.enable_eager_execution()` saying `AttributeError: module 'tensorflow.contrib.eager' has no attribute 'enable_eager_execution'`. I already reported an issue in their github. hope they will also update it – cmgchess Aug 26 '22 at 15:14
  • maybe this? https://stackoverflow.com/a/58966060/14774959 – ClaudiaR Aug 26 '22 at 15:18
0

after following the steps above, i encountered this error:

Loaded runtime CuDNN library: 7.4.1 but source was compiled with: 7.6.0.  CuDNN library major and minor version needs to match or have higher minor version in case of CuDNN 7.0 or later version. If using a binary install, upgrade your CuDNN library.  If building from sources, make sure the library loaded at runtime is compatible with the version specified during compile configuration

Seems like even after installing the compatible cudnn version it doesnt work, how can I work around this issue?