Skip to content

[xpu][test] Enable int8 mixed-precision training tests (test/prototype/test_quantized_training.py) and register scaled_int8_mm for XPU - #4630

Open
karol-brejna-i wants to merge 4 commits into
pytorch:mainfrom
karol-brejna-i:dev/kbrejna/xpu/scaled-int8-mm-xpu
Open

karol-brejna-i wants to merge 4 commits into
pytorch:mainfrom
karol-brejna-i:dev/kbrejna/xpu/scaled-int8-mm-xpu

Conversation

@karol-brejna-i

@karol-brejna-i karol-brejna-i commented Jul 28, 2026 •

Copy link
Copy Markdown

What

The PR consists of two parts.

1. Make test_int8_mixed_precision_training and test_bitnet_training (in test/prototype/test_quantized_training.py) accelerator-generic:

  • @pytest.mark.skipif(not torch.cuda.is_available(), ...) →
    @pytest.mark.skipif(not torch.accelerator.is_available(), reason="GPU not available")
  • device = "cuda" → device = get_current_accelerator_device()

The tests use scaled_int8_mm, which need to be properly registered for XPU.

2. Register the existing Triton kernel under the XPU dispatch key in
torchao/prototype/quantized_training/int8_mm.py:

 @torch.library.impl(lib, "scaled_int8_mm", "CUDA")
-def scaled_int8_mm_cuda(A: Tensor, B: Tensor, row_scale: Tensor, col_scale: Tensor):
+@torch.library.impl(lib, "scaled_int8_mm", "XPU")
+def scaled_int8_mm_gpu(A: Tensor, B: Tensor, row_scale: Tensor, col_scale: Tensor):

Why

Both callers select the Triton path on any backend whenever torch.utils._triton.has_triton()
is true — which includes XPU, because the CI image installs pytorch-triton-xpu:

# torchao/prototype/quantized_training/int8_mixed_precision.py (and bitnet.py)
if has_triton():
    from .int8_mm import scaled_int8_mm
else:
    ...  # torch._int_mm fallback

So on XPU the op is called but has no XPU dispatch key — it raises NotImplementedError
instead of falling back to torch._int_mm.

Neither part is independently valid (kernel registration and UT enablement), hence one PR:

  • Kernel registration alone — nothing exercises it on XPU (tests are still CUDA-gated), so there is no evidence it works.
  • Test enablement alone — the test hits torch.ops.torchao.scaled_int8_mm and errors out, turning a silent skip into a red XPU failure.

Validation

Environment: Intel XPU node, Python 3.12, torch 2.14.0.dev20260729+xpu, pytorch-triton-xpu present, single card via ZE_AFFINITY_MASK=0.

Quick smoke test

python -c "
import torch, torchao
from torchao.prototype.quantized_training.int8_mm import scaled_int8_mm
A = torch.randint(-8, 8, (64, 64), dtype=torch.int8, device='xpu')
B = torch.randint(-8, 8, (64, 64), dtype=torch.int8, device='xpu')
s = torch.ones(64, device='xpu')
print(scaled_int8_mm(A, B, s, s).shape)"

Before (main):

NotImplementedError: Could not run 'torchao::scaled_int8_mm' with arguments from the 'XPU' backend

After (PR branch):

torch.Size([64, 64])

Full test — pytest -rs test/prototype/test_quantized_training.py

Result Before (main) After (PR branch)
passed 16 48
skipped 20 4
failed/error 0 0

16 test IDs move SKIPPED → PASSED: the full parametrization of test_int8_mixed_precision_training (compile × 4 Int8MixedPrecisionTrainingConfigs × module_swap), including the compile=True half, i.e. inductor-xpu. No test moves in the other direction.

CPU-only collection check

CPU-only collection is unaffected — checked explicitly:

CUDA_VISIBLE_DEVICES="" ZE_AFFINITY_MASK=99 pytest -q --collect-only test/prototype/test_quantized_training.py

Collection succeeds with the same test count as main. No regressions.

Notes

@pytorch-bot

pytorch-bot Bot commented Jul 28, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/ao/4630

Note: Links to docs will display an error until the docs builds have been completed.

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jul 28, 2026
@karol-brejna-i karol-brejna-i changed the title [xpu] Register scaled_int8_mm for XPU and enable int8 mixed-precision training tests [xpu] Enable test/prototype/test_quantized_training.py Jul 28, 2026
@karol-brejna-i karol-brejna-i changed the title [xpu] Enable test/prototype/test_quantized_training.py [xpu][test] Enable int8 mixed-precision training tests (test/prototype/test_quantized_training.py) and register scaled_int8_mm for XPU Jul 28, 2026
@xiaowangintel xiaowangintel added module: training quantize_ api training flow ciflow/xpu label used to trigger xpu CI jobs xpu Intel XPU related features labels Jul 29, 2026
@pytorch-bot

pytorch-bot Bot commented Jul 29, 2026 •

Copy link
Copy Markdown

The following ciflow label(s) have been added but CI has not been triggered yet because the workflows are awaiting approval:

  • ciflow/xpu

Once a maintainer approves the workflows (scroll to the bottom of the PR page), the corresponding CI jobs will be triggered automatically. Please ping one of the reviewers if you do not have access to approve and run workflows.

@liangan1 liangan1 added ciflow/xpu label used to trigger xpu CI jobs xpu Intel XPU related features and removed ciflow/xpu label used to trigger xpu CI jobs xpu Intel XPU related features labels Jul 31, 2026
@karol-brejna-i
karol-brejna-i marked this pull request as ready for review August 3, 2026 11:52
Comment thread test/prototype/test_quantized_training.py Outdated
@karol-brejna-i
karol-brejna-i force-pushed the dev/kbrejna/xpu/scaled-int8-mm-xpu branch 3 times, most recently from 8392a9d to f9ab78c Compare August 5, 2026 05:38
@liangan1 liangan1 added ciflow/xpu label used to trigger xpu CI jobs xpu Intel XPU related features and removed ciflow/xpu label used to trigger xpu CI jobs xpu Intel XPU related features labels Aug 5, 2026
@karol-brejna-i
karol-brejna-i force-pushed the dev/kbrejna/xpu/scaled-int8-mm-xpu branch from f9ab78c to 262b974 Compare August 20, 2026 15:21
@liangan1 liangan1 added ciflow/xpu label used to trigger xpu CI jobs and removed ciflow/xpu label used to trigger xpu CI jobs xpu Intel XPU related features labels Aug 20, 2026
@karol-brejna-i
karol-brejna-i force-pushed the dev/kbrejna/xpu/scaled-int8-mm-xpu branch from 262b974 to 6981b61 Compare September 8, 2026 16:02
@liangan1 liangan1 added ciflow/xpu label used to trigger xpu CI jobs xpu Intel XPU related features and removed ciflow/xpu label used to trigger xpu CI jobs xpu Intel XPU related features labels Sep 8, 2026
@karol-brejna-i
karol-brejna-i force-pushed the dev/kbrejna/xpu/scaled-int8-mm-xpu branch 2 times, most recently from 6387405 to 44a5886 Compare September 9, 2026 17:43
@liangan1 liangan1 added ciflow/xpu label used to trigger xpu CI jobs xpu Intel XPU related features and removed ciflow/xpu label used to trigger xpu CI jobs xpu Intel XPU related features labels Sep 9, 2026
@karol-brejna-i
karol-brejna-i force-pushed the dev/kbrejna/xpu/scaled-int8-mm-xpu branch from 44a5886 to 3a5664e Compare September 10, 2026 10:32
@liangan1 liangan1 added ciflow/xpu label used to trigger xpu CI jobs xpu Intel XPU related features and removed ciflow/xpu label used to trigger xpu CI jobs xpu Intel XPU related features labels Sep 10, 2026
@karol-brejna-i
karol-brejna-i force-pushed the dev/kbrejna/xpu/scaled-int8-mm-xpu branch from 3a5664e to dec22c0 Compare September 14, 2026 15:51
@liangan1 liangan1 added ciflow/xpu label used to trigger xpu CI jobs xpu Intel XPU related features and removed ciflow/xpu label used to trigger xpu CI jobs xpu Intel XPU related features labels Sep 14, 2026
karol-brejna-i and others added 4 commits September 24, 2026 14:44
Replace the CPU/CUDA-only _DEVICES list so the supported int8 weight-only
tests also run on XPU and other available accelerators.
Switch the import to the surrounding parenthesized multiline style.
Register the backend-neutral Triton implementation for XPU, then run the
int8 mixed-precision and BitNet tests on the current accelerator.
Replace the torchao helper with torch.accelerator.current_accelerator() and
remove the now-unused import.
@karol-brejna-i
karol-brejna-i force-pushed the dev/kbrejna/xpu/scaled-int8-mm-xpu branch from dec22c0 to 07980dd Compare September 24, 2026 15:31

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/xpu label used to trigger xpu CI jobs CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. module: training quantize_ api training flow xpu Intel XPU related features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants