Shortcuts

parsing

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[소스]

기반 클래스: Dict

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)[소스]

Removes all unpicklable entries from hparams.

반환 형식

None

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

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

매개변수
  • frame (frame) – the current stack frame

  • path_args (List[Dict[str, Any]]) – a list of dictionaries containing the constructor args in all parent classes

  • inside (bool) – track if we are inside inheritance path, avoid terminating too soon

  • classes (Tuple[Type, ...]) – the classes in which to inspect the frames

반환 형식

List[Dict[str, Any]]

반환

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)[소스]

For backwards compatibility: #16369.

반환 형식

Dict[str, Any]

lightning.pytorch.utilities.parsing.is_picklable(obj)[소스]

Tests if an object can be pickled.

반환 형식

bool

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

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

예외 발생

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

반환 형식

Optional[Any]

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

Special hasattr for Lightning.

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

반환 형식

bool

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

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.

예외 발생

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

반환 형식

None

lightning.pytorch.utilities.parsing.parse_class_init_keys(cls)[소스]

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

예제

>>> class Model:
...     def __init__(self, hparams, *my_args, anykw=42, **my_kwargs):
...         pass
>>> parse_class_init_keys(Model)
('self', 'my_args', 'my_kwargs')
반환 형식

Tuple[str, Optional[str], Optional[str]]

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

See save_hyperparameters()

반환 형식

None