cerebras.modelzoo.common.pytorch_utils.visit_structure#

cerebras.modelzoo.common.pytorch_utils.visit_structure(data_structure: Union[Any, list, tuple, dict], select_fn: Callable[[Any], bool], strict: bool = False, scope: Optional[List[str]] = None) Generator[Tuple[List[str], Any], None, None][source]#

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

Parameters
  • data_structure – A nested data structure to traverse recursively.

  • select_fn – A callable that returns true if the item passed should be selected.

  • strict – 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 – 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.