MCPcopy Create free account
hub / github.com/boyiwei/alignment-attribution-code / add_batch

Method add_batch

lib/sparsegpt.py:28–41  ·  view source on GitHub ↗
(self, inp, out)

Source from the content-addressed store, hash-verified

26 self.nsamples = 0
27
28 def add_batch(self, inp, out):
29 if len(inp.shape) == 2:
30 inp = inp.unsqueeze(0)
31 tmp = inp.shape[0]
32 if isinstance(self.layer, nn.Linear) or isinstance(
33 self.layer, transformers.Conv1D
34 ):
35 if len(inp.shape) == 3:
36 inp = inp.reshape((-1, inp.shape[-1]))
37 inp = inp.t()
38 self.H *= self.nsamples / (self.nsamples + tmp)
39 self.nsamples += tmp
40 inp = math.sqrt(2 / self.nsamples) * inp.float()
41 self.H += inp.matmul(inp.t())
42
43 def fasterprune(self, sparsity, prune_n=0, prune_m=0, blocksize=128, percdamp=0.01):
44 W = self.layer.weight.data.clone()

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected