我是数据科学的初学者。我正在尝试使用自定义 autograd 函数来理解这个用于梯度计算的 PyTorch 代码:
class MyReLU(torch.autograd.Function):
@staticmethod
def forward(ctx, x):
ctx.save_for_backward(x)
return x.clamp(min=0)
def backward(ctx, grad_output):
x, = ctx.saved_tensors
grad_x = grad_output.clone()
grad_x[x < 0] = 0
return grad_x
但是,我不明白这一行:grad_x[x < 0] = 0
。谁能解释这部分?