All interview guides

TensorFlow Interview Questions and Answers

24 questions that come up in TensorFlow technical interviews, each with the answer and an explanation of why it is right.

Test yourself — 90 question bank

1. What is distributed training?

Advanced

Answer: Training across multiple GPUs or machines

Distributed training trains models across multiple GPUs/machines. Speeds up training for large models/datasets. TensorFlow provides tf.distribute strategies.

2. What is the Functional API?

Intermediate

Answer: Flexible API for building complex models with branching

Functional API builds models as graphs of layers. More flexible than Sequential. Supports multi-input/output, shared layers, branching.

3. What is TensorFlow?

Beginner

Answer: Open-source machine learning framework by Google

TensorFlow is an open-source end-to-end machine learning platform developed by Google Brain team. It provides tools for building and deploying ML models.

4. What is a tensor?

Beginner

Answer: Multi-dimensional array, fundamental data structure

A tensor is a multi-dimensional array with a uniform type. It is the fundamental data structure in TensorFlow, generalizing scalars, vectors, and matrices.

5. What is MirroredStrategy?

Advanced

Answer: Synchronous training on multiple GPUs on single machine

MirroredStrategy performs synchronous training across multiple GPUs on single machine. Replicates model on each GPU, aggregates gradients. Simplest multi-GPU strategy.

6. What is tf.data.Dataset?

Intermediate

Answer: API for building efficient input pipelines

tf.data.Dataset provides efficient data pipeline API. Supports lazy evaluation, parallel processing, prefetching. Essential for large datasets.

7. What is MultiWorkerMirroredStrategy?

Advanced

Answer: Synchronous training across multiple machines

MultiWorkerMirroredStrategy extends MirroredStrategy to multiple machines. Each machine can have multiple GPUs. Uses collective communication (all-reduce).

8. How do you create a constant tensor?

Beginner

Answer: tf.constant([1, 2, 3])

Use tf.constant() to create a constant tensor. Example: tf.constant([1, 2, 3]) creates a 1D tensor with immutable values.

9. What does dataset.batch() do?

Intermediate

Answer: Combines consecutive elements into batches

dataset.batch(batch_size) combines consecutive elements into batches. Essential for mini-batch gradient descent training.

10. What is TPUStrategy?

Advanced

Answer: Strategy for training on Tensor Processing Units

TPUStrategy enables training on Google TPUs. TPUs are specialized hardware for ML. Extremely fast for large models. Use with TPU-optimized code.

11. What does dataset.prefetch() do?

Intermediate

Answer: Prefetches data while training to reduce waiting

dataset.prefetch() overlaps data preprocessing and model execution. Fetches next batch while training on current. Improves performance.

12. What is the difference between tf.constant and tf.Variable?

Beginner

Answer: tf.constant is immutable, tf.Variable is mutable

tf.constant creates immutable tensors. tf.Variable creates mutable tensors that can be updated during training (weights, biases).

13. What is data augmentation?

Intermediate

Answer: Artificially increases dataset through transformations

Data augmentation artificially expands training data through random transformations (rotation, flip, crop, etc.). Reduces overfitting, improves generalization.

14. What is Keras?

Beginner

Answer: High-level neural networks API integrated into TensorFlow

Keras is a high-level neural networks API. Since TensorFlow 2.0, it is tightly integrated as tf.keras, the recommended way to build models.

15. What is gradient accumulation?

Advanced

Answer: Accumulates gradients over multiple batches before updating

Gradient accumulation accumulates gradients over multiple mini-batches before updating weights. Simulates larger batch size with limited memory.

16. What is automatic mixed precision (AMP)?

Advanced

Answer: Automatically uses float16/float32 for optimal performance

AMP automatically chooses float16/float32 per operation for optimal performance and stability. Use tf.keras.mixed_precision.Policy. Requires gradient scaling.

17. What is tf.keras.Sequential?

Beginner

Answer: Sequential model stacking layers linearly

Sequential is a linear stack of layers. Most straightforward way to build models. Each layer has one input and one output tensor.

18. What is pooling?

Intermediate

Answer: Downsampling operation reducing spatial dimensions

Pooling reduces spatial dimensions of feature maps. MaxPooling takes maximum, AvgPooling takes average. Reduces parameters and computation.

19. What is XLA (Accelerated Linear Algebra)?

Advanced

Answer: Compiler optimizing TensorFlow computations

XLA compiles TensorFlow computations to optimized code. Fuses operations, reduces memory, improves speed. Enable with jit_compile=True or tf.function(jit_compile=True).

20. How do you add a layer to Sequential model?

Beginner

Answer: model.add(layer)

Use model.add(layer) to add layers to Sequential model. Example: model.add(tf.keras.layers.Dense(64, activation='relu')).

21. What is model pruning?

Advanced

Answer: Removes unimportant weights to reduce model size

Pruning removes unimportant weights/neurons. Reduces model size and inference time. May require fine-tuning. Use TensorFlow Model Optimization toolkit.

22. What is batch normalization?

Intermediate

Answer: Normalizes layer inputs for each mini-batch

Batch normalization normalizes layer inputs across mini-batch. Stabilizes and speeds up training. Reduces internal covariate shift.

23. What is a Dense layer?

Beginner

Answer: Fully connected layer where each neuron connects to all inputs

Dense layer is a fully connected layer. Each output is computed from all inputs: output = activation(dot(input, weights) + bias).

24. What is a callback?

Intermediate

Answer: Function called at training stages for custom behavior

Callbacks are functions called at specific training stages. Examples: EarlyStopping, ModelCheckpoint, ReduceLROnPlateau, TensorBoard.

Ready to test yourself?

The full TensorFlow bank has 90 questions across 3 difficulty levels — timed, shuffled, and scored.

Take the TensorFlow quiz