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

Fix more JAX deprecation warnings. #758

Merged
merged 1 commit into from
Jun 13, 2024
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
8 changes: 4 additions & 4 deletions equinox/_vmap_pmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def _fun_wrapper(_dynamic_args):
_out_axes = _bind_main(_main, self._out_axes)
_out_axes = _resolve_axes(_out, _out_axes)
_none_axes = jtu.tree_map(_is_none, _out_axes, is_leaf=_is_none)
_nonvmapd, _vmapd = partition(_out, _none_axes)
_nonvmapd, _vmapd = partition(_out, _none_axes, is_leaf=_is_none)
return _vmapd, Static((_nonvmapd, _out_axes))

if len(jtu.tree_leaves(in_axes)) == 0 and self._axis_size is None:
Expand Down Expand Up @@ -444,10 +444,10 @@ def fun_wrapped(_dynamic):
jtu.tree_map(_check_map_out_axis, _out_axes)
_pmapd = []
for i in range(-max_out_size, max_out_size):
_i_axes = jtu.tree_map(lambda a: a == i, _out_axes)
_pmapd.append(filter(_out, _i_axes))
_i_axes = jtu.tree_map(lambda a: a == i, _out_axes, is_leaf=_is_none)
_pmapd.append(filter(_out, _i_axes, is_leaf=_is_none))
_none_axes = jtu.tree_map(_is_none, _out_axes, is_leaf=_is_none)
_nonpmapd = filter(_out, _none_axes)
_nonpmapd = filter(_out, _none_axes, is_leaf=_is_none)
_dynamic_nonpmapd, _static_nonpmapd = hashable_partition(_nonpmapd, is_array)
return _pmapd, _dynamic_nonpmapd, Static(_static_nonpmapd)

Expand Down
8 changes: 6 additions & 2 deletions equinox/internal/_loop/checkpointed.py
Original file line number Diff line number Diff line change
Expand Up @@ -1244,7 +1244,9 @@ def _stop_gradient_on_unperturbed(init_val, final_val, body_fun):


def _perturb_to_tang(t, p):
if p is None:
if t is None:
return None
elif p is None:
return None
elif p is False:
return None
Expand All @@ -1265,5 +1267,7 @@ def _stop_gradient_on_unperturbed_jvp(primals, tangents):
perturb_val = _resolve_perturb_val(
init_val, body_fun, perturb_val, perturb_body_fun
)
t_final_val = jtu.tree_map(_perturb_to_tang, t_final_val, perturb_val)
t_final_val = jtu.tree_map(
_perturb_to_tang, t_final_val, perturb_val, is_leaf=_is_none
)
return final_val, t_final_val
28 changes: 0 additions & 28 deletions tests/test_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,18 +143,6 @@ def g(x):
assert msg.startswith("egads")
assert "EQX_ON_ERROR" in msg
assert msg.endswith("information.")
tb = e.__traceback__
code_stack = []
while tb is not None:
if not tb.tb_frame.f_globals["__name__"].startswith("jaxtyping"):
code_stack.append(tb.tb_frame.f_code)
tb = tb.tb_next
assert len(code_stack) == 2
one, two = code_stack
assert one.co_filename.endswith("test_errors.py")
assert one.co_name == "test_traceback_runtime_eqx"
assert two.co_filename.endswith("equinox/_jit.py")
assert two.co_name == "_call"


def test_traceback_runtime_custom():
Expand All @@ -178,19 +166,3 @@ def _raises():
# assert e.__cause__ is None # varies by Python version and JAX version.
assert "egads" in str(e)
assert "EQX_ON_ERROR" not in str(e)
tb = e.__traceback__
code_stack = []
while tb is not None:
if not tb.tb_frame.f_globals["__name__"].startswith("jaxtyping"):
code_stack.append(tb.tb_frame.f_code)
tb = tb.tb_next
assert len(code_stack) == 4
one, two, three, four = code_stack
assert one.co_filename.endswith("test_errors.py")
assert one.co_name == "test_traceback_runtime_custom"
assert two.co_filename.endswith("equinox/_jit.py")
assert two.co_name == "__call__"
assert three.co_filename.endswith("equinox/_module.py")
assert three.co_name == "__call__"
assert four.co_filename.endswith("equinox/_jit.py")
assert four.co_name == "_call"
Loading