parsing — PyTorch Lightning 2.5.1.post0 documentation (original) (raw)

Functions

clean_namespace Removes all unpicklable entries from hparams.
collect_init_args Recursively collects the arguments passed to the child constructors in the inheritance tree.
get_init_args For backwards compatibility: #16369.
is_picklable Tests if an object can be pickled.
lightning_getattr Special getattr for Lightning.
lightning_hasattr Special hasattr for Lightning.
lightning_setattr Special setattr for Lightning.
parse_class_init_keys Parse key words for standard self, *args and **kwargs.
save_hyperparameters See save_hyperparameters()

Classes

AttributeDict Extended dictionary accessible with dot notation.

Utilities used for parameter parsing.

class lightning.pytorch.utilities.parsing.AttributeDict[source]

Bases: AttributeDict

Extended dictionary accessible with dot notation.

ad = AttributeDict({'key1': 1, 'key2': 'abc'}) ad.key1 1 ad.update({'my-key': 3.14}) ad.update(new_key=42) ad.key1 = 2 ad "key1": 2 "key2": abc "my-key": 3.14 "new_key": 42

lightning.pytorch.utilities.parsing.clean_namespace(hparams)[source]

Removes all unpicklable entries from hparams.

Return type:

None

lightning.pytorch.utilities.parsing.collect_init_args(frame, path_args, inside=False, classes=())[source]

Recursively collects the arguments passed to the child constructors in the inheritance tree.

Parameters:

Return type:

list[dict[str, Any]]

Returns:

A list of dictionaries where each dictionary contains the arguments passed to the constructor at that level. The last entry corresponds to the constructor call of the most specific class in the hierarchy.

lightning.pytorch.utilities.parsing.get_init_args(frame)[source]

For backwards compatibility: #16369.

Return type:

dict[str, Any]

lightning.pytorch.utilities.parsing.is_picklable(obj)[source]

Tests if an object can be pickled.

Return type:

bool

lightning.pytorch.utilities.parsing.lightning_getattr(model, attribute)[source]

Special getattr for Lightning. Checks for attribute in model namespace, the old hparams namespace/dict, and the datamodule.

Raises:

AttributeError – If model doesn’t have attribute in any of model namespace, the hparams namespace/dict, and the datamodule.

Return type:

Optional[Any]

lightning.pytorch.utilities.parsing.lightning_hasattr(model, attribute)[source]

Special hasattr for Lightning.

Checks for attribute in model namespace, the old hparams namespace/dict, and the datamodule.

Return type:

bool

lightning.pytorch.utilities.parsing.lightning_setattr(model, attribute, value)[source]

Special setattr for Lightning. Checks for attribute in model namespace and the old hparams namespace/dict. Will also set the attribute on datamodule, if it exists.

Raises:

AttributeError – If model doesn’t have attribute in any of model namespace, the hparams namespace/dict, and the datamodule.

Return type:

None

lightning.pytorch.utilities.parsing.parse_class_init_keys(cls)[source]

Parse key words for standard self, *args and **kwargs.

Return type:

tuple[str, Optional[str], Optional[str]]

Examples

class Model: ... def init(self, hparams, *my_args, anykw=42, **my_kwargs): ... pass parse_class_init_keys(Model) ('self', 'my_args', 'my_kwargs')

lightning.pytorch.utilities.parsing.save_hyperparameters(obj, *args, ignore=None, frame=None, given_hparams=None)[source]

See save_hyperparameters()

Return type:

None