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

Replace deprecated typing.Hashable with collections.abc.Hashable. #1068

Merged
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
3 changes: 2 additions & 1 deletion docs/ext/coverage_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

import inspect
import types
from typing import Any, Mapping, Sequence, Tuple
from collections.abc import Mapping
from typing import Any, Sequence, Tuple

import optax
from sphinx import application
Expand Down
3 changes: 2 additions & 1 deletion examples/cifar10_resnet.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
],
"source": [
"import functools\n",
"from typing import Any, Callable, Sequence, Tuple, Optional, Dict\n",
"from collections.abc import Callable\n",
"from typing import Any, Sequence, Tuple, Optional, Dict\n",
"\n",
"from flax import linen as nn\n",
"\n",
Expand Down
3 changes: 2 additions & 1 deletion examples/meta_learning.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
},
"outputs": [],
"source": [
"from typing import Callable, Iterator, Tuple\n",
"from collections.abc import Callable\n",
"from typing import Iterator, Tuple\n",
"import chex\n",
"import jax\n",
"import jax.numpy as jnp\n",
Expand Down
3 changes: 2 additions & 1 deletion optax/_src/alias.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"""Aliases for popular optimizers."""

import functools
from typing import Any, Callable, Optional, Union
from collections.abc import Callable
from typing import Any, Optional, Union

import jax.numpy as jnp

Expand Down
3 changes: 2 additions & 1 deletion optax/_src/alias_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
# ==============================================================================
"""Tests for `alias.py`."""

from typing import Any, Callable, Union
from collections.abc import Callable
from typing import Any, Union

from absl.testing import absltest
from absl.testing import parameterized
Expand Down
3 changes: 2 additions & 1 deletion optax/_src/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
# ==============================================================================
"""Base interfaces and datatypes."""

from typing import Any, Callable, NamedTuple, Optional, Protocol, runtime_checkable, Sequence, Union
from collections.abc import Callable
from typing import Any, NamedTuple, Optional, Protocol, runtime_checkable, Sequence, Union

import chex
import jax
Expand Down
3 changes: 2 additions & 1 deletion optax/_src/factorized.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"""Factorized optimizers."""

import dataclasses
from typing import NamedTuple, Optional, Callable
from collections.abc import Callable
from typing import NamedTuple, Optional

import chex
import jax
Expand Down
3 changes: 2 additions & 1 deletion optax/_src/linear_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"""Linear algebra utilities used in optimisation."""

import functools
from typing import Callable, Optional, Union
from collections.abc import Callable
from typing import Optional, Union

import chex
import jax
Expand Down
3 changes: 2 additions & 1 deletion optax/_src/linesearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"""Line-searches."""

import functools
from typing import Any, Callable, NamedTuple, Optional, Union
from collections.abc import Callable
from typing import Any, NamedTuple, Optional, Union

import chex
import jax
Expand Down
3 changes: 2 additions & 1 deletion optax/_src/linesearch_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
import io
import itertools
import math
from typing import Callable, Optional
from collections.abc import Callable
from typing import Optional

from absl.testing import absltest
from absl.testing import parameterized
Expand Down
3 changes: 2 additions & 1 deletion optax/_src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
import functools
import inspect
import operator
from typing import Any, Callable, Optional, Sequence, Union
from collections.abc import Callable
from typing import Any, Optional, Sequence, Union

import chex
from etils import epy
Expand Down
2 changes: 1 addition & 1 deletion optax/_src/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"""Transformation wrappers."""

import functools
from typing import Callable
from collections.abc import Callable

import chex
import jax.numpy as jnp
Expand Down
3 changes: 2 additions & 1 deletion optax/contrib/_acprop.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
Asynchronous Update for Adaptive Gradient Methods" by Zhuang et al.
(https://arxiv.org/abs/2110.05454).
"""
from typing import Any, Callable, Optional, Union
from collections.abc import Callable
from typing import Any, Optional, Union

import jax
import jax.numpy as jnp
Expand Down
3 changes: 2 additions & 1 deletion optax/contrib/_cocob.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
Networks without Learning Rates Through Coin Betting" by Francesco Orabona and
Tatiana Tommasi.
"""
from typing import Any, Callable, NamedTuple, Optional, Union
from collections.abc import Callable
from typing import Any, NamedTuple, Optional, Union

import jax
import jax.numpy as jnp
Expand Down
3 changes: 2 additions & 1 deletion optax/contrib/_dog.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
Gradient Descent Method<https://arxiv.org/pdf/2305.16284>`_, 2023.
"""

from typing import Any, Callable, NamedTuple, Optional, Union
from collections.abc import Callable
from typing import Any, NamedTuple, Optional, Union

import chex
import jax
Expand Down
3 changes: 2 additions & 1 deletion optax/contrib/_sam.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
"""
# pytype: skip-file

from typing import Callable, Optional
from collections.abc import Callable
from typing import Optional
import chex
import jax
import jax.numpy as jnp
Expand Down
3 changes: 2 additions & 1 deletion optax/losses/_ranking.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
[-0.755, 0.09, 0.665]
"""

from typing import Callable, Optional
from collections.abc import Callable
from typing import Optional

import chex
import jax
Expand Down
3 changes: 2 additions & 1 deletion optax/monte_carlo/control_variates.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@

For examples, see `control_delta_method` and `moving_avg_baseline`.
"""
from typing import Any, Callable, Sequence
from collections.abc import Callable
from typing import Any, Sequence

import chex
import jax
Expand Down
3 changes: 2 additions & 1 deletion optax/monte_carlo/stochastic_gradient_estimators.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"""

import math
from typing import Any, Callable, Sequence
from collections.abc import Callable
from typing import Any, Sequence

import chex
import jax
Expand Down
3 changes: 2 additions & 1 deletion optax/schedules/_inject.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

import functools
import inspect
from typing import Callable, Iterable, NamedTuple, Optional, Union
from collections.abc import Callable
from typing import Iterable, NamedTuple, Optional, Union
import warnings

import chex
Expand Down
3 changes: 2 additions & 1 deletion optax/transforms/_accumulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
# ==============================================================================
"""Gradient transformations for accumulating gradients across updates."""

from typing import Any, Callable, NamedTuple, Optional, Protocol, Union
from collections.abc import Callable
from typing import Any, NamedTuple, Optional, Protocol, Union

import chex
import jax
Expand Down
3 changes: 2 additions & 1 deletion optax/transforms/_adding.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
# ==============================================================================
"""Additive components in gradient transformations."""

from typing import Any, Callable, NamedTuple, Optional, Union
from collections.abc import Callable
from typing import Any, NamedTuple, Optional, Union

import chex
import jax
Expand Down
3 changes: 2 additions & 1 deletion optax/transforms/_combining.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
# ==============================================================================
"""Flexibly compose gradient transformations."""

from typing import Callable, NamedTuple, Union, Mapping, Hashable
from collections.abc import Callable, Hashable, Mapping
from typing import NamedTuple, Union

import jax

Expand Down
3 changes: 2 additions & 1 deletion optax/transforms/_masking.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
# ==============================================================================
"""Wrappers that mask out part of the parameters when applying a transform."""

from typing import Any, Callable, NamedTuple, Union
from collections.abc import Callable
from typing import Any, NamedTuple, Union

import jax

Expand Down
3 changes: 2 additions & 1 deletion optax/tree_utils/_random.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
# ==============================================================================
"""Utilities to generate random pytrees."""

from typing import Callable, Optional
from collections.abc import Callable
from typing import Optional

import chex
import jax
Expand Down
2 changes: 1 addition & 1 deletion optax/tree_utils/_random_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# ==============================================================================
"""Tests for optax.tree_utils._random."""

from typing import Callable
from collections.abc import Callable

from absl.testing import absltest
from absl.testing import parameterized
Expand Down
3 changes: 2 additions & 1 deletion optax/tree_utils/_state_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
import dataclasses
import functools
import typing
from typing import Any, Callable, Optional, Protocol, Tuple, Union, cast
from collections.abc import Callable
from typing import Any, Optional, Protocol, Tuple, Union, cast

import jax
from optax._src import base
Expand Down
Loading