Site icon Exam4Training

What should you do?

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 224×224

• 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?
A . Change the optimizer
B . Reduce the batch size
C . Change the learning rate
D . Reduce the image shape

Answer: B

Explanation:

A ResourceExhaustedError: out of memory (OOM) when allocating tensor is an error that occurs when the GPU runs out of memory while trying to allocate memory for a tensor. A tensor is a multi-dimensional array of numbers that represents the data or the parameters of a machine learning model. The size and shape of a tensor depend on various factors, such as the input data, the model architecture, the batch size, and the optimization algorithm1.

For the use case of training 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, the best option to resolve the error is to reduce the batch size. The batch size is a parameter that determines how many input examples are processed at a time by the model. A larger batch size can improve the model’s accuracy and stability, but it also requires more memory and computation. A smaller batch size can reduce the memory and computation requirements, but it may also affect the model’s performance and convergence2.

By reducing the batch size, the GPU can allocate less memory for each tensor, and avoid running out of memory. Reducing the batch size can also speed up the training process, as the GPU can process more batches in parallel. However, reducing the batch size too much may also have some drawbacks, such as increasing the noise and variance of the gradient updates, and slowing down the convergence of the model. Therefore, the optimal batch size should be chosen based on the trade-off between memory, computation, and performance3.

The other options are not as effective as option B, because they are not directly related to the memory allocation of the GPU.

Option A, changing the optimizer, may affect the speed and quality of the optimization process, but it may not reduce the memory usage of the model.

Option C, changing the learning rate, may affect the convergence and stability of the model, but it may not reduce the memory usage of the model.

Option D, reducing the image shape, may reduce the size of the input tensor, but it may also reduce the quality and resolution of the image, and affect the model’s accuracy. Therefore, option B, reducing the batch size, is the best answer for this question.

Reference: ResourceExhaustedError: OOM when allocating tensor with shape – Stack Overflow

How does batch size affect model performance and training time? – Stack Overflow

How to choose an optimal batch size for training a neural network? – Stack Overflow

Exit mobile version