The error comes from the fact that a values that ia needed to compute gradients has been changed inplace.
By looking quickly at your code, you might want to change style_loss += xxx by style_loss = style_loss + xxx. The first one is inplace, the second one is not.