haliax 1.4.dev332__py3-none-any.whl → 1.4.dev334__py3-none-any.whl

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/__about__.py CHANGED
@@ -1 +1 @@
1
- __version__ = "1.4.dev332"
1
+ __version__ = "1.4.dev334"
haliax/_src/state_dict.py CHANGED
@@ -395,7 +395,7 @@ def flatten_linear_layers(tree: T) -> T:
395
395
  new_In: Axis = flatten_axes(layer.In, "__IN__")
396
396
 
397
397
  if weight.array is not None:
398
- out_first = layer.out_first
398
+ out_first = layer._out_first
399
399
  weight = weight.flatten_axes(layer.Out, new_Out).flatten_axes(layer.In, new_In)
400
400
 
401
401
  if out_first:
haliax/axis.py CHANGED
@@ -35,6 +35,8 @@ def make_axes(**kwargs: int) -> Tuple[Axis, ...]:
35
35
  Example:
36
36
  ```
37
37
  X, Y = axes(X=10, Y=20)
38
+ ```
39
+
38
40
  """
39
41
  return tuple(Axis(name, size) for name, size in kwargs.items())
40
42
 
haliax/nn/embedding.py CHANGED
@@ -24,26 +24,60 @@ class Embedding(eqx.Module):
24
24
 
25
25
  @staticmethod
26
26
  def init(Vocab: Axis, Embed: AxisSpec, *, init_scale: float = 1, key, initializer_range: Optional[float] = None):
27
+ """
28
+ Initialize an Embedding module.
29
+
30
+ An embedding module is a simple lookup table that maps integer indices to vectors or tensors.
31
+ Weights are initialized with a truncated normal distribution with a standard deviation of
32
+ `init_scale / output_size`.
33
+
34
+ Args:
35
+ Vocab: Size of the vocabulary
36
+ Embed: Shape of the embedding vectors. May be a single axis or a full AxisSpec
37
+ init_scale: Scale of the initialization
38
+ key: PRNG key
39
+ initializer_range: Deprecated. Use init_scale instead.
40
+ """
27
41
  if initializer_range is not None:
28
42
  warnings.warn("initializer_range is deprecated. Use init_std instead.", DeprecationWarning)
29
43
  init_scale = initializer_range
30
44
 
31
45
  all_axes = (Vocab,) + ensure_tuple(Embed)
32
46
  output_size = hax.axis_size(Embed)
33
- weight = hax.random.truncated_normal(key, all_axes, -3, 3) * (init_scale / math.sqrt(output_size))
47
+ weight = hax.random.truncated_normal(key, all_axes, -3, 3) * (init_scale / output_size)
34
48
  return Embedding(weight=weight, Vocab=Vocab, Embed=Embed)
35
49
 
36
- def __call__(self, input_ids, *, key: Optional[PRNGKeyArray] = None):
50
+ def __call__(self, input_ids: NamedArray, *, key: Optional[PRNGKeyArray] = None):
51
+ """Alias for `embed`. key is ignored."""
37
52
  return self.embed(input_ids)
38
53
 
39
54
  @named_call
40
- def embed(self, input_ids):
55
+ def embed(self, input_ids: NamedArray):
56
+ """
57
+ Args:
58
+ input_ids: token IDs with shape > {Vocab}
59
+ """
41
60
  input_embeds = self.weight.take(self.Vocab, input_ids)
42
61
  return input_embeds
43
62
 
44
- def unembed(self, input_embeds):
63
+ def unembed(self, input_embeds: NamedArray):
64
+ """
65
+ Unembed the input embeddings back to the vocabulary space.
66
+
67
+ Equivalent to `input_embeds.dot(self.weight, axis=self.Embed)`.
68
+ """
45
69
  return input_embeds.dot(self.weight, axis=self.Embed)
46
70
 
47
71
  def resize_embeddings(self, new_size: int, key: Optional[PRNGKeyArray] = None):
72
+ """
73
+ Resize the embedding layer to a new size.
74
+ Args:
75
+ new_size: New size of the vocabulary
76
+ key: PRNG key for initialization of any new weights
77
+
78
+ Returns:
79
+ Embedding: Resized embedding layer
80
+
81
+ """
48
82
  new_weights = resize_axis(self.weight, self.Vocab, new_size, key=key)
49
83
  return dataclasses.replace(self, Vocab=self.Vocab.resize(new_size), weight=new_weights) # type: ignore
haliax/nn/linear.py CHANGED
@@ -72,7 +72,10 @@ class Linear(eqx.Module):
72
72
  return q
73
73
 
74
74
  @property
75
- def out_first(self):
75
+ def _out_first(self):
76
+ """
77
+ Returns: bool: Whether the output axes are first in the weight matrix
78
+ """
76
79
  # We do it this way because of scan layers
77
80
  if isinstance(self.Out, hax.Axis):
78
81
  return self.weight.axes[-1] != self.Out
@@ -58,6 +58,9 @@ def logsumexp(a: A, axis: Optional[AxisSelection] = None) -> A:
58
58
  return wrap_reduction_call(jnn.logsumexp, a, axis=axis, single_axis_only=False, supports_where=False)
59
59
 
60
60
 
61
+ # TODO: support where in softmax, etc
62
+
63
+
61
64
  def softmax(a: A, axis: Optional[AxisSelection] = None) -> A:
62
65
  return wrap_axiswise_call(jnn.softmax, a, axis=axis, single_axis_only=False)
63
66
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: haliax
3
- Version: 1.4.dev332
3
+ Version: 1.4.dev334
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/
@@ -1,6 +1,6 @@
1
- haliax/__about__.py,sha256=1Bc7sSYtp49Iv6Rc1ZOV2dLFJ-vdQxZRlu4f9wKlkYg,27
1
+ haliax/__about__.py,sha256=QmiPi6dv5hegVnrb07SVyu_ESGszJnp91zXeTEgMyZA,27
2
2
  haliax/__init__.py,sha256=CQHrLfNXSO8hd27zqqzDeJP6Vzls_BKAE65VA48wlAc,29075
3
- haliax/axis.py,sha256=U8Ugd2d-u55RoQQqRiITKm1mzsZkDh3rThfAgkTWOwo,20757
3
+ haliax/axis.py,sha256=tEfVlIqFzJRYfMVtHNw_iM68Otehzlb9cGRLFcrXr_s,20766
4
4
  haliax/core.py,sha256=d-9nppDP_-IcxF1yHXDzzVNbP7WIadA1ojb3xHP_-SQ,71000
5
5
  haliax/debug.py,sha256=0qEGgIsEw3Jkp40oxgBAjD0Ps-cxi3QNP42uMRGlM84,3612
6
6
  haliax/hof.py,sha256=jDcii2IwAfhoNYTCYsdeS8vpSKmtzioPKZ6LBAVuWn8,18205
@@ -22,21 +22,21 @@ haliax/_src/einsum.py,sha256=IXBynFdGYFYP3kbNjQfQLovqwjhNeDAoDnUiEqATV0I,15410
22
22
  haliax/_src/fp8.py,sha256=wtyOK7TrXgg4UlwydDklCMXvkbGMoixB3mKOk3IIJvM,4951
23
23
  haliax/_src/parsing.py,sha256=9JDE3unCjS8AN_B5kiAy1yV0AemYW0jL8A_T_bdcLHs,11189
24
24
  haliax/_src/rearrange.py,sha256=SWZAIMSrqQzqwZDxrMk25q6IOaK4PyDUEm-VOSe0N18,19498
25
- haliax/_src/state_dict.py,sha256=YcOtA_7B99_0VYBI1-WLHb4ZcxIfxQ1f1UyollTXlPI,17276
25
+ haliax/_src/state_dict.py,sha256=hKE0EVPN4zXvyBM40FyUSrmvd88SUFqCJ7ZLb4ZqNy4,17277
26
26
  haliax/_src/util.py,sha256=pXizGeJfRcx7QA1YVAxvru2EnMGIXAhZdcPGkwatP_M,1566
27
27
  haliax/nn/__init__.py,sha256=WeiO9JGBK-Am0NZ-s2UW7OmR4cFZbQAakuTDcMMnLg4,2875
28
28
  haliax/nn/activations.py,sha256=9h1uJ2pUWmb_OsRhqUGUJ6s95WZgxABDx7YWFD2tn5A,1723
29
29
  haliax/nn/attention.py,sha256=5P6IvQ5G-hpStKFnZ4mEV379Af6pkCyIA0qWXMM3Ed4,11942
30
30
  haliax/nn/conv.py,sha256=ozdvYBnb20CDz_xMKiXdpOW0ZMBZKlwadx21XafFw3E,15131
31
31
  haliax/nn/dropout.py,sha256=2BETs0MeHMdzUuGof3vdVRZSwC7vQwKP9BT-Ix0lDRY,3682
32
- haliax/nn/embedding.py,sha256=RfNNO2GZim7o0pxqzhpwv9JcPLAArEXKvKwi8mt0tQo,1687
33
- haliax/nn/linear.py,sha256=DQH4YdoQ4nOPpXihSZfPuoidIMQheTCp3aGDKksc7Ww,2722
32
+ haliax/nn/embedding.py,sha256=e-U3U7-nI0puNPLr-e-LH_-GfplgIuTHHGUzqMAsr-U,2880
33
+ haliax/nn/linear.py,sha256=21sorQpSjg4zPMG3-SHg7mqyAg86E5QKI3bxdSuw-Ag,2825
34
34
  haliax/nn/loss.py,sha256=OsXpiidiKOD6gslXC54hywn9qm3shH9qyhx8baaps0Y,4565
35
35
  haliax/nn/mlp.py,sha256=KW_7phxbt0C8CLEVahP5Zoq4SQruiGyg7ltRvLrTdPg,3695
36
- haliax/nn/normalization.py,sha256=4e1rpVvZKW9w5eUsn8j0tBF6lAIs5YljsvOE_HaoOD8,2652
36
+ haliax/nn/normalization.py,sha256=jjPVrs2wBlaK47WwaAm18Y53EnREvy6HLpAgtdqCajI,2692
37
37
  haliax/nn/pool.py,sha256=DHeswGramsqNvYufl36NbwgWgI-Iht9bnJy170Pwfu0,8530
38
38
  haliax/nn/scan.py,sha256=cm5GHVjdv8nWKKlo9hHzlyoj0Ubq9770EgqsdbUc7Z0,29163
39
- haliax-1.4.dev332.dist-info/METADATA,sha256=Qcs512OIq18GGpSwTgAhbstqbxdVfhfm5RjuueAYPoA,7663
40
- haliax-1.4.dev332.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
41
- haliax-1.4.dev332.dist-info/licenses/LICENSE,sha256=bJiay7Nn5SHQ2n_4ZIT3AE0W1RGq4O7pxOApgBsaT64,11349
42
- haliax-1.4.dev332.dist-info/RECORD,,
39
+ haliax-1.4.dev334.dist-info/METADATA,sha256=u8d5xnDqZtYJq6Bx1caefXQ45_e8pXpPydwjCAy0ykg,7663
40
+ haliax-1.4.dev334.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
41
+ haliax-1.4.dev334.dist-info/licenses/LICENSE,sha256=bJiay7Nn5SHQ2n_4ZIT3AE0W1RGq4O7pxOApgBsaT64,11349
42
+ haliax-1.4.dev334.dist-info/RECORD,,