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.

flatten_dict

rtype

Dict[str, Any]

get_init_args

rtype

Dict[str, Any]

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()

str_to_bool

Convert a string representation of truth to bool.

str_to_bool_or_int

Convert a string representation to truth of bool if possible, or otherwise try to convert it to an int.

str_to_bool_or_str

Possibly convert a string representation of truth to bool.

Classes

AttributeDict

Extended dictionary accessible with dot notation.

Utilities used for parameter parsing.

class pytorch_lightning.utilities.parsing.AttributeDict[source]

Bases: 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
pytorch_lightning.utilities.parsing.clean_namespace(hparams)[source]

Removes all unpicklable entries from hparams.

Return type

None

pytorch_lightning.utilities.parsing.collect_init_args(frame, path_args, inside=False)[source]

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

Parameters
  • 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

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.

pytorch_lightning.utilities.parsing.is_picklable(obj)[source]

Tests if an object can be pickled.

Return type

bool

pytorch_lightning.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]

pytorch_lightning.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

pytorch_lightning.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

pytorch_lightning.utilities.parsing.parse_class_init_keys(cls)[source]

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

Examples

>>> class Model():
...     def __init__(self, hparams, *my_args, anykw=42, **my_kwargs):
...         pass
>>> parse_class_init_keys(Model)
('self', 'my_args', 'my_kwargs')
Return type

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

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

See save_hyperparameters()

Return type

None

pytorch_lightning.utilities.parsing.str_to_bool(val)[source]

Convert a string representation of truth to bool.

True values are ‘y’, ‘yes’, ‘t’, ‘true’, ‘on’, and ‘1’; false values are ‘n’, ‘no’, ‘f’, ‘false’, ‘off’, and ‘0’.

Raises

ValueError – If val isn’t in one of the aforementioned true or false values.

>>> str_to_bool('YES')
True
>>> str_to_bool('FALSE')
False
Return type

bool

pytorch_lightning.utilities.parsing.str_to_bool_or_int(val)[source]

Convert a string representation to truth of bool if possible, or otherwise try to convert it to an int.

>>> str_to_bool_or_int("FALSE")
False
>>> str_to_bool_or_int("1")
True
>>> str_to_bool_or_int("2")
2
>>> str_to_bool_or_int("abc")
'abc'
Return type

Union[bool, int, str]

pytorch_lightning.utilities.parsing.str_to_bool_or_str(val)[source]

Possibly convert a string representation of truth to bool. Returns the input otherwise. Based on the python implementation distutils.utils.strtobool.

True values are ‘y’, ‘yes’, ‘t’, ‘true’, ‘on’, and ‘1’; false values are ‘n’, ‘no’, ‘f’, ‘false’, ‘off’, and ‘0’.

Return type

Union[str, bool]

Read the Docs v: latest
Versions
latest
stable
1.6.4
1.6.3
1.6.2
1.6.1
1.6.0
1.5.10
1.5.9
1.5.8
1.5.7
1.5.6
1.5.5
1.5.4
1.5.3
1.5.2
1.5.1
1.5.0
1.4.9
1.4.8
1.4.7
1.4.6
1.4.5
1.4.4
1.4.3
1.4.2
1.4.1
1.4.0
1.3.8
1.3.7
1.3.6
1.3.5
1.3.4
1.3.3
1.3.2
1.3.1
1.3.0
1.2.10
1.2.8
1.2.7
1.2.6
1.2.5
1.2.4
1.2.3
1.2.2
1.2.1
1.2.0
1.1.8
1.1.7
1.1.6
1.1.5
1.1.4
1.1.3
1.1.2
1.1.1
1.1.0
1.0.8
1.0.7
1.0.6
1.0.5
1.0.4
1.0.3
1.0.2
1.0.1
1.0.0
0.10.0
0.9.0
0.8.5
0.8.4
0.8.3
0.8.2
0.8.1
0.8.0
0.7.6
0.7.5
0.7.4
0.7.3
0.7.2
0.7.1
0.7.0
0.6.0
0.5.3
0.4.9
future-structure
Downloads
html
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.