torch.nn.Parameter(data=None, requires_grad=True)
Paddle 无此 API,需要组合实现。
# PyTorch 写法 y = torch.nn.Parameter(data=x, requires_grad=requires_grad) # Paddle 写法 y = paddle.create_parameter(shape=x.shape, dtype=x.dtype, default_initializer=paddle.nn.initializer.Assign(x)) y.stop_gradient = not requires_grad