11

I tried

%tensorflow_version 1.15

I used this code a couple days ago, but it doesn't work anymore since today.

The outcomes are

ValueError                                Traceback (most recent call last)
<ipython-input-6-24c52e77c597> in <module>()
----> 1 get_ipython().magic('tensorflow_version 1.15')

2 frames
/usr/local/lib/python3.7/dist-packages/IPython/core/interactiveshell.py in magic(self, arg_s)
   2158         magic_name, _, magic_arg_s = arg_s.partition(' ')
   2159         magic_name = magic_name.lstrip(prefilter.ESC_MAGIC)
-> 2160         return self.run_line_magic(magic_name, magic_arg_s)
   2161 
   2162     #-------------------------------------------------------------------------

/usr/local/lib/python3.7/dist-packages/IPython/core/interactiveshell.py in run_line_magic(self, magic_name, line)
   2079                 kwargs['local_ns'] = sys._getframe(stack_depth).f_locals
   2080             with self.builtin_trap:
-> 2081                 result = fn(*args,**kwargs)
   2082             return result
   2083 

/usr/local/lib/python3.7/dist-packages/google/colab/_tensorflow_magics.py in _tensorflow_version(line)
     39 
     40              Your notebook should be updated to use Tensorflow 2.
---> 41              See the guide at https://www.tensorflow.org/guide/migrate#migrate-from-tensorflow-1x-to-tensorflow-2."""
     42                        ))
     43 

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.

Is there any method I can try to fix it or does it means that colab will not support tensorflow 1.x anymore?

Shawn
  • 113
  • 1
  • 1
  • 5
  • I get the same problem - shouldn't it be possible to just install 1.x with pip and then modify it somehow, its obviously a hassle but far easier than the alternative... – John Doe Aug 03 '22 at 19:07
  • 2
    Using !pip install tensorflow==1.15.2 instead of %tensorflow_version 1.x works for me - it does however appear that colab is substantially slower now... – John Doe Aug 03 '22 at 19:16
  • 2
    It seems work for me too. Maybe you'd better using tensorflow-gpu==1.15 instead of tensorflow. – Shawn Aug 04 '22 at 03:12
  • Sweet! Thanks let me check it out – John Doe Aug 04 '22 at 20:08
  • It is much faster using the "tensorflow-gpu==1.15" massive thanks! – John Doe Aug 09 '22 at 11:09

2 Answers2

11

Google Colab removed support for Tensorflow 1, and it is not possible to use %tensorflow_version 1.x magic anymore. You must remove this instruction from your code if you have it.

Also the default python version as I update this answer is python 3.8 which is not compatible with tensorflow 1.x.

To make everything work you first have to downgrade python. Python 3.6 should work. As suggested by @s-abbaasi here's a guide on how to do so:

%%bash

MINICONDA_INSTALLER_SCRIPT=Miniconda3-4.5.4-Linux-x86_64.sh
MINICONDA_PREFIX=/usr/local
wget https://repo.continuum.io/miniconda/$MINICONDA_INSTALLER_SCRIPT
chmod +x $MINICONDA_INSTALLER_SCRIPT
./$MINICONDA_INSTALLER_SCRIPT -b -f -p $MINICONDA_PREFIX

Then add to path:

import sys
_ = (sys.path.append("/usr/local/lib/python3.6/site-packages"))

At this point you can manually uninstall and re-install tensorflow through pip:

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

Doing just so I sometimes encounter some errors due to the Cuda version. If this happens to you, you can execute the following:

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

The most appropriate version of cuda and libcudnn to use with the tensorflow version you want to install can be found here.

The versions available of libcudnn can be found with the following command:

!apt list -a libcudnn7

This will list all libcudnn7 versions available.

ClaudiaR
  • 3,108
  • 2
  • 13
  • 27
  • Exception is raised anyway – kubinka0505 Sep 11 '22 at 22:40
  • You have to remove the `%tensorflow_version 1.x` instruction that can’t be used anymore. Installing manually replaces the instruction @kubinka0505 – ClaudiaR Sep 12 '22 at 06:20
  • Uninstalling done but while running `!pip install tensorflow-gpu==1.15` the following error raises: `Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/ ERROR: Could not find a version that satisfies the requirement tensorflow-gpu==1.15 (from versions: 2.2.0,...) ERROR: No matching distribution found for tensorflow-gpu==1.15` – s.abbaasi Dec 16 '22 at 20:41
  • 2
    I think they recently updated the python version in google colab to 3.8 which is not compatible with tensorflow 1.x. The solution would be to downgrade python. @s.abbaasi – ClaudiaR Dec 17 '22 at 21:21
  • Thanks @ClaudiaR. Downgrading python works for me. Here is a guide to downgrade: https://stackoverflow.com/a/66776080/2962705 I recommend you to add downgrade solution to your post. So other users can consider it. – s.abbaasi Dec 21 '22 at 16:41
5

I was having the same problems while trying to use StyleGAN2-ADA, which only supports TensorFlow 1.

I found out that unfortunately Google Colab removed support for TensorFlow 1 in their latest release of 2022/8/11.

'Removed support for TensorFlow 1'

You can find more information in their notebook Release-Notes: https://colab.research.google.com/notebooks/relnotes.ipynb

Nicolò
  • 51
  • 1
  • 1
    Probably the most annoying thing Google has done, it takes money and engineering work to restructure massive codebases to TF2 from TF1. – Arka Mukherjee Nov 25 '22 at 07:48
  • It seems that only tf2 is supported by Colab, but that's not true, you still can use pip to uninstall tf2 and install a specific version of tf1. !yes|pip uninstall tensorflow, !pip install tensorflow==1.15.5 Maybe you should install other dependencies. So use !pip install -r requirements.txt Attention! You must restart the runtime in order to use newly installed versions. – Claude COULOMBE Nov 30 '22 at 08:45