MCPcopy Create free account
hub / github.com/Vchitect/Latte / backward

Method backward

models/utils.py:54–71  ·  view source on GitHub ↗
(ctx, *output_grads)

Source from the content-addressed store, hash-verified

52
53 @staticmethod
54 def backward(ctx, *output_grads):
55 ctx.input_tensors = [x.detach().requires_grad_(True) for x in ctx.input_tensors]
56 with torch.enable_grad():
57 # Fixes a bug where the first op in run_function modifies the
58 # Tensor storage in place, which is not allowed for detach()'d
59 # Tensors.
60 shallow_copies = [x.view_as(x) for x in ctx.input_tensors]
61 output_tensors = ctx.run_function(*shallow_copies)
62 input_grads = torch.autograd.grad(
63 output_tensors,
64 ctx.input_tensors + ctx.input_params,
65 output_grads,
66 allow_unused=True,
67 )
68 del ctx.input_tensors
69 del ctx.input_params
70 del output_tensors
71 return (None, None) + input_grads
72
73
74def timestep_embedding(timesteps, dim, max_period=10000, repeat_only=False):

Callers 2

mainFunction · 0.45
mainFunction · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected