| 61 | cache = {'i': 0, 'attention_mask': None} |
| 62 | |
| 63 | class Catcher(nn.Module): |
| 64 | |
| 65 | def __init__(self, module): |
| 66 | super().__init__() |
| 67 | self.module = module |
| 68 | |
| 69 | def forward(self, inp, **kwargs): |
| 70 | inps[cache['i']] = inp |
| 71 | cache['i'] += 1 |
| 72 | cache['attention_mask'] = kwargs['attention_mask'] |
| 73 | cache['position_ids'] = kwargs['position_ids'] |
| 74 | raise ValueError |
| 75 | |
| 76 | layers[0] = Catcher(layers[0]) |
| 77 | for i in range(nsamples): |