haliax 1.4.dev331__tar.gz → 1.4.dev332__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. {haliax-1.4.dev331 → haliax-1.4.dev332}/PKG-INFO +1 -1
  2. {haliax-1.4.dev331 → haliax-1.4.dev332}/mkdocs.yml +1 -0
  3. haliax-1.4.dev332/src/haliax/__about__.py +1 -0
  4. {haliax-1.4.dev331 → haliax-1.4.dev332}/src/haliax/__init__.py +2 -2
  5. {haliax-1.4.dev331 → haliax-1.4.dev332}/src/haliax/jax_utils.py +27 -19
  6. {haliax-1.4.dev331 → haliax-1.4.dev332}/src/haliax/nn/__init__.py +1 -4
  7. haliax-1.4.dev332/src/haliax/nn/scan.py +684 -0
  8. {haliax-1.4.dev331 → haliax-1.4.dev332}/src/haliax/random.py +0 -1
  9. {haliax-1.4.dev331 → haliax-1.4.dev332}/tests/test_scan.py +56 -3
  10. haliax-1.4.dev331/src/haliax/__about__.py +0 -1
  11. haliax-1.4.dev331/src/haliax/nn/scan.py +0 -425
  12. {haliax-1.4.dev331 → haliax-1.4.dev332}/.coveragerc +0 -0
  13. {haliax-1.4.dev331 → haliax-1.4.dev332}/.flake8 +0 -0
  14. {haliax-1.4.dev331 → haliax-1.4.dev332}/.github/workflows/publish_dev.yaml +0 -0
  15. {haliax-1.4.dev331 → haliax-1.4.dev332}/.github/workflows/run_pre_commit.yaml +0 -0
  16. {haliax-1.4.dev331 → haliax-1.4.dev332}/.github/workflows/run_quick_levanter_tests.yaml +0 -0
  17. {haliax-1.4.dev331 → haliax-1.4.dev332}/.github/workflows/run_tests.yaml +0 -0
  18. {haliax-1.4.dev331 → haliax-1.4.dev332}/.gitignore +0 -0
  19. {haliax-1.4.dev331 → haliax-1.4.dev332}/.pre-commit-config.yaml +0 -0
  20. {haliax-1.4.dev331 → haliax-1.4.dev332}/.readthedocs.yaml +0 -0
  21. {haliax-1.4.dev331 → haliax-1.4.dev332}/CONTRIBUTING.md +0 -0
  22. {haliax-1.4.dev331 → haliax-1.4.dev332}/LICENSE +0 -0
  23. {haliax-1.4.dev331 → haliax-1.4.dev332}/README.md +0 -0
  24. {haliax-1.4.dev331 → haliax-1.4.dev332}/docs/api.md +0 -0
  25. {haliax-1.4.dev331 → haliax-1.4.dev332}/docs/broadcasting.md +0 -0
  26. {haliax-1.4.dev331 → haliax-1.4.dev332}/docs/cheatsheet.md +0 -0
  27. {haliax-1.4.dev331 → haliax-1.4.dev332}/docs/css/material.css +0 -0
  28. {haliax-1.4.dev331 → haliax-1.4.dev332}/docs/css/mkdocstrings.css +0 -0
  29. {haliax-1.4.dev331 → haliax-1.4.dev332}/docs/faq.md +0 -0
  30. {haliax-1.4.dev331 → haliax-1.4.dev332}/docs/figures/data_parallel_mesh.png +0 -0
  31. {haliax-1.4.dev331 → haliax-1.4.dev332}/docs/figures/data_parallel_mesh_replicated.png +0 -0
  32. {haliax-1.4.dev331 → haliax-1.4.dev332}/docs/figures/device_mesh_1d.png +0 -0
  33. {haliax-1.4.dev331 → haliax-1.4.dev332}/docs/figures/device_mesh_1d_zero.png +0 -0
  34. {haliax-1.4.dev331 → haliax-1.4.dev332}/docs/figures/device_mesh_2d.png +0 -0
  35. {haliax-1.4.dev331 → haliax-1.4.dev332}/docs/figures/device_mesh_2d_batch_partitioned.png +0 -0
  36. {haliax-1.4.dev331 → haliax-1.4.dev332}/docs/figures/device_mesh_2d_data_replicated.png +0 -0
  37. {haliax-1.4.dev331 → haliax-1.4.dev332}/docs/figures/device_mesh_2d_data_replicated_mlp_partitioned.png +0 -0
  38. {haliax-1.4.dev331 → haliax-1.4.dev332}/docs/figures/device_mesh_2d_intermediate_fully_partitioned.png +0 -0
  39. {haliax-1.4.dev331 → haliax-1.4.dev332}/docs/figures/device_mesh_2d_zero.png +0 -0
  40. {haliax-1.4.dev331 → haliax-1.4.dev332}/docs/fp8.md +0 -0
  41. {haliax-1.4.dev331 → haliax-1.4.dev332}/docs/hof.md +0 -0
  42. {haliax-1.4.dev331 → haliax-1.4.dev332}/docs/index.md +0 -0
  43. {haliax-1.4.dev331 → haliax-1.4.dev332}/docs/indexing.md +0 -0
  44. {haliax-1.4.dev331 → haliax-1.4.dev332}/docs/matmul.md +0 -0
  45. {haliax-1.4.dev331 → haliax-1.4.dev332}/docs/nn.md +0 -0
  46. {haliax-1.4.dev331 → haliax-1.4.dev332}/docs/partitioning.md +0 -0
  47. {haliax-1.4.dev331 → haliax-1.4.dev332}/docs/rearrange.ipynb +0 -0
  48. {haliax-1.4.dev331 → haliax-1.4.dev332}/docs/rearrange.md +0 -0
  49. {haliax-1.4.dev331 → haliax-1.4.dev332}/docs/requirements.txt +0 -0
  50. {haliax-1.4.dev331 → haliax-1.4.dev332}/docs/state-dict.md +0 -0
  51. {haliax-1.4.dev331 → haliax-1.4.dev332}/docs/tutorial.md +0 -0
  52. {haliax-1.4.dev331 → haliax-1.4.dev332}/pyproject.toml +0 -0
  53. {haliax-1.4.dev331 → haliax-1.4.dev332}/src/haliax/_src/__init__.py +0 -0
  54. {haliax-1.4.dev331 → haliax-1.4.dev332}/src/haliax/_src/compile_utils.py +0 -0
  55. {haliax-1.4.dev331 → haliax-1.4.dev332}/src/haliax/_src/dot.py +0 -0
  56. {haliax-1.4.dev331 → haliax-1.4.dev332}/src/haliax/_src/einsum.py +0 -0
  57. {haliax-1.4.dev331 → haliax-1.4.dev332}/src/haliax/_src/fp8.py +0 -0
  58. {haliax-1.4.dev331 → haliax-1.4.dev332}/src/haliax/_src/parsing.py +0 -0
  59. {haliax-1.4.dev331 → haliax-1.4.dev332}/src/haliax/_src/rearrange.py +0 -0
  60. {haliax-1.4.dev331 → haliax-1.4.dev332}/src/haliax/_src/state_dict.py +0 -0
  61. {haliax-1.4.dev331 → haliax-1.4.dev332}/src/haliax/_src/util.py +0 -0
  62. {haliax-1.4.dev331 → haliax-1.4.dev332}/src/haliax/axis.py +0 -0
  63. {haliax-1.4.dev331 → haliax-1.4.dev332}/src/haliax/core.py +0 -0
  64. {haliax-1.4.dev331 → haliax-1.4.dev332}/src/haliax/debug.py +0 -0
  65. {haliax-1.4.dev331 → haliax-1.4.dev332}/src/haliax/hof.py +0 -0
  66. {haliax-1.4.dev331 → haliax-1.4.dev332}/src/haliax/nn/activations.py +0 -0
  67. {haliax-1.4.dev331 → haliax-1.4.dev332}/src/haliax/nn/attention.py +0 -0
  68. {haliax-1.4.dev331 → haliax-1.4.dev332}/src/haliax/nn/conv.py +0 -0
  69. {haliax-1.4.dev331 → haliax-1.4.dev332}/src/haliax/nn/dropout.py +0 -0
  70. {haliax-1.4.dev331 → haliax-1.4.dev332}/src/haliax/nn/embedding.py +0 -0
  71. {haliax-1.4.dev331 → haliax-1.4.dev332}/src/haliax/nn/linear.py +0 -0
  72. {haliax-1.4.dev331 → haliax-1.4.dev332}/src/haliax/nn/loss.py +0 -0
  73. {haliax-1.4.dev331 → haliax-1.4.dev332}/src/haliax/nn/mlp.py +0 -0
  74. {haliax-1.4.dev331 → haliax-1.4.dev332}/src/haliax/nn/normalization.py +0 -0
  75. {haliax-1.4.dev331 → haliax-1.4.dev332}/src/haliax/nn/pool.py +0 -0
  76. {haliax-1.4.dev331 → haliax-1.4.dev332}/src/haliax/ops.py +0 -0
  77. {haliax-1.4.dev331 → haliax-1.4.dev332}/src/haliax/partitioning.py +0 -0
  78. {haliax-1.4.dev331 → haliax-1.4.dev332}/src/haliax/quantization.py +0 -0
  79. {haliax-1.4.dev331 → haliax-1.4.dev332}/src/haliax/specialized_fns.py +0 -0
  80. {haliax-1.4.dev331 → haliax-1.4.dev332}/src/haliax/state_dict.py +0 -0
  81. {haliax-1.4.dev331 → haliax-1.4.dev332}/src/haliax/tree_util.py +0 -0
  82. {haliax-1.4.dev331 → haliax-1.4.dev332}/src/haliax/types.py +0 -0
  83. {haliax-1.4.dev331 → haliax-1.4.dev332}/src/haliax/util.py +0 -0
  84. {haliax-1.4.dev331 → haliax-1.4.dev332}/src/haliax/wrap.py +0 -0
  85. {haliax-1.4.dev331 → haliax-1.4.dev332}/tests/core_test.py +0 -0
  86. {haliax-1.4.dev331 → haliax-1.4.dev332}/tests/test_attention.py +0 -0
  87. {haliax-1.4.dev331 → haliax-1.4.dev332}/tests/test_axis.py +0 -0
  88. {haliax-1.4.dev331 → haliax-1.4.dev332}/tests/test_conv.py +0 -0
  89. {haliax-1.4.dev331 → haliax-1.4.dev332}/tests/test_debug.py +0 -0
  90. {haliax-1.4.dev331 → haliax-1.4.dev332}/tests/test_dot.py +0 -0
  91. {haliax-1.4.dev331 → haliax-1.4.dev332}/tests/test_einsum.py +0 -0
  92. {haliax-1.4.dev331 → haliax-1.4.dev332}/tests/test_fp8.py +0 -0
  93. {haliax-1.4.dev331 → haliax-1.4.dev332}/tests/test_hof.py +0 -0
  94. {haliax-1.4.dev331 → haliax-1.4.dev332}/tests/test_int8.py +0 -0
  95. {haliax-1.4.dev331 → haliax-1.4.dev332}/tests/test_nn.py +0 -0
  96. {haliax-1.4.dev331 → haliax-1.4.dev332}/tests/test_ops.py +0 -0
  97. {haliax-1.4.dev331 → haliax-1.4.dev332}/tests/test_parsing.py +0 -0
  98. {haliax-1.4.dev331 → haliax-1.4.dev332}/tests/test_partitioning.py +0 -0
  99. {haliax-1.4.dev331 → haliax-1.4.dev332}/tests/test_pool.py +0 -0
  100. {haliax-1.4.dev331 → haliax-1.4.dev332}/tests/test_random.py +0 -0
  101. {haliax-1.4.dev331 → haliax-1.4.dev332}/tests/test_rearrange.py +0 -0
  102. {haliax-1.4.dev331 → haliax-1.4.dev332}/tests/test_specialized_fns.py +0 -0
  103. {haliax-1.4.dev331 → haliax-1.4.dev332}/tests/test_state_dict.py +0 -0
  104. {haliax-1.4.dev331 → haliax-1.4.dev332}/tests/test_tree_util.py +0 -0
  105. {haliax-1.4.dev331 → haliax-1.4.dev332}/tests/test_utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: haliax
3
- Version: 1.4.dev331
3
+ Version: 1.4.dev332
4
4
  Summary: Named Tensors for Legible Deep Learning in JAX
5
5
  Project-URL: Homepage, https://github.com/stanford-crfm/haliax
6
6
  Project-URL: Bug Tracker, https://github.com/stanford-crfm/haliax/issues/
@@ -85,6 +85,7 @@ nav:
85
85
  - Rearrange: 'rearrange.md'
86
86
  - Matrix Multiplication: 'matmul.md'
87
87
  - Neural Networks: 'nn.md'
88
+ - Module Stacks: 'stacked.md'
88
89
  - Partitioning: 'partitioning.md'
89
90
  - Higher Order Functions: 'hof.md'
90
91
  - FP8: 'fp8.md'
@@ -0,0 +1 @@
1
+ __version__ = "1.4.dev332"
@@ -61,7 +61,7 @@ from .core import (
61
61
  updated_slice,
62
62
  )
63
63
  from .hof import fold, map, scan, vmap
64
- from .jax_utils import filter_checkpoint
64
+ from .jax_utils import tree_checkpoint_name
65
65
  from .ops import clip, isclose, pad_left, trace, tril, triu, where
66
66
  from .partitioning import auto_sharded, axis_mapping, fsdp, named_jit, shard, shard_with_axis_mapping
67
67
  from .specialized_fns import top_k
@@ -887,7 +887,6 @@ def true_divide(x1: NamedOrNumeric, x2: NamedOrNumeric, /) -> NamedOrNumeric:
887
887
  # deprecated name
888
888
  concat_axis_specs = concat_axes
889
889
 
890
-
891
890
  __all__ = [
892
891
  "debug",
893
892
  "random",
@@ -1071,4 +1070,5 @@ __all__ = [
1071
1070
  "ravel",
1072
1071
  "flatten",
1073
1072
  "is_named_array",
1073
+ "tree_checkpoint_name",
1074
1074
  ]
@@ -1,5 +1,6 @@
1
1
  import functools as ft
2
2
  import typing
3
+ import warnings
3
4
  from typing import Any, Callable, Optional, Sequence, Union
4
5
 
5
6
  import equinox as eqx
@@ -8,8 +9,8 @@ import numpy as np
8
9
  from jax import Array
9
10
  from jax import numpy as jnp
10
11
  from jax import random as jrandom
11
- from jax._src.numpy import lax_numpy
12
- from jax._src.typing import DTypeLike
12
+ from jax.ad_checkpoint import checkpoint_name
13
+ from jax.typing import DTypeLike
13
14
  from jaxtyping import PRNGKeyArray
14
15
 
15
16
  import haliax
@@ -27,6 +28,7 @@ except ImportError:
27
28
 
28
29
 
29
30
  F = typing.TypeVar("F", bound=Callable[..., Any])
31
+ T = typing.TypeVar("T")
30
32
 
31
33
 
32
34
  class Static(eqx.Module):
@@ -70,23 +72,9 @@ def filter_eval_shape(*args, **kwargs):
70
72
  def filter_checkpoint(fun: Callable, *, prevent_cse: bool = True, policy: Optional[Callable[..., bool]] = None):
71
73
  """As `jax.checkpoint`, but allows any Python object as inputs and outputs"""
72
74
 
73
- @ft.wraps(fun)
74
- def _fn(_static, _dynamic):
75
- _args, _kwargs = eqx.combine(_static, _dynamic)
76
- _out = fun(*_args, **_kwargs)
77
- _dynamic_out, _static_out = eqx.partition(_out, is_jax_array_like)
78
- return _dynamic_out, Static(_static_out)
75
+ warnings.warn("filter_checkpoint is deprecated, use eqx.filter_checkpoint instead", DeprecationWarning)
79
76
 
80
- checkpointed_fun = jax.checkpoint(_fn, prevent_cse=prevent_cse, policy=policy, static_argnums=(0,))
81
-
82
- @ft.wraps(fun)
83
- def wrapper(*args, **kwargs):
84
- dynamic, static = eqx.partition((args, kwargs), is_jax_array_like)
85
- dynamic_out, static_out = checkpointed_fun(static, dynamic)
86
-
87
- return eqx.combine(dynamic_out, static_out.value)
88
-
89
- return wrapper
77
+ return eqx.filter_checkpoint(fun, prevent_cse=prevent_cse, policy=policy)
90
78
 
91
79
 
92
80
  def is_jax_array_like(x):
@@ -202,7 +190,7 @@ def _jittable_dg_einsum(
202
190
  contract_path = opt_einsum.contract_path
203
191
  else:
204
192
  ty = next(iter(non_constant_dim_types))
205
- contract_path = lax_numpy._poly_einsum_handlers.get(ty, lax_numpy._default_poly_einsum_handler)
193
+ contract_path = jax_einsum._poly_einsum_handlers.get(ty, jax_einsum._default_poly_einsum_handler)
206
194
  # using einsum_call=True here is an internal api for opt_einsum... sorry
207
195
  operands, contractions = contract_path(*operands, einsum_call=True, use_blas=True, optimize=optimize)
208
196
 
@@ -212,3 +200,23 @@ def _jittable_dg_einsum(
212
200
  if spec is not None:
213
201
  einsum = jax.named_call(einsum, name=spec)
214
202
  return einsum(operands, contractions, precision, preferred_element_type, _dot_general) # type: ignore[operator]
203
+
204
+
205
+ def tree_checkpoint_name(x: T, name: str) -> T:
206
+ """
207
+ Checkpoint a tree of arrays with a given name. This is useful for gradient checkpointing.
208
+ This is equivalent to calling [jax.ad_checkpoint.checkpoint_name][]
209
+ except that it works for any PyTree, not just arrays.
210
+
211
+ See Also:
212
+ * [jax.ad_checkpoint.checkpoint_name][]
213
+ * [haliax.nn.StackedCheckpointPolicy][]
214
+ """
215
+
216
+ def _checkpoint_leaf(x):
217
+ if is_jax_array_like(x):
218
+ return checkpoint_name(x, name)
219
+ else:
220
+ return x
221
+
222
+ return jax.tree.map(_checkpoint_leaf, x)
@@ -38,10 +38,7 @@ from .loss import binary_cross_entropy_loss, cross_entropy_loss, cross_entropy_l
38
38
  from .mlp import MLP
39
39
  from .normalization import LayerNorm, log_softmax, logsumexp, softmax, standardize
40
40
  from .pool import max_pool, mean_pool, min_pool
41
- from .scan import BlockSeq, Stacked
42
-
43
-
44
- # TODO: support where in softmax, etc
41
+ from .scan import BlockSeq, Stacked, StackedCheckpointPolicy
45
42
 
46
43
 
47
44
  def one_hot(x: NamedArray | int, class_axis: Axis, *, dtype=None) -> NamedArray: