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 2 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
48 changes: 48 additions & 0 deletions optax/_src/tree.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# pylint: disable=line-too-long
Ata-Shaker marked this conversation as resolved.
Show resolved Hide resolved
# pylint: disable=redefined-builtin
Ata-Shaker marked this conversation as resolved.
Show resolved Hide resolved
"""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,
tree_dtype as dtype,
)
from optax.tree_utils._random import (
tree_random_like as random_like,
tree_split_key_like as split_key_like,
)

from optax.tree_utils._state_utils import (
NamedTupleKey,
tree_get as get,
tree_get_all_with_path as get_all_with_path,
tree_map_params as map_params,
tree_set as set,
)
from optax.tree_utils._tree_math import (
tree_add as add,
tree_add_scalar_mul as add_scalar_mul,
tree_bias_correction as bias_correction,
tree_clip as clip,
tree_conj as conj,
tree_div as div,
tree_full_like as full_like,
tree_l1_norm as l1_norm,
tree_l2_norm as l2_norm,
tree_linf_norm as linf_norm,
tree_max as max,
tree_mul as mul,
tree_ones_like as ones_like,
tree_real as real,
tree_scalar_mul as scalar_mul,
tree_sub as sub,
tree_sum as sum,
tree_update_infinity_moment as update_infinity_moment,
tree_update_moment as update_moment,
tree_update_moment_per_elem_norm as update_moment_per_elem_norm,
tree_vdot as vdot,
tree_where as where,
tree_zeros_like as zeros_like
)
Loading