google / google/flax

Return key from `traverse_util.Traversal.iterate()`

Open
#1,170 6 comments 0 reactions 0 assignees View on GitHub
Status: pull requests welcome
Dominant language
Jupyter Notebook
Stars
7.3k
Forks
833
Avg merge
5h 11m
Merged PRs (30d)
5

Description

Currently `traverse_util.Traversal.iterate()` only returns the traversed values. In some cases we need access to the traversed keys as well, for example when checking that two `ModelParamTraversal` do not overlap in their keyspace (#1135).

Thus, the interface should be updated to
```python
@abc.abstractmethod
def iterate(self, inputs):
"""Iterate over the values selected by this `Traversal`.

Args:
inputs: the object that should be traversed.
Returns:
An iterator over the traversed ``(key, value)``.
"""
pass
```

And all uses of `traverse_util.Traversal.iterate()` updated accordingly.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.