Skip to content

make mxfp8 dim1 cast kernel configurable #1427

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 25, 2025
Merged
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
31 changes: 20 additions & 11 deletions torchtitan/components/quantization/mx.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,30 +40,39 @@ def __init__(self, job_config: JobConfig, parallel_dims: ParallelDims):
"torchao is not installed. Please install it to use MXFP8 linear layers."
)
torchao_version = version("torchao")
mxfp8_min_version = "0.11.0"
if torchao_version < mxfp8_min_version:

# Last torchao release was 0.12.0, so nightly build starts with 0.13.0+git...
is_nightly_build = torchao_version.startswith("0.13.0")
if not is_nightly_build:
raise ImportError(
f"torchao version {torchao_version} is too old, please install torchao {mxfp8_min_version} or later and try again"
f"torchao version {torchao_version} is too old, please install torchao nightly build and try again"
)

# Can be removed if we enable the emulated versions
assert has_cuda_capability(
10, 0
), "MXFP8 is only supported on SM100 or architectures"

self.enabled = True
mx_job_config: MX = job_config.mx
self.filter_fqns = mx_job_config.filter_fqns
# TP not yet supported with torch.compile
assert not (
job_config.training.compile
and job_config.parallelism.tensor_parallel_degree > 1
), "TP not yet supported with torch.compile for mxfp8"

# Configure MXFP8
from torchao.prototype.mx_formats.config import MXLinearConfig
from torchao.prototype.mx_formats.config import (
MXFP8Dim1CastKernelChoice,
MXLinearConfig,
)

mx_job_config: MX = job_config.mx
config = MXLinearConfig.from_recipe_name(NAME_MAP[mx_job_config.recipe_name])
config.use_fp8_dim1_cast_triton_kernel = (
mx_job_config.use_fp8_dim1_cast_triton_kernel
)
config.mxfp8_dim1_cast_kernel_choice = MXFP8Dim1CastKernelChoice[
mx_job_config.mxfp8_dim1_cast_kernel_choice.upper()
]
self.filter_fqns = mx_job_config.filter_fqns
self.config = config

self.enabled = True
logger.info(f"Float8 training active with recipe {mx_job_config.recipe_name}")

def convert(self, model: nn.Module):
Expand Down
2 changes: 1 addition & 1 deletion torchtitan/config/job_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ class Float8:

@dataclass
class MX:
use_fp8_dim1_cast_triton_kernel: bool = True
mxfp8_dim1_cast_kernel_choice: Literal["triton", "cuda", "torch"] = "triton"
"""Temp work around for inductor performance gap"""

recipe_name: Literal["mxfp8"] = "mxfp8"
Expand Down
Loading