cerebras.modelzoo.common.pytorch_utils.visit_structure#

cerebras.modelzoo.common.pytorch_utils.visit_structure(data_structure, select_fn, strict=False, scope=None)[source]#

Recursively traverse nested structure and return the items accepted by the selector.

Parameters
  • data_structure (Union[Any, list, tuple, dict]) – A nested data structure to traverse recursively.

  • select_fn (Callable[[Any], bool]) – A callable that returns true if the item passed should be selected.

  • strict (bool) – Strictly checks that an item in the nested structure is either a list/dict/tuple or selected by the select_fn. Otherwise, raises an error. Defaults to False.

  • scope (Optional[List[str]]) – The current hierarchical scope of the data structure. Defaults to None.

Yields

A tuples of (scope, item) for each item selected by the select_fn.