Skip to content

feat(ops): add GGMLTensor.dequantize() for generic core cast path - #468

Open
Log-Dog012 wants to merge 1 commit into
city96:mainfrom
Log-Dog012:fix/ggmltensor-dequantize
Open

feat(ops): add GGMLTensor.dequantize() for generic core cast path#468
Log-Dog012 wants to merge 1 commit into
city96:mainfrom
Log-Dog012:fix/ggmltensor-dequantize

Conversation

@Log-Dog012

Copy link
Copy Markdown

What

Expose a dequantize(dtype=None) method on GGMLTensor that delegates to
dequantize_tensor, mirroring what GGMLLayer.get_weight already does.

This lets ComfyUI core's generic comfy.ops.cast_bias_weight dequantize GGUF
weights instead of leaking the block-packed storage into matmul, which crashes
on a shape mismatch for e.g. Qwen2.5-VL generate():

RuntimeError: mat1 and mat2 shapes cannot be multiplied (1x3584 and 2940x152064)

Why duck-typed

Core's cast_bias_weight only handles QuantizedTensor. Rather than have core
import GGUF types, we expose dequantize() here and core checks for it by duck
typing (see Comfy-Org/ComfyUI#CORE_PR).

Verification

Paired with the core change, loading a real Qwen2.5-VL GGUF clip and calling
the unmodified transformer.logits returns (1, 1, 152064) instead of crashing.

Expose a dequantize(dtype=None) method on GGMLTensor that delegates to
dequantize_tensor, mirroring what GGMLLayer.get_weight already does. This lets
ComfyUI core's generic comfy.ops.cast_bias_weight dequantize GGUF weights
instead of leaking the block-packed storage into matmul (which crashes on a
shape mismatch for e.g. Qwen2.5-VL generate()).
@Log-Dog012

Copy link
Copy Markdown
Author

Paired core PR: Comfy-Org/ComfyUI#15049 — that change makes the generic comfy.ops.cast_bias_weight call this GGMLTensor.dequantize() method (duck-typed), so GGUF weights dequantize on the core generate path instead of leaking packed storage into F.linear.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a duck-typed GGMLTensor.dequantize(dtype=None) API so ComfyUI core’s generic casting path can dequantize GGUF-backed weights before they reach F.linear, avoiding shape-mismatch crashes caused by block-packed storage.

Changes:

  • Add GGMLTensor.dequantize(dtype=None) delegating to dequantize_tensor.
  • Document why this method exists (core duck-typing and the F.linear shape-mismatch failure mode).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread ops.py
Comment on lines +103 to +106
dt = dtype if dtype is not None else torch.float32
w = dequantize_tensor(self, dt, None)
# prevent propagating the custom tensor class
return torch.Tensor(w)
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.

2 participants