Skip to content

Add grouped_mm kernel wrapper - #707

Merged
AkshitaB merged 3 commits into
akshitab/moe-v2-corefrom
akshitab/moe-grouped-mm
Jun 6, 2026
Merged

AkshitaB merged 3 commits into
akshitab/moe-v2-corefrom
akshitab/moe-grouped-mm

Conversation

@AkshitaB

@AkshitaB AkshitaB commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

What this adds

olmo_core.kernels.grouped_mm — a thin wrapper over torch.nn.functional.grouped_mm (ragged/grouped matmul indexed by an offs tensor) that adds two caller-provided buffers:

  • out= — write the forward result in place into a preallocated tensor and return it.
  • input_grad_out= — write grad(mat_a) into a preallocated buffer during backward.

These let callers reuse preallocated forward/backward buffers and avoid extra allocations in hot loops. Ships cuda/grouped_mm_out.cpp for the in-place output path, loaded lazily via load_cuda_extension, and exports grouped_mm from olmo_core.kernels.

Import-safety / testing

Pure-Python wrapper; the CUDA extension builds lazily on first use, so the module is import-safe on CPU (no GPU or compiler needed to import). Correctness is covered by GPU tests on hardware.

@AkshitaB
AkshitaB force-pushed the akshitab/moe-grouped-mm branch from f4fd5e6 to 2598fd9 Compare June 5, 2026 19:00
Base automatically changed from akshitab/moe-cuda-extension-loader to akshitab/moe-v2-core June 5, 2026 19:09
@AkshitaB
AkshitaB force-pushed the akshitab/moe-grouped-mm branch from 0aaf4cd to 05f0824 Compare June 5, 2026 19:10
@AkshitaB
AkshitaB marked this pull request as ready for review June 5, 2026 19:10
@AkshitaB
AkshitaB force-pushed the akshitab/moe-grouped-mm branch 3 times, most recently from a60a182 to 3a44467 Compare June 5, 2026 22:58
TianhuaTao and others added 3 commits June 5, 2026 16:23
grouped_mm wraps torch.nn.functional.grouped_mm and adds two caller-provided buffers:
`out=` writes the forward result in place, and `input_grad_out=` writes the gradient of
the first input during backward. These let callers reuse preallocated buffers and avoid
extra allocations in hot loops. Includes cuda/grouped_mm_out.cpp for the in-place output
path; the CUDA extension builds lazily via load_cuda_extension, so the module is
import-safe on CPU.

Co-Authored-By: Akshita Bhagia <[email protected]>
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…fwd + bwd)

Add a GPU test that runs grouped_mm with no out=/input_grad_out= buffers and asserts
both the forward output and the gradients match torch.nn.functional.grouped_mm, i.e. the
custom autograd wrapper is a faithful drop-in in its default configuration.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Add a has_torch_grouped_mm capability flag and a requires_torch_grouped_mm test
decorator (gpu + skipif on torch.nn.functional.grouped_mm availability), mirroring the
existing requires_grouped_gemm pattern. This is distinct from has_grouped_gemm, which
checks for the third-party grouped_gemm package. Gate the grouped_mm wrapper tests with
it so they skip cleanly on torch < 2.10 instead of erroring.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@AkshitaB
AkshitaB force-pushed the akshitab/moe-grouped-mm branch from 00ed3ee to 2110d9b Compare June 5, 2026 23:23
@AkshitaB
AkshitaB merged commit 0424de4 into akshitab/moe-v2-core Jun 6, 2026
87 of 93 checks passed
@AkshitaB
AkshitaB deleted the akshitab/moe-grouped-mm branch June 6, 2026 00:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants