Home › Blog › TensorFlow Interview Questions (2026): 30 Questions on Keras, tf.function and tf.data

TensorFlow Interview Questions (2026): 30 Questions on Keras, tf.function and tf.data

TensorFlow interview questions test TensorFlow 2's eager-first model, tf.function graphs and retracing, GradientTape , the Keras 3 model APIs and training loop, tf.data input pipelines, distribution strategies, and how models are saved and served. On November 17, 2026, PyPI listed TensorFlow 2.21.0 (March 6, 2026) as the latest stable release, with 2.22.0rc1 as a release candidate.

TensorFlow interview questions test TensorFlow 2's eager-first model, tf.function graphs and retracing, GradientTape, the Keras 3 model APIs and training loop, tf.data input pipelines, distribution strategies, and how models are saved and served. On November 17, 2026, PyPI listed TensorFlow 2.21.0 (March 6, 2026) as the latest stable release, with 2.22.0rc1 as a release candidate. TensorFlow's release notes say 2.16 made Keras 3 the default and removed tf.estimator, and 2.20 told users to migrate from tf.lite to LiteRT.

Below are 30 questions by level, five debugging scenarios and how ML interviews test this. Theory follow-ups are in deep learning interview questions, and the role-level view is in machine learning engineer interview questions.

TensorFlow interview questions: fundamentals (1–10)

  1. What is TensorFlow? Google's open-source machine learning platform: tensors, automatic differentiation and GPU and TPU support, with Keras as the high-level API, tf.data for input pipelines and TF Serving and LiteRT for deployment.
  2. What is eager execution? The TensorFlow 2 default: operations run immediately and return concrete values, so you can debug with ordinary Python.
  3. tf.Tensor versus tf.Variable? Tensors are immutable values. Variables hold mutable state such as weights, change with assign, and are tracked automatically for gradients when trainable.
  4. What are the three Keras model APIs? Sequential for a linear stack of layers; Functional for graphs with multiple inputs or outputs and shared layers; subclassing keras.Model with a custom call() for full control.
  5. What do compile and fit do? model.compile(optimizer="adam", loss=..., metrics=[...]) configures training; model.fit(x, y, epochs=10, validation_data=..., callbacks=[...]) runs it; evaluate and predict follow.
  6. Sparse or categorical cross-entropy? SparseCategoricalCrossentropy for integer labels, CategoricalCrossentropy for one-hot labels. Set from_logits=True when the last layer has no softmax.
  7. Which callbacks matter? EarlyStopping(monitor="val_loss", patience=5, restore_best_weights=True), ModelCheckpoint, ReduceLROnPlateau and TensorBoard.
  8. How do you reduce overfitting? More data or augmentation, dropout, L2 regularization, early stopping, a smaller model, and a validation split that reflects real data.
  9. What is Keras 3? A multi-backend Keras that runs on TensorFlow, JAX or PyTorch. It became the default in TensorFlow 2.16; to stay on Keras 2, the release notes say to install tf-keras and set TF_USE_LEGACY_KERAS=1.
  10. How do you save a Keras model? model.save("model.keras") writes the native Keras format, and the path must end in .keras; reload it with keras.models.load_model.

Intermediate TensorFlow questions (11–20)

  1. How does GradientTape work? with tf.GradientTape() as tape: loss = loss_fn(y, model(x, training=True)), then grads = tape.gradient(loss, model.trainable_variables) and optimizer.apply_gradients(zip(grads, model.trainable_variables)).
  2. What does tf.function do? It traces a Python function into a graph that runs faster and can be exported. Python side effects such as print run only while tracing; use tf.print inside.
  3. What causes retracing? New input shapes or dtypes, or new Python argument values, each create a new graph. Pass tensors instead of Python numbers, fix an input_signature, or set reduce_retracing=True.
  4. What is AutoGraph? The converter inside tf.function that turns Python if and while on tensors into graph control flow such as tf.cond and tf.while_loop.
  5. Build an efficient tf.data pipeline. ds.map(parse, num_parallel_calls=tf.data.AUTOTUNE).cache().shuffle(10000).batch(64).prefetch(tf.data.AUTOTUNE): parse in parallel, cache after expensive work, shuffle before batching, prefetch last.
  6. How big should the shuffle buffer be? Large enough to mix the data well; a buffer that holds the whole dataset gives a full shuffle if it fits in memory. A tiny buffer over sorted data barely shuffles.
  7. Why does the training argument matter? Dropout and batch normalization behave differently in training and inference. Pass training=True or False in custom loops. In Keras, setting trainable=False on a BatchNormalization layer also makes it run in inference mode, which matters when fine-tuning.
  8. How do you do transfer learning? Load a pretrained base from keras.applications, set base.trainable = False, train a new head, then unfreeze the top layers and continue with a low learning rate.
  9. How do you customize training but keep fit()? Override train_step in a keras.Model subclass, so callbacks, metrics and distribution still work with your own step logic.
  10. How do you enable mixed precision? keras.mixed_precision.set_global_policy("mixed_float16"), keeping the final layer in float32 for numeric stability; fit applies loss scaling for you.

Experienced and senior TensorFlow questions (21–30)

  1. Which distribution strategies exist? MirroredStrategy (several GPUs on one machine, synchronous), MultiWorkerMirroredStrategy, TPUStrategy and ParameterServerStrategy. Build and compile the model inside strategy.scope().
  2. How do you export for TF Serving? In Keras 3, model.export("path", format="tf_saved_model") writes a SavedModel for TF Serving. Per keras.io, export also supports onnx, openvino, litert and torch formats.
  3. What is happening with TensorFlow Lite? It is now LiteRT. The 2.20 release notes say tf.lite will be removed from the TensorFlow Python package in a future release, and tf.lite.Interpreter warns and points to ai_edge_litert.interpreter.
  4. How do you find a performance bottleneck? The TensorBoard profiler shows input-pipeline stalls and slow ops. Common fixes: a better tf.data pipeline, larger batches, mixed precision and XLA via jit_compile=True.
  5. Why does TensorFlow grab all GPU memory? By default it maps most GPU memory at startup. tf.config.experimental.set_memory_growth(gpu, True) allocates on demand, which helps when processes share a GPU.
  6. How do you write a custom layer? Subclass keras.layers.Layer, create weights in build(input_shape) with add_weight, compute in call, and implement get_config so the model can be saved and reloaded.
  7. What are ragged and sparse tensors? tf.RaggedTensor holds variable-length rows such as tokenized sentences; tf.sparse.SparseTensor stores mostly-zero data efficiently.
  8. How do you handle class imbalance? class_weight in fit, sample weights, resampling in tf.data, focal loss, and metrics such as precision, recall and AUC instead of accuracy.
  9. TensorFlow or PyTorch? TensorFlow's strengths are its deployment stack (Serving, LiteRT) and TPU support; PyTorch is widely used in research code. With Keras 3 you can switch backends. Interviewers want a reasoned choice, not loyalty.
  10. Which version changes should you know? 2.16: Keras 3 by default and tf.estimator removed. 2.20: migrate from tf.lite to LiteRT. 2.21: Python 3.9 support and the TensorBoard dependency removed.

TensorFlow scenario and troubleshooting questions

A tf.function keeps getting slower and logs retracing warnings. It is called with Python scalars or changing shapes. Pass tensors, add an input_signature with None dimensions, or set reduce_retracing=True.

Predictions in production differ from the notebook. Preprocessing differs between training and serving. Put preprocessing layers inside the model so the exported artifact carries them, and check the training flag.

The GPU is underused. The input pipeline cannot keep up. Add parallel map, cache and prefetch, use TFRecord files, and confirm with the profiler.

The loss becomes NaN. Check the learning rate, a from_logits mismatch, logs of zero, and a float16 output layer under mixed precision. tf.debugging.enable_check_numerics() finds the first bad op.

Old tutorial code fails on TensorFlow 2.16 or later. Keras 3 is now the default and tf.estimator is gone. Migrate to Keras 3 APIs: save with .keras files and export SavedModels with model.export; use tf-keras with TF_USE_LEGACY_KERAS=1 only as a stopgap.

How TensorFlow interviews test this

FormatWhat it usually looks likeHow to prepare
Concept Q&AEager versus graph, tf.function, GradientTape, Keras APIs, lossesExplain retracing and the training flag with examples
Live codingBuild and train a Keras model; write a custom training loopDo both versions for one small dataset
ML system designInput pipelines, distributed training, export and servingDraw tf.data, strategy scope and SavedModel export end to end
Applied roundTransfer learning or a vision taskSee computer vision interview questions

Many teams also use PyTorch; PyTorch interview questions covers the same ground there.

Where CoPilot Interview fits

CoPilot Interview is an AI interview assistant. Its free AI mock interview builds TensorFlow and machine learning questions from your résumé and the job description, reads them aloud and scores each spoken answer out of 10, which is a fast way to find the answers above that you know but cannot yet explain cleanly under pressure. The browser demo has 145 practice questions in 10 tracks, scores typed answers out of 10 and needs no signup. The free plan gives 15 minutes a day of live help in sessions of up to 15 minutes, with AI mock interviews included. Paid plans are Standard at $24.99 a month and Pro at $39.99 a month, in the desktop app for Windows 10/11 and macOS 12 or later.

Use it to practice. Online assessments, proctored tests, take-home tasks with rules and AI-led rounds forbid outside help, so prepare for those instead of bringing a tool. For any live interview, follow your employer's rules.

Disclosure: CoPilot Interview is our product, so weigh what we say about it accordingly.

Frequently asked questions

What are the most common TensorFlow interview questions?

Eager execution versus tf.function, retracing, GradientTape, Sequential versus Functional versus subclassed models, callbacks, tf.data pipelines, distribution strategies, and saving and exporting models.

What is the latest TensorFlow version?

PyPI listed TensorFlow 2.21.0, released March 6, 2026, as the latest stable release on November 17, 2026, with 2.22.0rc1 available as a release candidate.

Is TensorFlow still used in 2026?

Yes, especially where its deployment tools (TF Serving, LiteRT) or TPUs matter, and Keras 3 lets teams keep one model API across TensorFlow, JAX and PyTorch backends.

What is the difference between tf.keras and Keras 3?

Since TensorFlow 2.16, tf.keras refers to Keras 3, the multi-backend version. The older Keras 2 lives on as the tf-keras package.

How do I prepare for a TensorFlow interview?

Build one model with fit and the same model with a GradientTape loop, add a tf.data pipeline with prefetching, export it with model.export, and explain each step aloud.

Practice this interview before the real one

The AI mock interview builds questions from your resume and the job description, reads them aloud and scores each spoken answer out of 10. Included on the free plan.

Start a mock interview