Sets the environment variable DATA_DIR to the given `data_dir`. Args: data_dir: The data_dir. Raises: ValueError: If the environment variable DATA_DIR is already set to a different value.
(data_dir: Optional[str])
| 1530 | partial_fn = functools.partial(fn, *args, **kwargs) |
| 1531 | return functools.update_wrapper(partial_fn, fn) |
| 1532 | |
| 1533 | |
| 1534 | def prune_tree( |
| 1535 | in_tree: NestedTensor, |
| 1536 | should_prune: Callable[[str, NestedTensor], bool], |
| 1537 | *, |
| 1538 | prefix: str = "", |
| 1539 | separator: str = "/", |
| 1540 | ): |
| 1541 | """Returns a shallow copy of the input tree with subtrees pruned based on `should_prune`. |
| 1542 | |
| 1543 | This is a shallow copy because leaf nodes (non-dict values) are not deep-copied. |
| 1544 | |
| 1545 | Args: |
| 1546 | in_tree: The input tree to be pruned. |
| 1547 | should_prune: A callable which takes (path, subtree) as input and returns a boolean. The |
| 1548 | subtree provided will have already been pruned. If the callable returns True, the |
| 1549 | subtree itself will be dropped. |
| 1550 | prefix: Path prefix. |
| 1551 | separator: Separator used to join path parts. |
| 1552 | |
| 1553 | Returns: |
| 1554 | The pruned copy of the input tree. |
| 1555 | """ |
| 1556 | if isinstance(in_tree, dict): |
| 1557 | # Use type() so that if in_tree is a VDict, out_tree is also a VDict. |
| 1558 | out_tree = type(in_tree)() |
| 1559 | for k, v in in_tree.items(): |