問題文
A developer needs a tensor that has the same values as an existing tensor but is excluded from gradient tracking, and they must not modify the original. Which expression is appropriate?
選択肢
- torch.no_grad(x), which marks the tensor as excluded from every graph built after that point.
- x.item(), which strips the graph information while keeping the tensor usable in later arithmetic.
- x.requires_grad_(False), which is the documented way to obtain a detached copy while leaving the original tensor untouched for the rest of the program.
- x.detach(), which returns a tensor sharing the data but detached from the graph.