MCPcopy Create free account
hub / github.com/OpenDriveLab/ReSim / forward

Method forward

SwissArmyTransformer/sat/quantization/kernels.py:49–58  ·  view source on GitHub ↗
(ctx, inp: torch.Tensor, quant_w: torch.Tensor, scale_w: torch.Tensor, weight_bit_width)

Source from the content-addressed store, hash-verified

47class W8A16Linear(torch.autograd.Function):
48 @staticmethod
49 def forward(ctx, inp: torch.Tensor, quant_w: torch.Tensor, scale_w: torch.Tensor, weight_bit_width):
50 ctx.inp_shape = inp.size()
51 ctx.weight_bit_width = weight_bit_width
52 out_features = quant_w.size(0)
53 inp = inp.contiguous().view(-1, inp.size(-1))
54 weight = extract_weight_to_half(quant_w, scale_w, weight_bit_width)
55 ctx.weight_shape = weight.size()
56 output = inp.mm(weight.t())
57 ctx.save_for_backward(inp, quant_w, scale_w)
58 return output.view(*(ctx.inp_shape[:-1] + (out_features,)))
59
60 @staticmethod
61 def backward(ctx, grad_output: torch.Tensor):

Callers

nothing calls this directly

Calls 1

extract_weight_to_halfFunction · 0.85

Tested by

no test coverage detected