Skip to content

Commit 3527353

Browse files
Merge pull request #2527 from AI-Hypercomputer:chengnuojin-shardmap
PiperOrigin-RevId: 821821291
2 parents cff6edc + cc5053f commit 3527353

4 files changed

Lines changed: 12 additions & 16 deletions

File tree

pedagogical_examples/shmap_collective_matmul.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
from jax.experimental.pjit import pjit
3030
from jax.sharding import PartitionSpec as P
3131
from jax.sharding import Mesh
32-
from jax.experimental.shard_map import shard_map
3332

3433
MESH_DATA_AXIS = "dp"
3534
MESH_FSDP_AXIS = "fsdp"
@@ -103,14 +102,14 @@ def matmul(activations, weights): # pylint: disable=redefined-outer-name
103102

104103

105104
@partial(
106-
shard_map,
105+
jax.shard_map,
107106
mesh=global_mesh,
108107
in_specs=(
109108
P(MESH_FSDP_AXIS, MESH_TENSOR_AXIS, None),
110109
P(MESH_FSDP_AXIS, MESH_TENSOR_AXIS, None),
111110
),
112111
out_specs=P(MESH_FSDP_AXIS, None, MESH_TENSOR_AXIS, None),
113-
check_rep=False,
112+
check_vma=False,
114113
)
115114
def collective_matmul(activations, weights): # pylint: disable=redefined-outer-name
116115
"""Collective matrix multiply"""

src/MaxText/inference/paged_attention.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
import jax
2323
import jax.numpy as jnp
24-
from jax.experimental.shard_map import shard_map
2524
from jax.experimental.pallas.ops.tpu.paged_attention import paged_attention_kernel
2625
from jax.sharding import PartitionSpec as P
2726
from jax.sharding import Mesh
@@ -327,7 +326,7 @@ def paged_attention_v1_decode(
327326
q_pspec = nn.logical_to_mesh_axes((None, None, "paged_kv_heads", None))
328327

329328
@functools.partial(
330-
shard_map,
329+
jax.shard_map,
331330
mesh=self.mesh,
332331
in_specs=(
333332
q_pspec,
@@ -338,7 +337,7 @@ def paged_attention_v1_decode(
338337
None,
339338
),
340339
out_specs=q_pspec,
341-
check_rep=False,
340+
check_vma=False,
342341
)
343342
def wrap_paged_attention(q, k_pages, v_pages, lengths, page_indices, pages_per_compute_block):
344343
q = jnp.squeeze(q, axis=1)

src/MaxText/layers/attention_op.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
from jax.experimental.pallas.ops.gpu import decode_attention as gpu_pallas_decode_attention
2929
from jax.experimental.pallas.ops.tpu.splash_attention import splash_attention_kernel
3030
from jax.experimental.pallas.ops.tpu.splash_attention import splash_attention_mask
31-
from jax.experimental.shard_map import shard_map
3231
from jax.sharding import Mesh
3332
import jax
3433
import jax.numpy as jnp
@@ -946,11 +945,11 @@ def gpu_ragged_attention(self, q: Array, k: Array | KVTensor, v: Array | KVTenso
946945
bn = nn.logical_to_mesh_axes((CACHE_BATCH, CACHE_HEADS))
947946

948947
@functools.partial(
949-
shard_map,
948+
jax.shard_map,
950949
mesh=self.mesh,
951950
in_specs=(bnd, bsnd, bsnd, b, None),
952951
out_specs=(bnd, bn, bn),
953-
check_rep=False,
952+
check_vma=False,
954953
)
955954
def wrap_ragged_attention(
956955
q: Array, k: Array, v: Array, lengths: Array, block_size: int
@@ -1000,7 +999,7 @@ def tpu_ragged_attention(
1000999
bsnd = nn.logical_to_mesh_axes(self.cache_logical_axis_names)
10011000

10021001
@functools.partial(
1003-
shard_map,
1002+
jax.shard_map,
10041003
mesh=self.mesh,
10051004
in_specs=(
10061005
bsnd,
@@ -1010,7 +1009,7 @@ def tpu_ragged_attention(
10101009
None,
10111010
),
10121011
out_specs=bsnd,
1013-
check_rep=False,
1012+
check_vma=False,
10141013
)
10151014
def wrap_ragged_attention(query, key, value, lengths, block_size):
10161015
if query.shape[-2] == key.shape[-2]:
@@ -1162,7 +1161,7 @@ def wrap_splash_kernel(multi_head_mask, shard_head_size=1):
11621161
# 'segment_axis_names_kv' maps to ['activation_kv_length', []] meaning that K and V are not sharded
11631162
# splash_kernel is sharded over (HEAD, LENGTH)
11641163
@functools.partial(
1165-
shard_map,
1164+
jax.shard_map,
11661165
mesh=self.mesh,
11671166
in_specs=(
11681167
axis_names_q,
@@ -1176,7 +1175,7 @@ def wrap_splash_kernel(multi_head_mask, shard_head_size=1):
11761175
sink_axis_names, # sharding align with query heads
11771176
),
11781177
out_specs=axis_names_q,
1179-
check_rep=False,
1178+
check_vma=False,
11801179
)
11811180
def wrap_flash_attention(
11821181
query,

src/MaxText/layers/moe.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
from flax import nnx
2626
import jax
2727
from jax import ad_checkpoint as adc
28-
from jax.experimental import shard_map
2928
from jax.experimental import xla_metadata
3029
import jax.numpy as jnp
3130
import numpy as np
@@ -908,7 +907,7 @@ def gmm(inputs, kernel, tiling, group_sizes, expert_assignments):
908907
wo_pspec = aqt.partition_spec(wo_pspec, (1,), wo_kernel.dtype, use_bias=False)
909908

910909
@functools.partial(
911-
shard_map.shard_map,
910+
jax.shard_map,
912911
mesh=self.mesh,
913912
in_specs=(
914913
input_partition_pspec,
@@ -923,7 +922,7 @@ def gmm(inputs, kernel, tiling, group_sizes, expert_assignments):
923922
None,
924923
),
925924
out_specs=(nn.logical_to_mesh_axes((batch_logical_axis, "activation_norm_length", "activation_embed"))),
926-
check_rep=False,
925+
check_vma=False,
927926
)
928927
def wrapper(x, logits, pre_bias_logits, w0, w1, wo, w0_bias, w1_bias, wo_bias, rngs):
929928
batch_size, sequence_length, _ = x.shape

0 commit comments

Comments
 (0)