Question 1
BeginnerPyTorch 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.
