PROFESSIONAL-MACHINE-LEARNING-ENGINEER practice question 19 of 35

You need to train a computer vision model that predicts the type of government ID present in a given image using a GPU-powered virtual machine on…

Full set: 283 questions
You need to train a computer vision model that predicts the type of government ID present in a given image using a GPU-powered virtual machine on Compute Engine. You use the following parameters: • Optimizer: SGD • Image shape 224x224 • Batch size 64 • Epochs 10 • Verbose 2 During training you encounter the following error: ResourceExhaustedError: out of Memory (oom) when allocating tensor. What should you do?
Answer options
A: Change the optimizer
B: Reduce the batch size Correct answer
C: Change the learning rate
D: Reduce the image shape
Correct Answer:
B. Reduce the batch size
Explanation

The ResourceExhaustedError: out of Memory (oom) indicates that the GPU's VRAM is insufficient to hold the model, its gradients, and the current batch of data simultaneously. The batch size directly determines the number of images and their corresponding activation maps processed in a single forward/backward pass. Reducing the batch size is the most direct and common method to decrease the memory required per training step, thereby resolving the OOM error without altering the model's architecture or the input data's resolution. This allows the training process to fit within the available GPU memory.

Why Incorrect

A. Change the optimizer: The current optimizer, SGD, is already one of the most memory-efficient. Changing it, especially to an adaptive one like Adam, would likely increase memory usage.
C. Change the learning rate: The learning rate is a hyperparameter that controls the optimization step size; it has no direct impact on the amount of memory allocated for tensors.
D. Reduce the image shape: While this would reduce memory usage, it is a more drastic step that alters the input data, potentially losing critical information and degrading model performance. ---

References

1. Google Cloud Documentation: In the official documentation for Vertex AI Training, when discussing GPU usage, it is explicitly recommended to "try reducing the perreplicabatchsize" if you encounter out-of-memory errors.

Source: Google Cloud, Vertex AI Documentation, "Use GPUs for training". Section: "Recommendations for using GPUs".

2. TensorFlow Official Documentation: The TensorFlow guide on GPU usage explains that all tensors for an operation must fit in GPU memory. The size of the data batch is a primary contributor to the memory footprint of a training step. Reducing the batch size directly reduces this footprint.

Source: TensorFlow, "Use a GPU". Section: "Limiting GPU memory growth".

3. Stanford University Courseware (CS231n): Course materials on training neural networks explain that during the forward pass, activations for every neuron in the batch are stored. During the backward pass, gradients are stored. The memory required for these scales linearly with the batch size.

Source: Stanford CS231n: Convolutional Neural Networks for Visual Recognition, "Training Neural Networks, Part 1" notes. Section: "Batch Normalization".

Scroll to Top