How Could I Fix This Torch. Zero() Problem?

How Could I Fix This Torch. Zero() Problem?

I'm trying to write a Logistic Regression by myself, but I found an error while initializing this torch.zero().

code:

w = torch.normal(0, 0.01, size=(2,1), requires_grad=True)
b = torch.zeros(1,require_grad=True) # Error occured here

Error message:

Traceback (most recent call last):
  File "linearRegression.py", line 37, in <module>
    b = torch.zeros(1,require_grad=True)
TypeError: zeros() received an invalid combination of arguments - got (int, require_grad=bool), but expected one of:
 * (tuple of ints size, *, tuple of names names, torch.dtype dtype, torch.layout layout, torch.device device, bool pin_memory, bool requires_grad)
 * (tuple of ints size, *, Tensor out, torch.dtype dtype, torch.layout layout, torch.device device, bool pin_memory, bool requires_grad)

1 Answer

You have a typo, change require_grad to requires_grad.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Sarah Jenkins
Author

Sarah Jenkins

Sarah Jenkins is a veteran tech journalist with over 12 years of experience covering artificial intelligence, mobile innovations, and digital ethics. Her insights have appeared in leading technology publications worldwide.