forward function of this executor. Notice this one will store and compute gradient. Args: inputs (Union[dict, list, torch.Tensor]): [input tensor or somewhat] output_names (List[str], optional): onnx output node names, which used to confi
(
self,
inputs: Union[dict, list, torch.Tensor],
output_names:List[str] = None,
hooks: Dict[str, RuntimeHook] = None,
)
| 410 | ) |
| 411 | |
| 412 | def forward_with_gradient( |
| 413 | self, |
| 414 | inputs: Union[dict, list, torch.Tensor], |
| 415 | output_names:List[str] = None, |
| 416 | hooks: Dict[str, RuntimeHook] = None, |
| 417 | ) -> List[torch.Tensor]: |
| 418 | """forward function of this executor. |
| 419 | |
| 420 | Notice this one will store and compute gradient. |
| 421 | |
| 422 | Args: |
| 423 | inputs (Union[dict, list, torch.Tensor]): [input tensor or somewhat] |
| 424 | output_names (List[str], optional): |
| 425 | onnx output node names, which used to confirm a output order. |
| 426 | |
| 427 | Defaults to None. |
| 428 | |
| 429 | hooks (Dict[str, RuntimeHook], optional): |
| 430 | A hook table for customizing operation behaviour and collate data during executing. |
| 431 | All hooks should inherit from class RuntimeHook, with all necessary methods implemented. |
| 432 | See also: ppq.executor.base.RuntimeHook |
| 433 | |
| 434 | Executor calls hook.pre_forward_hook(operation, input_data) before dispatching operation, |
| 435 | by using this feature, you can dynamically dispatch operation during executing, |
| 436 | or processing input data as you want.(remember to return processed input data) |
| 437 | |
| 438 | Executor calls hook.post_forward_hook(operation, output_data) after the execution, |
| 439 | you are supposed to gather all necessary data from execution via this feature. |
| 440 | |
| 441 | For Quantable Operation, a much more powerful class: |
| 442 | ppq.executor.base.QuantOpRuntimeHook is provided. |
| 443 | see also: ppq.executor.base.QuantOpRuntimeHook |
| 444 | |
| 445 | Defaults to None. |
| 446 | |
| 447 | Returns: |
| 448 | List[torch.Tensor]: [executing result, list of tensor objects.] |
| 449 | """ |
| 450 | return self.__forward( |
| 451 | inputs=inputs, |
| 452 | output_names=output_names, |
| 453 | executing_order=self._executing_order, |
| 454 | hooks=hooks |
| 455 | ) |
| 456 | |
| 457 | def __forward( |
| 458 | self, |