haliax 1.4.dev313__tar.gz → 1.4.dev315__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.dev313 → haliax-1.4.dev315}/PKG-INFO +1 -1
- haliax-1.4.dev315/src/haliax/__about__.py +1 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/src/haliax/core.py +1 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/src/haliax/jax_utils.py +1 -1
- {haliax-1.4.dev313 → haliax-1.4.dev315}/src/haliax/nn/scan.py +13 -3
- {haliax-1.4.dev313 → haliax-1.4.dev315}/tests/core_test.py +17 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/tests/test_scan.py +39 -1
- haliax-1.4.dev313/src/haliax/__about__.py +0 -1
- {haliax-1.4.dev313 → haliax-1.4.dev315}/.coveragerc +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/.flake8 +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/.github/workflows/publish_dev.yaml +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/.github/workflows/run_pre_commit.yaml +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/.github/workflows/run_quick_levanter_tests.yaml +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/.github/workflows/run_tests.yaml +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/.gitignore +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/.pre-commit-config.yaml +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/.readthedocs.yaml +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/CONTRIBUTING.md +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/LICENSE +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/README.md +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/docs/api.md +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/docs/broadcasting.md +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/docs/cheatsheet.md +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/docs/css/material.css +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/docs/css/mkdocstrings.css +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/docs/faq.md +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/docs/figures/data_parallel_mesh.png +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/docs/figures/data_parallel_mesh_replicated.png +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/docs/figures/device_mesh_1d.png +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/docs/figures/device_mesh_1d_zero.png +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/docs/figures/device_mesh_2d.png +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/docs/figures/device_mesh_2d_batch_partitioned.png +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/docs/figures/device_mesh_2d_data_replicated.png +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/docs/figures/device_mesh_2d_data_replicated_mlp_partitioned.png +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/docs/figures/device_mesh_2d_intermediate_fully_partitioned.png +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/docs/figures/device_mesh_2d_zero.png +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/docs/fp8.md +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/docs/hof.md +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/docs/index.md +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/docs/indexing.md +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/docs/matmul.md +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/docs/nn.md +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/docs/partitioning.md +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/docs/rearrange.ipynb +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/docs/rearrange.md +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/docs/requirements.txt +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/docs/tutorial.md +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/mkdocs.yml +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/pyproject.toml +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/src/haliax/__init__.py +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/src/haliax/_src/__init__.py +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/src/haliax/_src/compile_utils.py +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/src/haliax/_src/dot.py +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/src/haliax/_src/einsum.py +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/src/haliax/_src/fp8.py +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/src/haliax/_src/parsing.py +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/src/haliax/_src/rearrange.py +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/src/haliax/_src/util.py +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/src/haliax/axis.py +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/src/haliax/debug.py +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/src/haliax/hof.py +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/src/haliax/nn/__init__.py +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/src/haliax/nn/activations.py +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/src/haliax/nn/attention.py +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/src/haliax/nn/conv.py +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/src/haliax/nn/dropout.py +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/src/haliax/nn/embedding.py +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/src/haliax/nn/linear.py +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/src/haliax/nn/loss.py +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/src/haliax/nn/mlp.py +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/src/haliax/nn/normalization.py +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/src/haliax/nn/pool.py +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/src/haliax/ops.py +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/src/haliax/partitioning.py +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/src/haliax/quantization.py +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/src/haliax/random.py +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/src/haliax/specialized_fns.py +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/src/haliax/tree_util.py +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/src/haliax/types.py +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/src/haliax/util.py +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/src/haliax/wrap.py +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/tests/test_attention.py +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/tests/test_axis.py +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/tests/test_conv.py +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/tests/test_debug.py +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/tests/test_dot.py +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/tests/test_einsum.py +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/tests/test_fp8.py +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/tests/test_hof.py +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/tests/test_nn.py +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/tests/test_ops.py +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/tests/test_parsing.py +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/tests/test_partitioning.py +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/tests/test_pool.py +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/tests/test_random.py +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/tests/test_rearrange.py +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/tests/test_specialized_fns.py +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/tests/test_tree_util.py +0 -0
- {haliax-1.4.dev313 → haliax-1.4.dev315}/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.dev315
|
|
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.dev315"
|
|
@@ -952,6 +952,7 @@ def _compute_new_axes_and_slices_for_index(
|
|
|
952
952
|
# we allow this if it's a 0-d or 1-d array
|
|
953
953
|
if slice_.ndim == 0:
|
|
954
954
|
ordered_slices[axis_index] = slice_
|
|
955
|
+
kept_axes[axis_index] = False
|
|
955
956
|
elif slice_.ndim == 1:
|
|
956
957
|
# we allow this if it's a 1-d array, in which case we treat it as sugar for NamedArray(slice_, sliced-axis)
|
|
957
958
|
ordered_slices[axis_index] = haliax.named(slice_, axis_name(axis))
|
|
@@ -80,7 +80,7 @@ def filter_checkpoint(fun: Callable, *, prevent_cse: bool = True, policy: Option
|
|
|
80
80
|
|
|
81
81
|
|
|
82
82
|
def is_jax_array_like(x):
|
|
83
|
-
return hasattr(x, "shape") and hasattr(x, "dtype")
|
|
83
|
+
return hasattr(x, "shape") and hasattr(x, "dtype") # and not isinstance(x, haliax.NamedArray)
|
|
84
84
|
|
|
85
85
|
|
|
86
86
|
# adapted from jax but exposed so i can use it
|
|
@@ -102,7 +102,14 @@ class BlockSeq(eqx.Module, Generic[M]):
|
|
|
102
102
|
(block_args, block_kwargs) = haliax.tree_util.tree_map(
|
|
103
103
|
functools.partial(BlockSeq._slice_out, self.Block, i), (extra_args, extra_kwargs)
|
|
104
104
|
)
|
|
105
|
-
|
|
105
|
+
block_result = block(carry, *block_args, **block_kwargs)
|
|
106
|
+
if not isinstance(block_result, (tuple, list)) or len(block_result) != 2:
|
|
107
|
+
raise ValueError(
|
|
108
|
+
f"BlockSeq.scan expects the block to return a pair of (carry, extra), got {block_result}"
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
carry, extra = block_result
|
|
112
|
+
|
|
106
113
|
out.append(extra)
|
|
107
114
|
|
|
108
115
|
# TODO: do we want to stack the outputs?
|
|
@@ -124,8 +131,11 @@ class BlockSeq(eqx.Module, Generic[M]):
|
|
|
124
131
|
|
|
125
132
|
@staticmethod
|
|
126
133
|
def _slice_out(Block, i, x):
|
|
127
|
-
if haliax.is_named_array(x)
|
|
128
|
-
|
|
134
|
+
if haliax.is_named_array(x):
|
|
135
|
+
if haliax.selects_axis(x.axes, Block):
|
|
136
|
+
return x[Block, i]
|
|
137
|
+
else:
|
|
138
|
+
return x
|
|
129
139
|
elif haliax.jax_utils.is_jax_array_like(x):
|
|
130
140
|
return x[i]
|
|
131
141
|
else:
|
|
@@ -543,6 +543,23 @@ def test_index():
|
|
|
543
543
|
assert jnp.all(jnp.equal(named1[{"H": 0, "W": 0, "D": 0}], named1.array[0, 0, 0]))
|
|
544
544
|
|
|
545
545
|
|
|
546
|
+
def test_index_with_tracer():
|
|
547
|
+
H = Axis("H", 20)
|
|
548
|
+
W = Axis("W", 30)
|
|
549
|
+
D = Axis("D", 40)
|
|
550
|
+
named1 = hax.random.uniform(PRNGKey(0), (H, W, D))
|
|
551
|
+
|
|
552
|
+
@jax.jit
|
|
553
|
+
def f(idx):
|
|
554
|
+
return named1["H", idx]
|
|
555
|
+
|
|
556
|
+
idx = jnp.array([1, 2, 3])
|
|
557
|
+
assert jnp.all(jnp.equal(f(idx).array, named1.array[1:4, :, :]))
|
|
558
|
+
|
|
559
|
+
idx = jnp.array(0)
|
|
560
|
+
assert jnp.all(jnp.equal(f(idx).array, named1.array[0, :, :]))
|
|
561
|
+
|
|
562
|
+
|
|
546
563
|
def test_index_array_slices():
|
|
547
564
|
# fancier tests with array slices with named array args
|
|
548
565
|
H = Axis("H", 10)
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import equinox as eqx
|
|
2
2
|
import jax
|
|
3
|
+
import pytest
|
|
3
4
|
|
|
4
5
|
import haliax as hax
|
|
5
6
|
from haliax.nn.scan import BlockSeq, Stacked
|
|
@@ -66,9 +67,14 @@ def test_seq_and_stacked_give_same_results():
|
|
|
66
67
|
x = hax.random.uniform(jax.random.PRNGKey(1), (E,))
|
|
67
68
|
y = m.fold(x, key=jax.random.split(jax.random.PRNGKey(2), Block.size))
|
|
68
69
|
y_seq = m_seq.fold(x, key=jax.random.split(jax.random.PRNGKey(2), Block.size))
|
|
69
|
-
|
|
70
70
|
assert hax.all(hax.isclose(y, y_seq, atol=1e-5))
|
|
71
71
|
|
|
72
|
+
with pytest.raises(ValueError):
|
|
73
|
+
m.scan(x, key=jax.random.split(jax.random.PRNGKey(2), Block.size))
|
|
74
|
+
|
|
75
|
+
with pytest.raises(ValueError):
|
|
76
|
+
m_seq.scan(x, key=jax.random.split(jax.random.PRNGKey(2), Block.size))
|
|
77
|
+
|
|
72
78
|
|
|
73
79
|
def test_using_scan():
|
|
74
80
|
class Module(eqx.Module):
|
|
@@ -95,3 +101,35 @@ def test_using_scan():
|
|
|
95
101
|
|
|
96
102
|
assert y.axes == (E,)
|
|
97
103
|
assert intermediates.axes == (Block, E)
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def test_scan_with_aux_named_args():
|
|
107
|
+
class Module(eqx.Module):
|
|
108
|
+
named: hax.NamedArray
|
|
109
|
+
array: jax.Array
|
|
110
|
+
static: int = eqx.static_field()
|
|
111
|
+
|
|
112
|
+
def __call__(self, x, y, *, key):
|
|
113
|
+
return x + self.array + self.static + hax.random.normal(key, x.axes), x * 2 + y
|
|
114
|
+
|
|
115
|
+
@staticmethod
|
|
116
|
+
def init(named, array, static):
|
|
117
|
+
return Module(named=named, array=array, static=static)
|
|
118
|
+
|
|
119
|
+
Block = hax.Axis("block", 4)
|
|
120
|
+
E = hax.Axis("E", 10)
|
|
121
|
+
|
|
122
|
+
initial_named = hax.random.uniform(jax.random.PRNGKey(0), (Block, E))
|
|
123
|
+
initial_y = hax.random.uniform(jax.random.PRNGKey(1), (E,))
|
|
124
|
+
|
|
125
|
+
m = Stacked.init(Block, Module)(named=initial_named, array=jax.numpy.ones(Block.size), static=1)
|
|
126
|
+
m_seq = BlockSeq.init(Block, Module)(named=initial_named, array=jax.numpy.ones(Block.size), static=1)
|
|
127
|
+
|
|
128
|
+
x = hax.random.uniform(jax.random.PRNGKey(1), (E,))
|
|
129
|
+
z, z_scan = m.scan(x, initial_y, key=jax.random.split(jax.random.PRNGKey(2), Block.size))
|
|
130
|
+
z_seq, z_seq_scan = m_seq.scan(x, initial_y, key=jax.random.split(jax.random.PRNGKey(2), Block.size))
|
|
131
|
+
assert hax.all(hax.isclose(z, z_seq, atol=1e-5))
|
|
132
|
+
|
|
133
|
+
z_seq_scan = hax.stack(Block, z_seq_scan)
|
|
134
|
+
|
|
135
|
+
assert hax.all(hax.isclose(z_scan, z_seq_scan, atol=1e-5))
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "1.4.dev313"
|
|
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
|