PyTorch Certified Associate (PTCA) Free Sample Questions

Description

Covers core PyTorch concepts, tensors and model training and testing, building neural network blocks, precision, and datasets, DataLoaders and transforms for data handling.

12 free sample questions150 in the full practice test

Try simulator

PTCA Sample Questions

  1. Question 1

    Beginner

    PyTorch Fundamentals · Tensor creation and operations

    An ML engineer is initializing a tensor from a nested Python list and needs PyTorch to track operations on it for automatic differentiation. Which of the following approaches is the most idiomatic and efficient way to achieve this upon creation?

    Answer and explanation

    Correct answer: B

    The factory function torch.tensor() accepts a requires_grad keyword argument, allowing you to create the tensor and enable gradient tracking in a single, efficient step. The other options either use invalid attributes (track_grad) or unnecessary multi-step procedures.

  2. Question 2

    Intermediate

    PyTorch Fundamentals · PyTorch core concepts and workflow

    A researcher is implementing a custom regularization penalty. They need to extract an intermediate feature map from the forward pass, perform some non-differentiable numpy operations on it to calculate a logging metric, and then continue the standard backward pass using the original feature map.

    Which PyTorch mechanism should be used to extract the feature map for the logging metric without breaking or modifying the computation graph?

    Answer and explanation

    Correct answer: C

    The .detach() method returns a new Tensor that shares the same storage as the original but is detached from the computation graph (requires_grad=False). This allows you to safely move it to numpy for logging without corrupting the backpropagation flow of the original tensor.

  3. Question 3

    Beginner

    PyTorch Fundamentals · Training / evaluation / inference workflow

    True or False: Calling model.eval() automatically disables gradient computation during the forward pass, effectively acting as a substitute for torch.no_grad() during inference.

    Answer and explanation

    Correct answer: B

    False. model.eval() only changes the behavior of certain layers like Dropout and BatchNorm to evaluation mode. It does NOT disable gradient tracking. You must explicitly use the torch.no_grad() or torch.inference_mode() context managers to disable gradient computation and save memory.

  4. Question 4

    Intermediate

    PyTorch Fundamentals · Device placement and management

    During the setup phase of a deep learning pipeline, an architect configures the model and optimizer. Which of the following sequences represents the correct best practice for initializing an optimizer in relation to moving the model to a target hardware device (e.g., GPU)?

    Answer and explanation

    Correct answer: B

    You must move the model to the target device before passing its parameters to the optimizer. If you initialize the optimizer first and then move the model, the optimizer will hold references to the old CPU parameters, while the model will use the newly allocated GPU parameters, causing the optimizer step to have no effect on the model's actual GPU weights.

  5. Question 5

    Advanced

    PyTorch Fundamentals · Tensor creation and operations

    A computer vision model requires blending a feature map tensor A with a per-channel bias tensor B. Tensor A has the shape (16, 3, 256, 256) representing (batch, channels, height, width). Tensor B has the shape (3, 1, 1). When the operation C = A + B is executed, what will be the resulting shape of tensor C based on PyTorch broadcasting semantics?

    Answer and explanation

    Correct answer: A

    According to PyTorch broadcasting rules, dimensions are aligned from right to left. B's shape (3, 1, 1) aligns with the last three dimensions of A (3, 256, 256). Since dimensions of size 1 can be broadcast to match the other tensor, and missing leading dimensions (the batch dimension 16) are implicitly assumed to be 1, the operation broadcasts successfully resulting in the maximum size along each dimension: (16, 3, 256, 256).

    flowchart LR A["Tensor A: (16, 3, 256, 256)"] --> Ops(+) B["Tensor B: ( 1, 3, 1, 1)"] --> Ops Ops --> C["Result C: (16, 3, 256, 256)"]
  6. Question 6

    Beginner

    PyTorch Fundamentals · PyTorch core concepts and workflow

    To compute the gradients of the loss with respect to all tensors in the computation graph that have requires_grad=True, you must call the ________ method on the final loss tensor.

    Answer and explanation

    Correct answer: A

    The backward() method is called on the scalar loss tensor to traverse the computation graph backwards, computing the gradient of the loss with respect to all leaf tensors that have requires_grad=True.

Register free for 6 more questions

Or unlock all 150 PTCA questions with explanations, timed mode and flashcards.