application_vnd.jupyter.stderr_output_1.png
from tensorflow import keras

import tensorflow as tf

def auto_select_accelerator():
    try:
        tpu = tf.distribute.cluster_resolver.TPUClusterResolver()
        tf.config.experimental_connect_to_cluster(tpu)
        tf.tpu.experimental.initialize_tpu_system(tpu)
        strategy = tf.distribute.experimental.TPUStrategy(tpu)
    except ValueError:
        strategy = tf.distribute.get_strategy()
    return strategy

strategy = auto_select_accelerator()

with strategy.scope():
    DistilBERTmodel = TFDistilBertModel.from_pretrained('distilbert-base-uncased', config=config)
    model = create_model(DistilBERTmodel)
    model.compile(keras.optimizers.Adam(lr), loss='binary_crossentropy', metrics=['accuracy'])