Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add alias for for functions in optax.tree_utils like jax.tree #1166

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions optax/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
from optax._src.utils import multi_normal
from optax._src.utils import scale_gradient
from optax._src.utils import value_and_grad_from_state
from optax._src import tree

# TODO(mtthss): remove contrib aliases from flat namespace once users updated.
# Deprecated modules
Expand Down
41 changes: 41 additions & 0 deletions optax/_src/tree.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""Utilities for working with tree-like container data structures. The
:mod:`optax.tree` namespace contains aliases of utilities from
:mod:`optax.tree_util`."""

# pylint: disable=unused-import
from optax.tree_utils._casting import tree_cast as cast
from optax.tree_utils._casting import tree_dtype as dtype

from optax.tree_utils._random import tree_random_like as random_like
from optax.tree_utils._random import tree_split_key_like as split_key_like

from optax.tree_utils._state_utils import NamedTupleKey
from optax.tree_utils._state_utils import tree_get as get
from optax.tree_utils._state_utils import tree_get_all_with_path as get_all_with_path
from optax.tree_utils._state_utils import tree_map_params as map_params
from optax.tree_utils._state_utils import tree_set as set # pylint: disable=redefined-builtin

from optax.tree_utils._tree_math import tree_add as add
from optax.tree_utils._tree_math import tree_add_scalar_mul as add_scalar_mul
from optax.tree_utils._tree_math import tree_bias_correction as bias_correction
from optax.tree_utils._tree_math import tree_clip as clip
from optax.tree_utils._tree_math import tree_conj as conj
from optax.tree_utils._tree_math import tree_div as div
from optax.tree_utils._tree_math import tree_full_like as full_like
from optax.tree_utils._tree_math import tree_l1_norm as l1_norm
from optax.tree_utils._tree_math import tree_l2_norm as l2_norm
from optax.tree_utils._tree_math import tree_linf_norm as linf_norm
from optax.tree_utils._tree_math import tree_max as max # pylint: disable=redefined-builtin
from optax.tree_utils._tree_math import tree_mul as mul
from optax.tree_utils._tree_math import tree_ones_like as ones_like
from optax.tree_utils._tree_math import tree_real as real
from optax.tree_utils._tree_math import tree_scalar_mul as scalar_mul
from optax.tree_utils._tree_math import tree_sub as sub
from optax.tree_utils._tree_math import tree_sum as sum # pylint: disable=redefined-builtin
from optax.tree_utils._tree_math import tree_update_infinity_moment as update_infinity_moment
from optax.tree_utils._tree_math import tree_update_moment as update_moment
from optax.tree_utils._tree_math import tree_update_moment_per_elem_norm as update_moment_per_elem_norm
from optax.tree_utils._tree_math import tree_vdot as vdot
from optax.tree_utils._tree_math import tree_where as where
from optax.tree_utils._tree_math import tree_zeros_like as zeros_like

Loading