Overview
TensorFlow 2.12, released on March 24, 2023, introduces DTensor for distributed computing and prepares the transition to Keras 3.
Main Features
DTensor
DTensor is a distributed tensor API that automatically shards data and computation across multiple devices (GPU/TPU) transparently.
python
import tensorflow as tf
from tensorflow.experimental import dtensor
# Create a compute mesh across 2 devices
mesh = dtensor.create_mesh([("batch", 2)])
layout = dtensor.Layout(["batch", dtensor.UNSHARDED], mesh)
# Automatically distributed tensor
x = dtensor.call_with_layout(
tf.ones, layout, shape=(8, 4)
)
print(f'Shape: {x.shape}') # (8, 4)
Keras 3 preparation
TensorFlow 2.12 introduces API changes that prepare the migration to Keras 3, with better separation between the backend and the high-level API.
python
import tensorflow as tf
# Keras API integrated in TensorFlow
model = tf.keras.Sequential([
tf.keras.layers.Dense(128, activation='relu'),
tf.keras.layers.Dropout(0.2),
tf.keras.layers.Dense(10, activation='softmax'),
])
model.compile(
optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy'],
)
