Shortcuts

pytorch_lightning.core.saving module

class pytorch_lightning.core.saving.ModelIO[source]

Bases: object

on_hpc_load(checkpoint)[source]

Hook to do whatever you need right before Slurm manager loads the model.

Parameters

checkpoint (Dict[str, Any]) – A dictionary with variables from the checkpoint.

Return type

None

on_hpc_save(checkpoint)[source]

Hook to do whatever you need right before Slurm manager saves the model.

Parameters

checkpoint (Dict[str, Any]) – A dictionary in which you can save variables to save in a checkpoint. Contents need to be pickleable.

Return type

None

on_load_checkpoint(checkpoint)[source]

Do something with the checkpoint. Gives model a chance to load something before state_dict is restored.

Parameters

checkpoint (Dict[str, Any]) – A dictionary with variables from the checkpoint.

Return type

None

on_save_checkpoint(checkpoint)[source]

Give the model a chance to add something to the checkpoint. state_dict is already there.

Parameters

checkpoint (Dict[str, Any]) – A dictionary in which you can save variables to save in a checkpoint. Contents need to be pickleable.

Return type

None

pytorch_lightning.core.saving.convert(val)[source]
Return type

Union[int, float, bool, str]

pytorch_lightning.core.saving.load_hparams_from_tags_csv(tags_csv)[source]

Load hparams from a file.

>>> hparams = Namespace(batch_size=32, learning_rate=0.001, data_root='./any/path/here')
>>> path_csv = './testing-hparams.csv'
>>> save_hparams_to_tags_csv(path_csv, hparams)
>>> hparams_new = load_hparams_from_tags_csv(path_csv)
>>> vars(hparams) == hparams_new
True
>>> os.remove(path_csv)
Return type

Dict[str, Any]

pytorch_lightning.core.saving.load_hparams_from_yaml(config_yaml)[source]

Load hparams from a file.

>>> hparams = Namespace(batch_size=32, learning_rate=0.001, data_root='./any/path/here')
>>> path_yaml = './testing-hparams.yaml'
>>> save_hparams_to_yaml(path_yaml, hparams)
>>> hparams_new = load_hparams_from_yaml(path_yaml)
>>> vars(hparams) == hparams_new
True
>>> os.remove(path_yaml)
Return type

Dict[str, Any]

pytorch_lightning.core.saving.save_hparams_to_tags_csv(tags_csv, hparams)[source]
Return type

None

pytorch_lightning.core.saving.save_hparams_to_yaml(config_yaml, hparams)[source]
Return type

None

pytorch_lightning.core.saving.update_hparams(hparams, updates)[source]

Overrides hparams with new values

>>> hparams = {'c': 4}
>>> update_hparams(hparams, {'a': {'b': 2}, 'c': 1})
>>> hparams['a']['b'], hparams['c']
(2, 1)
>>> update_hparams(hparams, {'a': {'b': 4}, 'c': 7})
>>> hparams['a']['b'], hparams['c']
(4, 7)
Parameters
  • hparams (dict) – the original params and also target object

  • updates (dict) – new params to be used as update

Return type

None