MCPcopy Create free account
hub / github.com/apple/axlearn / flatten_items

Function flatten_items

axlearn/common/utils.py:421–429  ·  view source on GitHub ↗

Flattens `tree` and returns a list of (path, value) pairs.

(
    tree: Nested[Tensor], separator: str = "/", is_leaf: Optional[Callable[[Any], bool]] = None
)

Source from the content-addressed store, hash-verified

419
420
421def flatten_items(
422 tree: Nested[Tensor], separator: str = "/", is_leaf: Optional[Callable[[Any], bool]] = None
423) -> Sequence[tuple[str, Tensor]]:
424 """Flattens `tree` and returns a list of (path, value) pairs."""
425 flat_paths_and_values, _ = jax.tree_util.tree_flatten_with_path(tree, is_leaf=is_leaf)
426 return list(
427 (separator.join(_key_entry_to_str(k) for k in path), value)
428 for path, value in flat_paths_and_values
429 )
430
431
432@jax.tree_util.register_pytree_with_keys_class

Callers 15

param_init_debug_stringFunction · 0.90
_settings_to_stringFunction · 0.90
__call__Method · 0.90
__call__Method · 0.90
__call__Method · 0.90
target_to_sourceMethod · 0.90
source_to_targetMethod · 0.90
source_to_targetMethod · 0.90
target_to_sourceMethod · 0.90
source_to_targetMethod · 0.90
__call__Method · 0.90

Calls 2

_key_entry_to_strFunction · 0.85
joinMethod · 0.80

Tested by 15

param_init_debug_stringFunction · 0.72
_settings_to_stringFunction · 0.72
testParityMethod · 0.72
__call__Method · 0.72
test_flatten_itemsMethod · 0.72