haliax 1.4.dev310__tar.gz → 1.4.dev313__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.
- {haliax-1.4.dev310 → haliax-1.4.dev313}/PKG-INFO +1 -1
- haliax-1.4.dev313/src/haliax/__about__.py +1 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/src/haliax/core.py +2 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/src/haliax/nn/scan.py +54 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/tests/test_scan.py +27 -0
- haliax-1.4.dev310/src/haliax/__about__.py +0 -1
- {haliax-1.4.dev310 → haliax-1.4.dev313}/.coveragerc +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/.flake8 +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/.github/workflows/publish_dev.yaml +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/.github/workflows/run_pre_commit.yaml +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/.github/workflows/run_quick_levanter_tests.yaml +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/.github/workflows/run_tests.yaml +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/.gitignore +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/.pre-commit-config.yaml +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/.readthedocs.yaml +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/CONTRIBUTING.md +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/LICENSE +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/README.md +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/docs/api.md +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/docs/broadcasting.md +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/docs/cheatsheet.md +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/docs/css/material.css +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/docs/css/mkdocstrings.css +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/docs/faq.md +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/docs/figures/data_parallel_mesh.png +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/docs/figures/data_parallel_mesh_replicated.png +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/docs/figures/device_mesh_1d.png +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/docs/figures/device_mesh_1d_zero.png +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/docs/figures/device_mesh_2d.png +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/docs/figures/device_mesh_2d_batch_partitioned.png +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/docs/figures/device_mesh_2d_data_replicated.png +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/docs/figures/device_mesh_2d_data_replicated_mlp_partitioned.png +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/docs/figures/device_mesh_2d_intermediate_fully_partitioned.png +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/docs/figures/device_mesh_2d_zero.png +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/docs/fp8.md +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/docs/hof.md +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/docs/index.md +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/docs/indexing.md +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/docs/matmul.md +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/docs/nn.md +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/docs/partitioning.md +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/docs/rearrange.ipynb +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/docs/rearrange.md +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/docs/requirements.txt +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/docs/tutorial.md +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/mkdocs.yml +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/pyproject.toml +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/src/haliax/__init__.py +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/src/haliax/_src/__init__.py +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/src/haliax/_src/compile_utils.py +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/src/haliax/_src/dot.py +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/src/haliax/_src/einsum.py +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/src/haliax/_src/fp8.py +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/src/haliax/_src/parsing.py +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/src/haliax/_src/rearrange.py +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/src/haliax/_src/util.py +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/src/haliax/axis.py +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/src/haliax/debug.py +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/src/haliax/hof.py +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/src/haliax/jax_utils.py +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/src/haliax/nn/__init__.py +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/src/haliax/nn/activations.py +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/src/haliax/nn/attention.py +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/src/haliax/nn/conv.py +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/src/haliax/nn/dropout.py +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/src/haliax/nn/embedding.py +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/src/haliax/nn/linear.py +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/src/haliax/nn/loss.py +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/src/haliax/nn/mlp.py +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/src/haliax/nn/normalization.py +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/src/haliax/nn/pool.py +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/src/haliax/ops.py +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/src/haliax/partitioning.py +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/src/haliax/quantization.py +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/src/haliax/random.py +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/src/haliax/specialized_fns.py +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/src/haliax/tree_util.py +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/src/haliax/types.py +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/src/haliax/util.py +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/src/haliax/wrap.py +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/tests/core_test.py +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/tests/test_attention.py +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/tests/test_axis.py +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/tests/test_conv.py +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/tests/test_debug.py +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/tests/test_dot.py +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/tests/test_einsum.py +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/tests/test_fp8.py +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/tests/test_hof.py +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/tests/test_nn.py +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/tests/test_ops.py +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/tests/test_parsing.py +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/tests/test_partitioning.py +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/tests/test_pool.py +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/tests/test_random.py +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/tests/test_rearrange.py +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/tests/test_specialized_fns.py +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/tests/test_tree_util.py +0 -0
- {haliax-1.4.dev310 → haliax-1.4.dev313}/tests/test_utils.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: haliax
|
|
3
|
-
Version: 1.4.
|
|
3
|
+
Version: 1.4.dev313
|
|
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/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "1.4.dev313"
|
|
@@ -684,6 +684,8 @@ def take(array: NamedArray, axis: AxisSelector, index: Union[int, NamedArray]) -
|
|
|
684
684
|
new_axes = array.axes[:axis_index] + array.axes[axis_index + 1 :]
|
|
685
685
|
return NamedArray(new_array, new_axes)
|
|
686
686
|
else:
|
|
687
|
+
if not jnp.issubdtype(index.dtype, jnp.integer):
|
|
688
|
+
raise ValueError(f"Index must be an integer array, got {index.dtype}")
|
|
687
689
|
# #13: should broadcast/autobatch take
|
|
688
690
|
remaining_axes = eliminate_axes(array.axes, axis)
|
|
689
691
|
# axis order is generally [array.axes[:axis_index], index.axes, array.axes[axis_index + 1 :]]
|
|
@@ -156,6 +156,13 @@ class Stacked(eqx.Module, Generic[M]):
|
|
|
156
156
|
|
|
157
157
|
Stacked also supports gradient checkpointing, which is useful for very large models that don't fit in memory.
|
|
158
158
|
|
|
159
|
+
Typically only one of "fold" or "scan" can be used with a given Stacked module, depending on the what the module
|
|
160
|
+
returns: if the module returns a single output, use "fold"; if the module returns a sequence of intermediates and
|
|
161
|
+
an output to be passed to the next layer, use "scan". More concretely, for a transformer, you would use "scan" if
|
|
162
|
+
you wanted to return a kv cache (or the attention matrix) as well as the output of the transformer. If you just
|
|
163
|
+
wanted the output of the transformer, you would use "fold".
|
|
164
|
+
|
|
165
|
+
|
|
159
166
|
Example:
|
|
160
167
|
```python
|
|
161
168
|
>>> import equinox as eqx
|
|
@@ -206,6 +213,32 @@ class Stacked(eqx.Module, Generic[M]):
|
|
|
206
213
|
return fn
|
|
207
214
|
|
|
208
215
|
def scan(self, init, *extra_args, **extra_kwargs):
|
|
216
|
+
"""
|
|
217
|
+
Scan over the stacked module. This is the same as a for loop that applies each instance of the module in sequence
|
|
218
|
+
to the input, passing the output of one instance to the next instance. It returns a stack of intermediates as
|
|
219
|
+
well as the final output.
|
|
220
|
+
|
|
221
|
+
That is, it behaves similarly to the following Python code:
|
|
222
|
+
|
|
223
|
+
```python
|
|
224
|
+
carry = init
|
|
225
|
+
intermediates = []
|
|
226
|
+
|
|
227
|
+
for block in self.stacked:
|
|
228
|
+
carry, extra = block(carry)
|
|
229
|
+
intermediates.append(extra)
|
|
230
|
+
|
|
231
|
+
return carry, hax.stack(Block, intermediates)
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
Args:
|
|
235
|
+
init:
|
|
236
|
+
*extra_args:
|
|
237
|
+
**extra_kwargs:
|
|
238
|
+
|
|
239
|
+
Returns:
|
|
240
|
+
|
|
241
|
+
"""
|
|
209
242
|
if self.gradient_checkpointing:
|
|
210
243
|
do_block = filter_checkpoint(self._do_block, prevent_cse=self.prevent_cse)
|
|
211
244
|
else:
|
|
@@ -213,6 +246,27 @@ class Stacked(eqx.Module, Generic[M]):
|
|
|
213
246
|
return haliax.scan(do_block, self.Block)(init, self.stacked, *extra_args, **extra_kwargs)
|
|
214
247
|
|
|
215
248
|
def fold(self, init, *args, **kwargs):
|
|
249
|
+
"""
|
|
250
|
+
Fold over the stacked module. This is the same as a for loop that applies each instance of the module in sequence
|
|
251
|
+
to the input, passing the output of one instance to the next instance.
|
|
252
|
+
That is, it behaves similarly to the following Python code:
|
|
253
|
+
|
|
254
|
+
```python
|
|
255
|
+
carry = init
|
|
256
|
+
for block in self.stacked:
|
|
257
|
+
carry = block(carry)
|
|
258
|
+
|
|
259
|
+
return carry
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
Args:
|
|
263
|
+
init:
|
|
264
|
+
*args:
|
|
265
|
+
**kwargs:
|
|
266
|
+
|
|
267
|
+
Returns:
|
|
268
|
+
|
|
269
|
+
"""
|
|
216
270
|
if self.gradient_checkpointing:
|
|
217
271
|
do_block = filter_checkpoint(self._do_block, prevent_cse=self.prevent_cse)
|
|
218
272
|
else:
|
|
@@ -68,3 +68,30 @@ def test_seq_and_stacked_give_same_results():
|
|
|
68
68
|
y_seq = m_seq.fold(x, key=jax.random.split(jax.random.PRNGKey(2), Block.size))
|
|
69
69
|
|
|
70
70
|
assert hax.all(hax.isclose(y, y_seq, atol=1e-5))
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def test_using_scan():
|
|
74
|
+
class Module(eqx.Module):
|
|
75
|
+
named: hax.NamedArray
|
|
76
|
+
array: jax.Array
|
|
77
|
+
static: int = eqx.static_field()
|
|
78
|
+
|
|
79
|
+
def __call__(self, x, *, key):
|
|
80
|
+
return x + self.array + self.static + hax.random.normal(key, x.axes), x * 2
|
|
81
|
+
|
|
82
|
+
@staticmethod
|
|
83
|
+
def init(named, array, static):
|
|
84
|
+
return Module(named=named, array=array, static=static)
|
|
85
|
+
|
|
86
|
+
Block = hax.Axis("block", 4)
|
|
87
|
+
E = hax.Axis("E", 10)
|
|
88
|
+
|
|
89
|
+
initial_named = hax.random.uniform(jax.random.PRNGKey(0), (Block, E))
|
|
90
|
+
|
|
91
|
+
m = Stacked.init(Block, Module)(named=initial_named, array=jax.numpy.ones(Block.size), static=1)
|
|
92
|
+
|
|
93
|
+
x = hax.random.uniform(jax.random.PRNGKey(1), (E,))
|
|
94
|
+
y, intermediates = m.scan(x, key=jax.random.split(jax.random.PRNGKey(2), Block.size))
|
|
95
|
+
|
|
96
|
+
assert y.axes == (E,)
|
|
97
|
+
assert intermediates.axes == (Block, E)
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "1.4.dev310"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|