| 689 | } |
| 690 | |
| 691 | def _initialize(self, prog, mode): |
| 692 | assert self.model._place is not None, ( |
| 693 | "device is not set, please call `model.prepare()` first" |
| 694 | ) |
| 695 | |
| 696 | place = self.model._place |
| 697 | |
| 698 | if self._executor is None: |
| 699 | self._executor = base.Executor(place) |
| 700 | self._executor.run(self._startup_prog) |
| 701 | |
| 702 | if ( |
| 703 | self._amp_level == "O2" |
| 704 | and mode == 'train' |
| 705 | and core.is_compiled_with_cuda() |
| 706 | ): |
| 707 | self.model._optimizer.amp_init(place) |
| 708 | |
| 709 | self._compiled_progs[mode] = prog |
| 710 | |
| 711 | |
| 712 | class StaticGraphAdapter: |