Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Colab TPU suddenly not found anymore

Issue

Since Monday or Thuesday this week (10.03.2025) the Google Colab TPUs are not found anymore.

Can someone help me please?

I am using

  • TensorFlow Version: 2.18.1
  • Keras-Tuner Version: 1.4.7

These are my resources

Sie haben Colab Pro abonniert. Weitere Informationen
Verfügbar: 55.47 Recheneinheiten
Nutzungsrate: ca. 3.66 pro Stunde
Sie haben 4 aktive Sitzungen.

This is my code

# TPU Strategy Setup
try:
    print("Connecting to TPU...")
    tpu = tf.distribute.cluster_resolver.TPUClusterResolver()  # Resolving TPU cluster
    tf.config.experimental_connect_to_cluster(tpu)
    tf.tpu.experimental.initialize_tpu_system(tpu)
    print("TPU initialized successfully!")
    strategy = tf.distribute.TPUStrategy(tpu)  # TPU strategy definition
except ValueError:
    print("TPU not found. Falling back to CPU/GPU strategy.")
    strategy = tf.distribute.get_strategy()  # Default CPU/GPU strategy

# Confirm strategy definition
if 'strategy' not in locals():
    raise RuntimeError("TPU strategy setup failed. Please check TPU initialization.")

# Log TPU Configuration
print(f"Using distribution strategy: {strategy.__class__.__name__}")
print(f"Number of replicas: {strategy.num_replicas_in_sync}")

tf.debugging.set_log_device_placement(True)

# Enable Mixed Precision for TPU optimization
policy = mixed_precision.Policy('mixed_bfloat16')
mixed_precision.set_global_policy(policy)
print("Mixed Precision enabled: ", policy)

Output: Connecting to TPU... TPU not found. Falling back to CPU/GPU strategy. Using distribution strategy: _DefaultDistributionStrategy Number of replicas: 1 Mixed Precision enabled: <DTypePolicy "mixed_bfloat16">

I tried dto switch the run time types back- and forward including saving them, restarting the sessions, logging in and out of the Google colab account.

I except to get the TPU found and up and running like last week.

like image 561
Albert Blarer Avatar asked Nov 21 '25 21:11

Albert Blarer


1 Answers

This solution works for me:

!pip install tensorflow==2.18.0
!pip install tensorflow-tpu==2.18.0 --find-links=https://storage.googleapis.com/libtpu-tf-releases/index.html

import tensorflow as tf

try:
    tpu = tf.distribute.cluster_resolver.TPUClusterResolver(tpu='local')
    tf.config.experimental_connect_to_cluster(tpu)
    tf.tpu.experimental.initialize_tpu_system(tpu)
    strategy = tf.distribute.TPUStrategy(tpu)
    print("TPU is running:", tpu.master())
except ValueError as e:
    print("TPU is not avaible:", e)
like image 99
kubas126 Avatar answered Nov 24 '25 22:11

kubas126