def test_sanitize_callable_params(): """Callback function are not serializiable. Therefore, we get them a chance to return something and if the returned type is not accepted, return None. """ opt = "--max_epochs 1".split(" ") parser = ArgumentParser() parser = Trainer.add_argparse_args(parent_parser=parser) params = parser.parse_args(opt) def return_something(): return "something" params.something = return_something def wrapper_something(): return return_something params.wrapper_something_wo_name = lambda: lambda: "1" params.wrapper_something = wrapper_something params = _convert_params(params) params = _flatten_dict(params) params = _sanitize_callable_params(params) assert params["gpus"] == "None" assert params["something"] == "something" assert params["wrapper_something"] == "wrapper_something" assert params["wrapper_something_wo_name"] == "<lambda>"
def log_hyperparams( self, params: Union[Dict[str, Any], Namespace]) -> None: # skipcq: PYL-W0221 r""" Log hyper-parameters to the run. Hyperparams will be logged under the "<prefix>/hyperparams" namespace. Note: You can also log parameters by directly using the logger instance: ``neptune_logger.experiment["model/hyper-parameters"] = params_dict``. In this way you can keep hierarchical structure of the parameters. Args: params: `dict`. Python dictionary structure with parameters. Example:: from pytorch_lightning.loggers import NeptuneLogger PARAMS = { "batch_size": 64, "lr": 0.07, "decay_factor": 0.97 } neptune_logger = NeptuneLogger( api_key="ANONYMOUS", project="common/pytorch-lightning-integration" ) neptune_logger.log_hyperparams(PARAMS) """ params = _convert_params(params) params = _sanitize_callable_params(params) parameters_key = self.PARAMETERS_KEY parameters_key = self._construct_path_with_prefix(parameters_key) self.run[parameters_key] = params
def log_hyperparams(self, params: Union[Dict[str, Any], Namespace]) -> None: params = _convert_params(params) params = _flatten_dict(params) params = _sanitize_callable_params(params) self.experiment.config.update(params, allow_val_change=True)