required_grad is an attribute of tensor, so you should use it as e.g.:
x = torch.tensor([1., 2., 3.], requires_grad=True)

x = torch.randn(1, requires_grad=True)

x = torch.randn(1)
x.requires_grad_(True)