Args: config (DictConfig): A OmegaConf config (e.g. produced by hydra yaml config file parsing) Returns: The model that you can directly use to train with pytorch-lightning
(config: DictConfig, **kwargs)
| 15 | |
| 16 | |
| 17 | def get_model(config: DictConfig, **kwargs) -> BaseModel: |
| 18 | """ |
| 19 | Args: |
| 20 | config (DictConfig): A OmegaConf config (e.g. produced by hydra yaml config file parsing) |
| 21 | Returns: |
| 22 | The model that you can directly use to train with pytorch-lightning |
| 23 | """ |
| 24 | if config.get('normalizer'): |
| 25 | # This can be a bit redundant with get_datamodule (normalizer is instantiated twice), but it is better to be |
| 26 | # sure that the output_normalizer is used by the model in cases where pytorch-lightning is not used. |
| 27 | # By default if you use pytorch-lightning, the correct output_normalizer is passed to the model before training, |
| 28 | # even without the below |
| 29 | normalizer: Normalizer = hydra.utils.instantiate( |
| 30 | config.normalizer, _recursive_=False, |
| 31 | datamodule_config=config.datamodule, |
| 32 | ) |
| 33 | kwargs['output_normalizer'] = normalizer.output_normalizer |
| 34 | model: BaseModel = hydra.utils.instantiate( |
| 35 | config.model, _recursive_=False, |
| 36 | datamodule_config=config.datamodule, |
| 37 | **kwargs |
| 38 | ) |
| 39 | return model |
| 40 | |
| 41 | |
| 42 | def get_datamodule(config: DictConfig) -> ClimartDataModule: |
no outgoing calls
no test coverage detected