fix(benchmark): don't segfault benchmarking quantized models on CUDA#6
Merged
Merged
Conversation
nathanhubens
force-pushed
the
fix/quantized-benchmark-segfault
branch
from
July 6, 2026 11:33
f1af535 to
59fbcf8
Compare
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
force-pushed
the
fix/quantized-benchmark-segfault
branch
from
July 6, 2026 11:39
59fbcf8 to
c221281
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_reluon aQuantizedCUDAtensor with no registered kernel → PyTorch's dispatcher segfaults instead of raising. Only the forward-executing profilers (speed/memory/energy) crash;size/computeare fine.Fix
_is_quantized()+_device_supported()/_ensure_device_supported()incore._run_on_devicesskips unsupported devices (CUDA for a quantized model) → NaN metrics + a warning. One choke point covers the multi-device speed/memory/energy profilers._ensure_device_supportedguard at each single-device forward entry (speed/memory/energy) → raises a catchableRuntimeErrorrather than segfaulting.Non-quantized models are unaffected (ResNet-18 still benchmarks on cpu and cuda).
Verification
139 (SIGSEGV)→0(clean).benchmark(qmodel, x, metrics=('speed','memory','energy'))→{cpu: finite, cuda: NaN}, no crash.nbdev-testgreen on all 5 touched notebooks.