MCPcopy Create free account
hub / github.com/MegaScenes/nvs / backward

Method backward

ldm/modules/diffusionmodules/util.py:131–148  ·  view source on GitHub ↗
(ctx, *output_grads)

Source from the content-addressed store, hash-verified

129
130 @staticmethod
131 def backward(ctx, *output_grads):
132 ctx.input_tensors = [x.detach().requires_grad_(True) for x in ctx.input_tensors]
133 with torch.enable_grad():
134 # Fixes a bug where the first op in run_function modifies the
135 # Tensor storage in place, which is not allowed for detach()'d
136 # Tensors.
137 shallow_copies = [x.view_as(x) for x in ctx.input_tensors]
138 output_tensors = ctx.run_function(*shallow_copies)
139 input_grads = torch.autograd.grad(
140 output_tensors,
141 ctx.input_tensors + ctx.input_params,
142 output_grads,
143 allow_unused=True,
144 )
145 del ctx.input_tensors
146 del ctx.input_params
147 del output_tensors
148 return (None, None) + input_grads
149
150
151def timestep_embedding(timesteps, dim, max_period=10000, repeat_only=False):

Callers 1

mainFunction · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected