Flattens a pytree.
tree – a pytree to flatten.
bool]]) – an optionally specified function that will be called at each flattening step. It should return a boolean, which indicates whether the flattening should traverse the current object, or if it should be stopped immediately, with the whole subtree being treated as a leaf.
A pair where the first element is a list of leaf values and the second element is a treedef representing the structure of the flattened tree.