(self, *args, **kwargs)
| 516 | keep_tensors=False): |
| 517 | |
| 518 | def _forward(self, *args, **kwargs): |
| 519 | ret = self.forward_origin(*args, **kwargs) |
| 520 | if keep_tensors: |
| 521 | args = numpify_tensor_nested(detach_tensor_nested(args)) |
| 522 | kwargs = numpify_tensor_nested(detach_tensor_nested(kwargs)) |
| 523 | output = numpify_tensor_nested(detach_tensor_nested(ret)) |
| 524 | else: |
| 525 | args = { |
| 526 | 'sum': |
| 527 | numpify_tensor_nested( |
| 528 | detach_tensor_nested(args), reduction='sum'), |
| 529 | 'mean': |
| 530 | numpify_tensor_nested( |
| 531 | detach_tensor_nested(args), reduction='mean'), |
| 532 | } |
| 533 | kwargs = { |
| 534 | 'sum': |
| 535 | numpify_tensor_nested( |
| 536 | detach_tensor_nested(kwargs), reduction='sum'), |
| 537 | 'mean': |
| 538 | numpify_tensor_nested( |
| 539 | detach_tensor_nested(kwargs), reduction='mean'), |
| 540 | } |
| 541 | output = { |
| 542 | 'sum': |
| 543 | numpify_tensor_nested( |
| 544 | detach_tensor_nested(ret), reduction='sum'), |
| 545 | 'mean': |
| 546 | numpify_tensor_nested( |
| 547 | detach_tensor_nested(ret), reduction='mean'), |
| 548 | } |
| 549 | |
| 550 | io_json[name] = { |
| 551 | 'input': { |
| 552 | 'args': args, |
| 553 | 'kwargs': kwargs, |
| 554 | }, |
| 555 | 'output': output, |
| 556 | } |
| 557 | return ret |
| 558 | |
| 559 | if not restore and not hasattr(module, 'forward_origin'): |
| 560 | module.forward_origin, module.forward = module.forward, type( |
nothing calls this directly
no test coverage detected
searching dependent graphs…