Learn Before
Concept
Targeted Parameter Access in PyTorch
In PyTorch, the underlying numerical values of a parameter object can be explicitly accessed using the .data attribute. Additionally, the gradients associated with the parameter can be retrieved using the .grad attribute. For example, net[2].bias.data extracts the numerical value of the bias from a specific layer, while net[2].weight.grad accesses the gradient of its weights.
0
1
Updated 2026-05-08
Tags
D2L
Dive into Deep Learning @ D2L