DeepSpeed icon indicating copy to clipboard operation
DeepSpeed copied to clipboard

init_inference rejects dtype=torch.int8 on every accelerator

Open udsy19 opened this issue 2 months ago • 2 comments

Describe the bug deepspeed.init_inference(model, dtype=torch.int8) raises ValueError: Data type torch.int8 is not supported by <device> accelerator unconditionally, on every accelerator DeepSpeed ships (checked cpu, cuda, hpu, mlu, xpu — none list torch.int8 in supported_dtypes()). This is a regression: two unrelated cleanup PRs (#6528, "add bfloat16 to inference support dtypes", 2024-09-27; and #5505, "remove unused _validate_args function", 2025-01-07) combined to silently tighten InferenceEngine.__init__'s dtype gate (deepspeed/inference/engine.py:74) from its original fp16-only check to a blanket supported_dtypes() check that was never meant to describe DeepSpeed's own int8 weight-quantization dtype. docs/_tutorials/inference-tutorial.md ("Datatypes and Quantized Models", rewritten as recently as #8535) still documents int8 as supported.

Found while investigating #1454 — the compute_attention()/input_mask crash reported there is already fixed upstream, but the underlying "run int8 quantized inference" workflow that issue was trying to use is broken by this separate, still-live gap.

To Reproduce

import torch, deepspeed
deepspeed.init_inference(torch.nn.Linear(4, 4), dtype=torch.int8)

No GPU needed — the gate itself is device-agnostic and raises identically on CPU.

Expected behavior init_inference should accept dtype=torch.int8 as it did before #6528, since DeepSpeed's own int8 weight-quantization path (DeepSpeedSelfAttention/DeepSpeedMLP in deepspeed/ops/transformer/inference/ds_attention.py) still special-cases torch.int8 construction today — that code is presently unreachable dead code because the engine can no longer be constructed with this dtype at all.

System info:

  • Reproduces identically on every accelerator backend (cpu, cuda, hpu, mlu, xpu) since the dtype check is evaluated before any accelerator-specific code runs.
  • Python 3.12, torch 2.14 (CPU repro); not version-specific — same gate on current master.

Additional context A one-line fix (exempt torch.int8 from the supported_dtypes() gate, matching the code's pre-#6528 scope) plus a regression test is ready; opening a PR alongside this issue.

udsy19 avatar Sep 18 '26 00:09 udsy19

Hi @udsy19, you closed #8578 to consolidate your PRs and kept the branch. Are you planning to reopen it? If not, I'd like to take this.

On master, init_inference rejects int8 at the supported_dtypes() check in deepspeed/inference/engine.py (line 74), so it never reaches the int8 quantize path further down (line 480), and the int8 branch of _convert_to_dtype is if False:. The inference tutorial still says INT8 is supported. The review on #8578 showed that opening the gate alone doesn't quantize, so before writing code I'd check with the maintainers whether they want a working int8 path or a clear error plus a docs fix, and add a CPU test either way.

bhargavchintam avatar Oct 31 '26 08:10 bhargavchintam

@hwchen2017 @tohtana, one question before anyone writes code here: should init_inference(dtype=torch.int8) quantize again, or fail with a clear error? On master the supported_dtypes() check in deepspeed/inference/engine.py rejects int8 before the quantize= path, and the int8 branch of _convert_to_dtype is if False:, so ebarkhordar's run on #8578 showed that letting int8 through leaves the weights unquantized. The inference tutorial still says int8 is supported. If you want it working, I'd wire the quantize path behind the gate with a CPU test; if not, a clear error and a tutorial fix. udsy19 hasn't said whether they'll reopen #8578, so I'd only start once you've picked one.

bhargavchintam avatar Nov 08 '26 03:11 bhargavchintam