PTCA PyTorch Certified Associate (PTCA) Practice Questions
Prepare for PTCA with more than an answer.
- Exam fee
- $250 USD
- Time limit
- 120 minutes
- Passing score
- 75%
- Level
- Associate
- Valid for
- 2 years
Domains covered on the exam 4
- PyTorch Fundamentals38%
- Model Development20%
- Performance & Optimization26%
- Data Handling16%
- 1
When deploying a PyTorch model into a high-performance production environment for pure inference, which context manager provides the absolute maximum performance optimization by explicitly disabling view tracking and version counter tracking in addition to gradient tracking?
Show answer details
Correct answer: C
While torch.no_grad() disables gradient calculation, torch.inference_mode() is a newer context manager specifically designed for pure inference. It goes further by bypassing version tracking and view tracking entirely, resulting in slightly better performance and reduced memory overhead. Tensors created in this mode cannot be used in computations that will later require gradients.
- 2
A systems engineer is optimizing memory usage in a PyTorch script running on edge devices. They notice multiple tensor math operations creating new intermediate tensors. Which PyTorch syntax convention indicates that a tensor operation will be performed in-place, directly modifying the original tensor to save memory?
Show answer details
Correct answer: C
In PyTorch, operations that mutate a tensor in-place are denoted by a trailing underscore (e.g.,
tensor.add_(x),tensor.zero_()). These operations overwrite the existing tensor's memory instead of allocating a new tensor for the result. Note that in-place operations can sometimes break the autograd graph if the original values are needed for backpropagation. - 3
An AI researcher is implementing a complex Generative Adversarial Network (GAN). During one iteration, they need to backpropagate through the same computation graph twice to calculate two distinct loss penalties sequentially. When calling
loss1.backward(), what specific argument must be provided to prevent PyTorch from freeing the computation graph buffers?Show answer details
Correct answer: B
By default, PyTorch frees the memory of the dynamically created computation graph immediately after
backward()is called to save memory. If you need to perform multiple backward passes through the same graph (e.g., complex GANs or meta-learning), you must passretain_graph=Trueto the firstbackward()call. - 4
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?
Show answer details
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.
- 5
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?
Show answer details
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.
- 6
True or False: Calling
model.eval()automatically disables gradient computation during the forward pass, effectively acting as a substitute fortorch.no_grad()during inference.Show answer details
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 thetorch.no_grad()ortorch.inference_mode()context managers to disable gradient computation and save memory.
