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)
ChrisColeTech added a commit to ChrisColeTech/ComfyUI-GGUF-Loader that referenced this pull request Aug 12, 2026
Cherry-pick production fixes from city96/ComfyUI-GGUF open PRs:
- city96#472 dequant device-constant cache (major LTX/sampling speedup)
- city96#433 IQ1/IQ2/IQ3 torch dequant (extra TE quants)
- city96#470 QK-norm .scale→.weight (silent NaN/black Flux-compat)
- city96#467 dequant bare nn.Parameters (LTX learnable_registers)
- city96#392 lumina2/zimage pad token shape fix
- city96#456/city96#468 GGMLTensor dtype + dequantize() for core cast path
- city96#461 WeightAdapter-aware move_patch_to_device
- city96#469 force_patch on partial load/unload
- city96#440/city96#436 mistral3 TE, city96#438 qwen35, qwen2 allowlist
- city96#473 partial: Qwen3-VL deepstack mmproj map for MiniMax H3 TE

Skipped mega/draft rewrites (city96#459, full city96#473 LazyGGUFReader, city96#336 Triton).
See PR_BACKPORT.md for the full matrix.
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