Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/ci/shards.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,8 @@ class Spec(_RequiredSpec, total=False):
'tokamax/_src/ops/experimental/kda/pallas_mosaic_tpu_remat_test.py',
'tokamax/_src/ops/experimental/kda/pallas_mosaic_tpu_packed_bwd_test.py',
'tokamax/_src/ops/experimental/kda/pallas_mosaic_tpu_packed_gradients_test.py',
'tokamax/_src/ops/experimental/kda/pallas_mosaic_tpu_cp_fused_test.py',
'tokamax/_src/ops/experimental/kda/pallas_mosaic_tpu_cp_megakernel_test.py',
'tokamax/_src/ops/experimental/kda/pallas_mosaic_tpu_bwd_fused_test.py',
),
minutes=16,
Expand Down
10 changes: 9 additions & 1 deletion tokamax/_src/ops/experimental/kda/pallas_mosaic_tpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ class Config:
normalization backward; beta retains its existing gather.
`fuse_backward=True` also fuses the non-CP saved-state backward. Manual
state rematerialization is fused separately with `fuse_rematerialization=True`;
CP retains its existing backward path.
`fuse_cp_backward=True` fuses the saved-state local reverse pass after
CP communication. With `fuse_rematerialization=True`, this also applies
to CP rematerialization, preserving its staged state reconstruction.
`cp_megakernel=True` selects the full CP core (including remote DMA)
instead, for 128-aligned K/V. It is opt-in pending TPU validation.
"""

chunk_size: Annotated[int, pydantic.Field(gt=0)] = 64
Expand All @@ -79,6 +83,8 @@ class Config:
packed_backward: bool = False
packed_gradients: bool = False
fuse_backward: bool = True
fuse_cp_backward: bool = False
cp_megakernel: bool = False
# Opt-in until TPU compilation and device-time validation completes.
fuse_rematerialization: bool = False

Expand Down Expand Up @@ -578,6 +584,8 @@ def _fwd(
fuse_rematerialization=config.fuse_rematerialization,
packed_inputs=packed_inputs,
packed_gradients=config.packed_gradients,
fuse_cp_backward=config.fuse_cp_backward,
cp_megakernel=config.cp_megakernel,
)

grads = {
Expand Down
Loading