Use torch.optim to optimize a stats learning objective

Hey guys, so I am trying to optimize a stats learning model but not nn object, or put it in this way: can pytorch optimize any objective function with respect to its parameters? e.g.

x = torch.randn(500)
obj = x.T@x + torch.log(torch.abs(x)).sum + x[0]

Now can I optimize obj with respect to x? Bother giving an example? Thanks.