Skip to main content

Triton GPU-only grouped_mm (BF16) matching PyTorch grouped_mm semantics.

Project description

grouped_mm_bf16 (Triton)

Install

  1. Install PyTorch for your system (CUDA / ROCm / CPU): https://pytorch.org/get-started/locally/

  2. Install this package (and Triton):

pip install grouped-mm-bf16[triton]

Usage

import torch
from grouped_mm_bf16 import grouped_mm

dev = "cuda"

# 3D x 3D (batched matmul): [G,M,K] @ [G,K,N] -> [G,M,N]
a = torch.randn((4, 32, 64), device=dev, dtype=torch.bfloat16)
b = torch.randn((4, 64, 48), device=dev, dtype=torch.bfloat16)
out = grouped_mm(a, b)

# 2D x 3D with offsets: [M_total,K] @ [G,K,N] -> [M_total,N]
sizes = torch.tensor([0, 7, 1, 13, 0, 11], device=dev, dtype=torch.int32)
offs = sizes.cumsum(0)  # group end indices along M_total
a = torch.randn((int(offs[-1].item()), 64), device=dev, dtype=torch.bfloat16)
b = torch.randn((sizes.numel(), 64, 48), device=dev, dtype=torch.bfloat16)
out = grouped_mm(a, b, offs=offs)

About

Universal (NVIDIA CUDA + AMD HIP) Triton implementation of torch.nn.functional.grouped_mm semantics for BF16.

This repo provides grouped_mm_bf16.grouped_mm(...), mirroring the private operator signature:

grouped_mm(mat_a, mat_b, offs=None, bias=None, out_dtype=None) -> Tensor

Notes:

  • GPU-only: raises if any inputs are on CPU; never falls back to CPU.
  • Matches PyTorch grouped_mm shape semantics (2D/3D + offs) and dtype rules.
  • bias is rejected, matching current PyTorch behavior (Bias not supported yet).
  • Like PyTorch's current CUDA implementation, inputs must have "valid" (row/column-major) strides and 16-byte alignment; contiguous matrices with odd inner dimensions may need padding.

GitHub CI + PyPI publishing

This repo includes:

  • CI workflow: .github/workflows/ci.yml (builds sdist/wheel + twine check)
  • Publish to PyPI workflow: .github/workflows/publish.yml (uses PyPI “Trusted Publisher” / OIDC)

To enable PyPI GitHub integration (recommended: no API token in GitHub secrets):

  1. Create the project on PyPI (first manual upload is fine).
  2. PyPI → your project → SettingsPublishingAdd a trusted publisher.
  3. Select GitHub Actions, then set:
    • Owner: lostmsu
    • Repository: grouped_mm_bf16
    • Workflow name/path: .github/workflows/publish.yml
    • Environment: (leave empty unless you want to require a GitHub Environment)
  4. Create a GitHub Release (or run the workflow manually via workflow_dispatch).

Notes:

  • For TestPyPI, you need to configure a trusted publisher on TestPyPI separately, and then run the workflow manually with repository=testpypi.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

grouped_mm_bf16-0.1.1.tar.gz (15.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

grouped_mm_bf16-0.1.1-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

Details for the file grouped_mm_bf16-0.1.1.tar.gz.

File metadata

  • Download URL: grouped_mm_bf16-0.1.1.tar.gz
  • Upload date:
  • Size: 15.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for grouped_mm_bf16-0.1.1.tar.gz
Algorithm Hash digest
SHA256 1d3d99b57fa2dbdb9332209f54857548836ff261180635c742f1af16ffaf125a
MD5 8f2d109bc88bd67d52ce7ca65e9ac062
BLAKE2b-256 bfbec4f85b48154cee00529bdbe6405b6cd364dde5390b3bcd70253704dacab2

See more details on using hashes here.

File details

Details for the file grouped_mm_bf16-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for grouped_mm_bf16-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d80d4d54eaa19ed8bb0a575d0103e2366d05dba4de4ab0aef55aa46256460490
MD5 91b786b5a3ad7680c9970fa9b94559f7
BLAKE2b-256 f67512f958f9daedcf4c81ac6fb9568a9e341cdbbb7da73df72ab6294aadbe06

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page