(
self,
graph: BaseGraph,
dataloader: Iterable,
executor: BaseGraphExecutor,
collate_fn: Callable,
**kwargs
)
| 529 | |
| 530 | @ empty_ppq_cache |
| 531 | def optimize( |
| 532 | self, |
| 533 | graph: BaseGraph, |
| 534 | dataloader: Iterable, |
| 535 | executor: BaseGraphExecutor, |
| 536 | collate_fn: Callable, |
| 537 | **kwargs |
| 538 | ) -> None: |
| 539 | |
| 540 | blocks = self.split_graph_into_blocks( |
| 541 | graph=graph, executing_order=executor._executing_order, |
| 542 | blocksize=self.block_size, interested_layers=self.interested_layers) |
| 543 | |
| 544 | # ready for finetuning, print information. |
| 545 | print('') |
| 546 | print('Check following parameters:') |
| 547 | print(f'Interested Layers: {self.interested_layers}') |
| 548 | print(f'Num of blocks: {len(blocks)}') |
| 549 | print(f'Steps: {self.steps}') |
| 550 | print(f'collecting_device: {self.collecting_device}') |
| 551 | print('') # blank line |
| 552 | |
| 553 | # do per-block finetune |
| 554 | for block_idx, block in enumerate(blocks): |
| 555 | qt_inputs, fp_outputs = self.collect( |
| 556 | graph=graph, block=block, executor=executor, |
| 557 | dataloader=dataloader, collate_fn=collate_fn, |
| 558 | collecting_device=self.collecting_device) |
| 559 | |
| 560 | print(f'# Block [{block_idx + 1} / {len(blocks)}]: ' |
| 561 | f'[{block.sp.name} -> {block.ep.name}]') |
| 562 | pre_loss, post_loss = self.correct_bias( |
| 563 | qt_inputs=qt_inputs, fp_outputs=fp_outputs, |
| 564 | block=block, executor=executor, graph=graph) |
| 565 | print(f'# Tuning Finished : ({pre_loss:.4f} -> {min(pre_loss, post_loss):.4f}) [Block Loss]') |
| 566 | print('') # blank line |
| 567 | |
| 568 | |
| 569 | class LearnedStepSizePass(TrainingBasedPass): |
nothing calls this directly
no test coverage detected