Unable to update a latent vector using custom loss function

Typically how you debug these situations is to bisect your model and figure out where the model is first disconnected.

From reading your code, it looks like z_latent_vect is the output of an operation in no-grad mode, which means it will have requires_grad=False. Does making that requires_grad=True fix things.

(also you shouldn’t use “Variable”, it’s deprecated - the equivalent code here is .requires_grad_(True)).