(
self, graph: BaseGraph,
dataloader: Iterable, executor: BaseGraphExecutor,
collate_fn: Callable, **kwargs)
| 826 | return pre_loss, post_loss |
| 827 | |
| 828 | def optimize( |
| 829 | self, graph: BaseGraph, |
| 830 | dataloader: Iterable, executor: BaseGraphExecutor, |
| 831 | collate_fn: Callable, **kwargs) -> None: |
| 832 | |
| 833 | blocks = self.split_graph_into_blocks( |
| 834 | graph=graph, executing_order=executor._executing_order, |
| 835 | blocksize=self.block_size, interested_layers=self.interested_layers) |
| 836 | |
| 837 | # ready for finetuning, print information. |
| 838 | print('') |
| 839 | print('Check following parameters:') |
| 840 | print(f'Is Scale Trainable: {self.is_scale_trainable}') |
| 841 | print(f'Interested Layers: {self.interested_layers}') |
| 842 | print(f'Collecting Device: {self.collecting_device}') |
| 843 | print(f'Num of blocks: {len(blocks)}') |
| 844 | print(f'Learning Rate: {self.lr}') |
| 845 | print(f'Steps: {self.steps}') |
| 846 | print(f'Gamma: {self.gamma}') |
| 847 | print('') # blank line |
| 848 | |
| 849 | # do per-block finetune |
| 850 | for block_idx, block in enumerate(blocks): |
| 851 | # collect data for training |
| 852 | qt_inputs, fp_outputs = self.collect( |
| 853 | graph=graph, block=block, executor=executor, |
| 854 | dataloader=dataloader, collate_fn=collate_fn, |
| 855 | collecting_device=self.collecting_device) |
| 856 | |
| 857 | print(f'# Block [{block_idx + 1} / {len(blocks)}]: ' |
| 858 | f'[{block.sp.name} -> {block.ep.name}]') |
| 859 | pre_loss, post_loss = self.finetune( |
| 860 | steps=self.steps, learning_rate=self.lr, block=block, |
| 861 | qt_inputs=qt_inputs, fp_outputs=fp_outputs, executor=executor) |
| 862 | print(f'# Tuning Finished : ({pre_loss:.4f} -> {min(pre_loss, post_loss):.4f}) [Block Loss]') |
| 863 | print('') # blank line |
nothing calls this directly
no test coverage detected