MCPcopy Create free account
hub / github.com/TencentARC/AnimeGamer / backward

Method backward

VDM_Decoder/vae_modules/utils.py:389–406  ·  view source on GitHub ↗
(ctx, *output_grads)

Source from the content-addressed store, hash-verified

387
388 @staticmethod
389 def backward(ctx, *output_grads):
390 ctx.input_tensors = [x.detach().requires_grad_(True) for x in ctx.input_tensors]
391 with torch.enable_grad(), torch.cuda.amp.autocast(**ctx.gpu_autocast_kwargs):
392 # Fixes a bug where the first op in run_function modifies the
393 # Tensor storage in place, which is not allowed for detach()'d
394 # Tensors.
395 shallow_copies = [x.view_as(x) for x in ctx.input_tensors]
396 output_tensors = ctx.run_function(*shallow_copies)
397 input_grads = torch.autograd.grad(
398 output_tensors,
399 ctx.input_tensors + ctx.input_params,
400 output_grads,
401 allow_unused=True,
402 )
403 del ctx.input_tensors
404 del ctx.input_params
405 del output_tensors
406 return (None, None) + input_grads

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected