Not really familiar with Lua Torch, but the error seems to be coming from using inplace operations like .div_ on Variables. You could try replacing those with their counterparts, like .div and checking if it fixes your code.
From the docs:

Supporting in-place operations in autograd is a hard matter, and we discourage their use in most cases.

You can read more about it here: Autograd mechanics 3