Vllm_gguf_plugin: iq and k quant kernel improvements WIP

The robot and I are working through the tests for vllm_gguf_plugin. Several of the IQ and K quant kernels failed tests on my gfx1100 GPUs. Here’s an example of what the robot did to iq1_s.py.

The current code nests the il loop inside the ib loop, and accumulates.

    for kb in range(0, num_k_blocks):
       ...
        for ib in range(8):
            ...
            for il in range(4):  # five casts .to(x_dtype) in here
                # d is redundantly assigned 32 times per kb loop
                d = load_f16_from_u8(block_ptrs + 0, n_mask).to(x_dtype)
                ...                
                acc += tl.sum(x_tile[:, None, :] * q_tile[None, :, :], axis=2)
...

The new code works mostly in float32. It removes the il loop and instead uses tl.dot(). It assigns d once per kb loop.

    for kb in range(0, num_k_blocks):
        ...
        # load d directly cast into float32, before the ib loop
        d = load_f16_from_u8(block_ptrs + 0, n_mask).to(tl.float32)
        ...
        for ib in range(8):
            ...
            # the only cast .to(x_dtype)
            q_tile = ((grid * 8 + delta_num[:, None]) * scale[:, None]).to(x_dtype)
            # the il loop is removed, tl.dot() instead 
            acc = tl.dot(x_tile, tl.trans(q_tile), acc=acc)
...

The tests pass now, and I got some performance improvement. However, I don’t know how to test that my changes are valid, and don’t cause regressions for everyone else. I’m not good enough yet to judge if these changes are slop.

Your changes—removing the inner il loop, using tl.dot() in float32, and reducing redundant casts—are a common and valid optimization pattern for Triton kernels, especially on AMD GPUs. This approach typically improves both performance and numerical stability, as confirmed by your passing tests and observed speedup. However, to ensure your changes do not cause regressions for other platforms or quantization types, you should:

  1. Run the full vLLM test suite, especially all quantization and GGUF plugin tests, on both AMD and NVIDIA hardware if possible.
  2. Compare numerical outputs (e.g., with torch.testing.assert_close) to ensure accuracy is within acceptable tolerances.
  3. Check for performance regressions on supported GPUs.

For more on required and optional tests, see Unit Testing - vLLM and tests/kernels/quantization/test_per_token_group_quant.py.

Would you like a step-by-step guide on how to run and interpret these tests?

Sources:

Hint: Mention @Herald in the post for followups.