MCPcopy Create free account
hub / github.com/Pints-AI/1.5-Pints / backward

Method backward

lit_gpt/rmsnorm.py:374–413  ·  view source on GitHub ↗
(ctx, dz, *args)

Source from the content-addressed store, hash-verified

372
373 @staticmethod
374 def backward(ctx, dz, *args):
375 # assert dz.is_contiguous()
376 dz = maybe_align(dz.contiguous(), 16) # this happens!
377 dx = maybe_align(args[0].contiguous(), 16) if ctx.prenorm else None
378 x, x0, dmask, gamma, mu, rsigma, rowscale, colscale = ctx.saved_tensors
379 # x0 is None if colscale is None
380 dropout_p = ctx.dropout_p
381 has_residual = ctx.has_residual
382 dx0mat, dresidualmat, dgamma, dbeta, *rest = _dropout_add_layer_norm_backward(
383 dz,
384 dx,
385 x,
386 x0,
387 dmask,
388 mu,
389 rsigma,
390 gamma,
391 rowscale,
392 colscale,
393 dropout_p,
394 has_residual,
395 ctx.is_rms_norm,
396 )
397 dx0 = dx0mat.view(x.shape)
398 dresidual = dresidualmat.view(x.shape) if dresidualmat is not None else None
399 dcolscale = rest[0] if colscale is not None else None
400 return (
401 dx0,
402 dresidual,
403 dgamma,
404 dbeta if ctx.has_beta else None,
405 None,
406 dcolscale,
407 None,
408 None,
409 None,
410 None,
411 None,
412 None,
413 )
414
415
416class DropoutAddLayerNormSubsetFn(torch.autograd.Function):

Callers 3

measure_flopsFunction · 0.45
fitFunction · 0.45
trainFunction · 0.45

Calls 2

maybe_alignFunction · 0.85

Tested by

no test coverage detected