Skip to content

Commit 8b0dc02

Browse files
emilyfertigOptaxDev
authored andcommitted
Use internal warn_deprecated_function instead of the Chex version.
PiperOrigin-RevId: 830563605
1 parent 5db134c commit 8b0dc02

6 files changed

Lines changed: 20 additions & 15 deletions

File tree

optax/_src/deprecations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def warn_deprecated_function(
7575
The wrapped function.
7676
7777
Example usage:
78-
>>> @functools.partial(chex.warn_deprecated_function, replacement='g')
78+
>>> @functools.partial(warn_deprecated_function, replacement='g')
7979
... def f(a, b):
8080
... return a + b
8181
"""

optax/_src/transform.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from optax._src import base
2525
from optax._src import numerics
2626
from optax._src import utils
27+
from optax._src.deprecations import warn_deprecated_function # pylint: disable=g-importing-member
2728
from optax.transforms import _accumulation
2829
from optax.transforms import _adding
2930
import optax.tree
@@ -1813,7 +1814,7 @@ def update_fn(
18131814

18141815

18151816
@functools.partial(
1816-
chex.warn_deprecated_function, replacement='optax.tree.cast'
1817+
warn_deprecated_function, replacement='optax.tree.cast'
18171818
)
18181819
def cast_tree(
18191820
tree: chex.ArrayTree, dtype: Optional[chex.ArrayDType]

optax/_src/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import jax.scipy.stats.norm as multivariate_normal
2828
from optax._src import base
2929
from optax._src import numerics
30+
from optax._src.deprecations import warn_deprecated_function # pylint: disable=g-importing-member
3031
import optax.tree
3132

3233

@@ -55,7 +56,7 @@ def canonicalize_key(key_or_seed: jax.Array | int) -> jax.Array:
5556

5657

5758
@functools.partial(
58-
chex.warn_deprecated_function, replacement='optax.tree.cast'
59+
warn_deprecated_function, replacement='optax.tree.cast'
5960
)
6061
def cast_tree(
6162
tree: chex.ArrayTree, dtype: Optional[chex.ArrayDType]

optax/losses/_classification.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import jax.numpy as jnp
2424
import jax.scipy.special
2525
from optax import projections
26+
from optax._src.deprecations import warn_deprecated_function # pylint: disable=g-importing-member
2627

2728

2829
def canonicalize_axis(axis, ndim):
@@ -83,7 +84,7 @@ class is an independent binary prediction and different classes are not
8384

8485

8586
@functools.partial(
86-
chex.warn_deprecated_function, replacement='sigmoid_binary_cross_entropy'
87+
warn_deprecated_function, replacement='sigmoid_binary_cross_entropy'
8788
)
8889
def binary_logistic_loss(logits, labels):
8990
return sigmoid_binary_cross_entropy(logits, labels)
@@ -147,7 +148,7 @@ def sparsemax_loss(
147148
return jax.nn.sparse_plus(jnp.where(labels, -logits, logits))
148149

149150

150-
@functools.partial(chex.warn_deprecated_function, replacement='sparsemax_loss')
151+
@functools.partial(warn_deprecated_function, replacement='sparsemax_loss')
151152
def binary_sparsemax_loss(logits, labels):
152153
return sparsemax_loss(logits, labels)
153154

@@ -406,7 +407,7 @@ def softmax_cross_entropy_with_integer_labels(
406407

407408

408409
@functools.partial(
409-
chex.warn_deprecated_function,
410+
warn_deprecated_function,
410411
replacement='softmax_cross_entropy_with_integer_labels',
411412
)
412413
def multiclass_logistic_loss(logits, labels):

optax/monte_carlo/control_variates.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
import jax
6161
import jax.numpy as jnp
6262
from optax._src import base
63+
from optax._src.deprecations import warn_deprecated_function # pylint: disable=g-importing-member
6364

6465

6566
CvState = Any
@@ -69,7 +70,7 @@
6970
ControlVariate = tuple[ComputeCv, CvExpectedValue, UpdateCvState]
7071

7172

72-
@chex.warn_deprecated_function
73+
@warn_deprecated_function
7374
def control_delta_method(
7475
function: Callable[[chex.Array], float],
7576
) -> ControlVariate:
@@ -143,7 +144,7 @@ def update_state(
143144
return delta, expected_value_delta, update_state
144145

145146

146-
@chex.warn_deprecated_function
147+
@warn_deprecated_function
147148
def moving_avg_baseline(
148149
function: Callable[[chex.Array], float],
149150
decay: float = 0.99,
@@ -217,7 +218,7 @@ def _map(cv, params, samples, state):
217218
return jax.vmap(lambda x: cv(params, x, state))(samples)
218219

219220

220-
@chex.warn_deprecated_function
221+
@warn_deprecated_function
221222
def control_variates_jacobians(
222223
function: Callable[[chex.Array], float],
223224
control_variate_from_function: Callable[
@@ -366,7 +367,7 @@ def param_fn(x):
366367
return jacobians, control_variate_state
367368

368369

369-
@chex.warn_deprecated_function
370+
@warn_deprecated_function
370371
def estimate_control_variate_coefficients(
371372
function: Callable[[chex.Array], float],
372373
control_variate_from_function: Callable[

optax/monte_carlo/stochastic_gradient_estimators.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@
3838
import numpy as np
3939
from optax._src import base
4040
from optax._src import utils
41+
from optax._src.deprecations import warn_deprecated_function # pylint: disable=g-importing-member
4142

4243

43-
@chex.warn_deprecated_function
44+
@warn_deprecated_function
4445
def score_function_jacobians(
4546
function: Callable[[chex.Array], float],
4647
params: base.Params,
@@ -93,7 +94,7 @@ def surrogate(params):
9394
return jax.jacfwd(surrogate)(params)
9495

9596

96-
@chex.warn_deprecated_function
97+
@warn_deprecated_function
9798
def pathwise_jacobians(
9899
function: Callable[[chex.Array], float],
99100
params: base.Params,
@@ -146,7 +147,7 @@ def surrogate(params):
146147
return jax.jacfwd(surrogate)(params)
147148

148149

149-
@chex.warn_deprecated_function
150+
@warn_deprecated_function
150151
def measure_valued_jacobians(
151152
function: Callable[[chex.Array], float],
152153
params: base.Params,
@@ -207,7 +208,7 @@ def measure_valued_jacobians(
207208
]
208209

209210

210-
@chex.warn_deprecated_function
211+
@warn_deprecated_function
211212
def measure_valued_estimation_mean(
212213
function: Callable[[chex.Array], float],
213214
dist: Any,
@@ -280,7 +281,7 @@ def measure_valued_estimation_mean(
280281
return grads
281282

282283

283-
@chex.warn_deprecated_function
284+
@warn_deprecated_function
284285
def measure_valued_estimation_std(
285286
function: Callable[[chex.Array], float],
286287
dist: Any,

0 commit comments

Comments
 (0)