Skip to content

various fixes #2133

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

Closed
wants to merge 2 commits into from
Closed
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
32 changes: 32 additions & 0 deletions test/prototype/mx_formats/test_mx_linear.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
MXInferenceLinear,
MXLinear,
)
from torchao.prototype.mx_formats.mx_subclass import MXFPConfig
from torchao.quantization import quantize_
from torchao.quantization.utils import compute_error
from torchao.utils import (
Expand Down Expand Up @@ -372,3 +373,34 @@ def test_inference_print_str():
s = str(m)
assert "bl_sz=32" in s
assert "kernel=emulated" in s


@pytest.mark.skipif(not torch.cuda.is_available(), reason="CUDA not available")
@pytest.mark.skipif(
not TORCH_VERSION_AT_LEAST_2_8, reason="torch.compile requires PyTorch 2.8+"
)
@pytest.mark.skipif(not is_sm_at_least_100, reason="Reqs sm100")
@pytest.mark.parametrize("elem_dtype", [torch.float8_e4m3fn])
@pytest.mark.parametrize("bias", [True, False])
@pytest.mark.parametrize("compile", [True, False])
@torch.no_grad()
def test_inference_subclass(elem_dtype, bias: bool, compile: bool):
"""
Smoke test for inference compile
"""
if elem_dtype in (torch.float8_e4m3fn, torch.float8_e5m2):
if not is_sm_at_least_89():
pytest.skip("CUDA capability >= 8.9 required for float8 in triton")

m = nn.Linear(32, 128, bias=bias, dtype=torch.bfloat16, device="cuda")
m_mx = copy.deepcopy(m)
config = MXFPConfig()
quantize_(m_mx, config=config)
if compile:
m_mx = torch.compile(m_mx, fullgraph=True)

x = torch.randn(128, 32, device="cuda", dtype=torch.bfloat16)
y_ref = m(x)
y_mx = m_mx(x)
sqnr = compute_error(y_ref, y_mx)
assert sqnr >= 25.0, f"Got a sqnr of {sqnr} for {elem_dtype} and bias={bias}"
3 changes: 2 additions & 1 deletion torchao/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
quantize_,
)

from . import dtypes, optim, swizzle, testing
from . import dtypes, optim, quantization, swizzle, testing

__all__ = [
"dtypes",
Expand All @@ -53,4 +53,5 @@
"swizzle",
"testing",
"ops",
"quantization",
]
1 change: 1 addition & 0 deletions torchao/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ def config_to_dict(config: AOBaseConfig) -> Dict[str, Any]:
"torchao.quantization",
"torchao.sparsity.sparse_api",
"torchao.prototype.quantization",
"torchao.prototype.mx_formats",
}


Expand Down
2 changes: 2 additions & 0 deletions torchao/prototype/mx_formats/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
MXLinearConfig,
MXLinearRecipeName,
)
from torchao.prototype.mx_formats.mx_subclass import MXFPConfig

# import mx_linear here to register the quantize_ transform logic
# ruff: noqa: I001
Expand All @@ -14,4 +15,5 @@
"MXInferenceLinearConfig",
"MXLinearConfig",
"MXLinearRecipeName",
"MXFPConfig",
]
Loading
Loading