Skip to content

Explore llama.cpp/ggml quantization kernels for our GGUF integration #14841

Open

Description

@moon-bot-app

Transformers recently landed support for running llama.cpp / ggml quantization schemes directly, backed by a set of ggml kernels distributed through the kernels library. Write-up: https://huggingface.co/blog/transformers-llama-cpp-quants

This looks potentially interesting for our GGUF integration in Diffusers:

  • Today our GGUF support dequantizes on the fly; the ggml kernels could let us run quantized ops natively instead, which should help both memory and speed.
  • It could also open up nicer MPS / local-inference angles, which is a frequent ask for Diffusers users.

Relevant kernels (currently being moved from transformers-community to the ggml-org org):

Next steps to figure out:

  1. Which of these kernels are actually applicable to diffusion model architectures (quantization/norm most likely; attn depends on our attention dispatch).
  2. Whether they can be plugged into the existing GGUFQuantizer path via the kernels library.
  3. Benchmark quality/speed/memory vs. the current dequantize-on-load behaviour, including on MPS.

Requested by Sayak Paul - Slack thread - Agent trace

Activity

  1. added
    performanceAnything related to performance improvements, profiling and benchmarking
    on Sep 22, 2026
  2. iwr-redmond commented on Sep 23, 2026

    @iwr-redmond

    While Llama.cpp proper cannot run models with media outputs, there is a longstanding downstream project that supports inference with a variety of diffusion models here. Llama.cpp contributor @ServeurpersoCom also maintains downstream GGML projects for Ace-Step and MiniMax Music.

  3. LaelaZorana commented on Oct 8, 2026

    @LaelaZorana

    I would like to take this one, and I think we can proceed in 3 steps.

    ggml-quantization covers the linear layers of the transformer blocks, which should account for most of the GGUF weights, and RMSNorm is already possible via ggml-norm as long as the dtypes match up. ggml-attn depends on how we plan to hook into the attn dispatcher.

    Load ggml-org/ggml-quantization from GGUFQuantizer via get_kernel and use the Metal build on MPS. CUDA can remain on Isotr0py/ggml's MMQ implementation. As a fallback we can continue to use dequantize when there is no kernel for a given quantization type.

    I would like to run the benchmarks twice and post the results here, once with these changes and once with the current dequantize path. I will try Flux and SD3.5 models with Q4_K and Q8_0 GGUF quants, then we can look at similarity, step latency and peak memory on CUDA and MPS.

    Can a maintainer please confirm the scope above looks right before I make a PR?

  4. Jackmeson1 commented on Oct 20, 2026

    @Jackmeson1

    There is an import failure relevant to this integration and #12509. This CPU reproduction simulates CUDA eligibility while calling the real kernels loader:

    import os
    
    os.environ["DIFFUSERS_GGUF_CUDA_KERNELS"] = "true"
    os.environ["DIFFUSERS_TRUST_REMOTE_KERNELS"] = "true"
    
    import torch
    
    torch.cuda.is_available = lambda: True
    torch.cuda.get_device_capability = lambda *args, **kwargs: (12, 0)
    
    from diffusers import UNet2DModel

    Observed: the import fails with A kernel version or revision must be specified. Expected: an unavailable optional GGUF accelerator should not prevent importing an unrelated model.

    Environment: Python 3.12.15, diffusers e04f0c5f / 0.42.0.dev0, torch 2.14.1+cpu, kernels 0.17.2, gguf 0.19.0.

    GGUF utilities call get_kernel("Isotr0py/ggml") during model import without a version or revision. A warning plus native-dequantization fallback restores the tested imports while preserving the explicit trust requirement; it does not restore accelerated kernel compatibility. I can send a focused import/fallback fix after maintainer acknowledgment.

    Found and reproduced with AI assistance; the repro above was run by me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    performanceAnything related to performance improvements, profiling and benchmarking

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions