Skip to content

fix(benchmark): don't segfault benchmarking quantized models on CUDA#6

Merged
nathanhubens merged 1 commit into
masterfrom
fix/quantized-benchmark-segfault
Jul 6, 2026
Merged

fix(benchmark): don't segfault benchmarking quantized models on CUDA#6
nathanhubens merged 1 commit into
masterfrom
fix/quantized-benchmark-segfault

Conversation

@nathanhubens

Copy link
Copy Markdown
Contributor

Summary

benchmark() SIGSEGVs (uncatchable) when given an INT8-quantized model on a CUDA host.

Root cause: quantized ops (fbgemm/qnnpack) have CPU-only kernels. benchmark() defaults its device list to ['cpu', 'cuda']; moving a quantized model to CUDA dispatches e.g. quantized::conv2d_relu on a QuantizedCUDA tensor with no registered kernel → PyTorch's dispatcher segfaults instead of raising. Only the forward-executing profilers (speed/memory/energy) crash; size/compute are fine.

Fix

  • _is_quantized() + _device_supported() / _ensure_device_supported() in core.
  • _run_on_devices skips unsupported devices (CUDA for a quantized model) → NaN metrics + a warning. One choke point covers the multi-device speed/memory/energy profilers.
  • Belt-and-suspenders _ensure_device_supported guard at each single-device forward entry (speed/memory/energy) → raises a catchable RuntimeError rather than segfaulting.

Non-quantized models are unaffected (ResNet-18 still benchmarks on cpu and cuda).

Verification

  • Exact repro: 139 (SIGSEGV)0 (clean).
  • benchmark(qmodel, x, metrics=('speed','memory','energy')){cpu: finite, cuda: NaN}, no crash.
  • New regression tests (a static-quantized net across all metrics; core unit tests). nbdev-test green on all 5 touched notebooks.

@nathanhubens
nathanhubens force-pushed the fix/quantized-benchmark-segfault branch from f1af535 to 59fbcf8 Compare July 6, 2026 11:33
Quantized models (INT8 fbgemm/qnnpack) have CPU-only kernels. benchmark() defaults
to devices [cpu, cuda] on a CUDA host; moving a quantized model to CUDA dispatches
e.g. quantized::conv2d_relu on a QuantizedCUDA tensor with no registered kernel ->
PyTorch's dispatcher SEGFAULTS (uncatchable). Hits any workflow that INT8-quantizes
a model and then benchmarks it.

Fix:
- _is_quantized() + _device_supported()/_ensure_device_supported() in core.
- _run_on_devices skips unsupported devices (CUDA for quantized) -> NaN + warning:
  one choke point for the speed/memory/energy multi-device profilers.
- Belt-and-suspenders guard at each single-device forward entry raises a catchable
  RuntimeError instead of segfaulting.
Non-quantized models unaffected (ResNet-18 still benches cpu+cuda). Regression
tests added; nbdev-test green on all 5 touched notebooks.
@nathanhubens
nathanhubens force-pushed the fix/quantized-benchmark-segfault branch from 59fbcf8 to c221281 Compare July 6, 2026 11:39
@nathanhubens
nathanhubens merged commit 8240d4e into master Jul 6, 2026
2 checks passed
@nathanhubens
nathanhubens deleted the fix/quantized-benchmark-segfault branch July 6, 2026 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant