| 22 | cache = {'i': 0, 'attention_mask': None} |
| 23 | |
| 24 | class Catcher(nn.Module): |
| 25 | |
| 26 | def __init__(self, module): |
| 27 | super().__init__() |
| 28 | self.module = module |
| 29 | |
| 30 | def forward(self, inp, **kwargs): |
| 31 | inps[cache['i']] = inp |
| 32 | cache['i'] += 1 |
| 33 | cache['attention_mask'] = kwargs['attention_mask'] |
| 34 | cache['position_ids'] = kwargs['position_ids'] |
| 35 | raise ValueError |
| 36 | |
| 37 | layers[0] = Catcher(layers[0]) |
| 38 | for i in range(nsamples): |