Skip to content

fix(kernels): a per-format capture refinement may only narrow SUPPORTS_GRAPH_CAPTURE (#5014) - #5045

Merged
Qubitium merged 1 commit into
mainfrom
root/gguf-kquant-graph-5014
Nov 18, 2026
Merged

Qubitium merged 1 commit into
mainfrom
root/gguf-kquant-graph-5014

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Summary

graph_capture_safe() asked an instance's supports_graph_capture() hook before reading the class declaration. For a kernel that declares SUPPORTS_GRAPH_CAPTURE = False but inherits GGUFTorchLinear's per-format hook (GGUFCppKernel, GGUFCudaKernel), the hook answered for the format and the helper reported the kernel capturable. The refinement is only allowed to narrow the declaration, never widen it.

  • graph_capture_safe() reads SUPPORTS_GRAPH_CAPTURE first and consults the instance hook only when the declaration is True.
  • GGUFTorchLinear.supports_graph_capture() returns False when the concrete class turned the claim off.
  • Runtime formats are unchanged: Q2_K/Q3_K still narrow to False, Q4_K/Q5_K/Q6_K stay capturable.

Follow-up hardening to #5014 (landed in #5035); the merged fix is untouched.

Test

tests/kernels/test_gguf_kquant_graph_capture_5014.py::test_instance_refinement_cannot_widen_a_subclass_declaration

  • Unmodified origin/main (0783ccdbc, test copied into a separate worktree): 1 failed, 19 passed — the helper answers True for a subclass that declares False.
  • This branch: 20 passed.

The new node uses __new__ to build a real instance of a subclass that declares False (so it exercises the inherited hook without the SUPPORTS_* registration check) and a duck-typed instance whose hook would widen the claim.

Checklist

  • Regression test fails on unmodified main
  • ruff check clean on the three touched files
  • No behaviour change for any kernel that declares True

…S_GRAPH_CAPTURE (#5014)

``graph_capture_safe()`` consulted an instance's ``supports_graph_capture()``
hook before looking at the class declaration, so a kernel that declares
``SUPPORTS_GRAPH_CAPTURE = False`` but inherits ``GGUFTorchLinear``'s per-format
hook (``GGUFCppKernel``, ``GGUFCudaKernel``) was reported capturable whenever
its format happened to be in ``GRAPH_CAPTURE_QTYPES``. The hook is a
refinement of the declaration, not an override of it: it may narrow ``True``
per runtime format, never widen a ``False``.

``graph_capture_safe()`` now reads the declaration first and only asks the
instance when that declaration is ``True``. ``GGUFTorchLinear``'s own hook
applies the same rule, so ``GGUFTorchLinear.supports_graph_capture()`` also
answers ``False`` on a subclass that turned the claim off. No runtime format
changes: Q2_K/Q3_K still narrow to ``False`` and Q4_K/Q5_K/Q6_K stay
capturable.

Follow-up to #5014 / #5035. The test node fails on unmodified main (the
helper answers ``True`` for a subclass that declares ``False``) and passes
here; the other 19 nodes of the file are unchanged.
@Qubitium
Qubitium force-pushed the root/gguf-kquant-graph-5014 branch from 3b3a2a2 to d8f398e Compare November 18, 2026 00:14
@Qubitium
Qubitium merged commit 7f464ce into main Nov 18, 2026
3 of 5 checks passed
@Qubitium
Qubitium deleted the root/gguf-kquant-graph-5014 branch November 18, 2026 00:14
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