Skip to content

ggml: uniformize im2col dst_type for all conv ops - #23660

Merged
ggerganov merged 4 commits into
ggml-org:masterfrom
Juste-Leo2:FixConv
Jul 14, 2026
Merged

ggml: uniformize im2col dst_type for all conv ops#23660
ggerganov merged 4 commits into
ggml-org:masterfrom
Juste-Leo2:FixConv

Conversation

@Juste-Leo2

Copy link
Copy Markdown
Contributor

Overview

This PR adjusts the im2col output type in all convolution operations that use it. Instead of always forcing F16, we keep F16 only when the weight is F16, and use F32 for everything else (BF16, F32, quantized types).

Additional information

This change was discovered while working on the Zaya model, which uses ggml_conv_1d_grouped (#22833). This operation goes through im2col, and the old code forced F16, which caused precision loss with BF16 weights or even crashes with quantized weights. The ggml_conv2d and ggml_conv3d operations had a similar issue, as they passed the weight type directly to im2col without checking.
Related to PR #23112 (Zaya).

Requirements

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: YES
    • The proposed changes here indirectly follow from previous Zaya-related PRs
    • AI was used to translate this PR into English and improve readability

@Juste-Leo2
Juste-Leo2 marked this pull request as ready for review May 25, 2026 10:31
@Juste-Leo2
Juste-Leo2 requested a review from ggerganov as a code owner May 25, 2026 10:31
@github-actions github-actions Bot added the ggml changes relating to the ggml tensor library for machine learning label May 25, 2026
@Juste-Leo2

Copy link
Copy Markdown
Contributor Author

CC @pwilkin in case you'd like to take a look :)

@CISC CISC left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

On what backend did it crash on quantized weights?

@Juste-Leo2

Juste-Leo2 commented May 25, 2026

Copy link
Copy Markdown
Contributor Author

On what backend did it crash on quantized weights?

It crashed on the CPU and Vulkan backends (CUDA was unaffected). I had previously done a temporary workaround (here), but forcing F16 ended up breaking BF16.

@Juste-Leo2

Copy link
Copy Markdown
Contributor Author

CC @ngxson, I need this PR to move forward with the rest of the Zaya development. Since you work a lot on vision models and seemed interested in the Zaya draft, I thought it made perfect sense to ping you as a reviewer. Especially since this touches im2col and convolutions, which are critical points for vision operations. Let me know what you think!

@Juste-Leo2

Copy link
Copy Markdown
Contributor Author

I just rebased the branch on the latest master, as suggested in the contributing guidelines. Since it's been 3 weeks, I figured this PR might have gotten lost in the notification pile :)

If @ggerganov , @pwilkin , or @ngxson could validate the PR, it would really unblock me for the rest of the Zaya implementation. I need this PR to be merged so I can add the Q8 test for ggml_conv_1d_grouped. Thanks!

Comment thread ggml/src/ggml.c Outdated
@Juste-Leo2

Copy link
Copy Markdown
Contributor Author

All instances have been updated to follow this casting logic!

I know that modifying im2col has an impact on vision models, so we definitely need to be careful with it. Please don't hesitate to let me know if any other adjustments are necessary. Thanks again for taking the time to review!

@Juste-Leo2
Juste-Leo2 requested a review from ggerganov June 23, 2026 10:04
@Juste-Leo2

Copy link
Copy Markdown
Contributor Author

@ggerganov Quick ping on this PR! Let me know if the updated im2col casting logic looks good to merge :)

@ggerganov ggerganov added the merge ready A maintainer can use this label to indicate that they consider the changes final and ready to merge. label Jul 7, 2026
ngxson
ngxson previously approved these changes Jul 7, 2026
@ngxson
ngxson dismissed their stale review July 7, 2026 11:01

CI fails

@ngxson ngxson left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This breaks the multimodal test on CI, so surely will also break existing vision models

@ngxson ngxson removed the merge ready A maintainer can use this label to indicate that they consider the changes final and ready to merge. label Jul 7, 2026
@Juste-Leo2

Copy link
Copy Markdown
Contributor Author

This breaks the multimodal test on CI, so surely will also break existing vision models

@ngxson You're right, I assume there might be other similar issues in the pipeline due to this change. I'll track them down and push a comprehensive fix as soon as I'm back at my PC (I'm currently traveling and on mobile). Thanks for pointing this out!

@github-actions github-actions Bot added the testing Everything test related label Jul 7, 2026
@Juste-Leo2

Copy link
Copy Markdown
Contributor Author

Ok, after investigating with opencode, I think I've figured out the issue.

The latest change modifies the selection rule for the im2col output type : now, for all weight types except BF16, the im2col output is always F16, regardless of the kernel type. The im2col_f16 function (and its 3D version) had a GGML_ASSERT requiring the kernel (src0) to be F16, however, it is never actually read during the operation. Same thing for nb00, it is checked for F16 but never used. I therefore removed these 3 lines and added a new test with an F32 kernel + F16 output, which reproduces the CI error. Normally, this fix should also work for quantized kernels.

Normally, the other backends should work, they don't have any blocking GGML_ASSERT

The error reproduced locally is identical to the one in the CI. After the fix, everything passes. @ngxson could you re-run the Server test to check if there are any other issues?

@Juste-Leo2
Juste-Leo2 requested a review from ngxson July 7, 2026 15:23
@Juste-Leo2

Copy link
Copy Markdown
Contributor Author

@ngxson Friendly ping on this! CI tests are passing with the latest fix (the editorConfig failure is unrelated to this PR). Let me know if the changes look good to you now so we can move forward with the merge :)

@pwilkin

pwilkin commented Jul 10, 2026

Copy link
Copy Markdown
Member

@ngxson needs your approval.

@Juste-Leo2

Copy link
Copy Markdown
Contributor Author

@ggerganov Quick ping on this! The CI issue has been fixed and @pwilkin approved the changes last Friday. I imagine @ngxson might be quite busy right now, so since his review status is still blocking the merge, could you perhaps take a look and merge it if it's good to go? Getting this merged would allow me to rebase #22833 (ggml_conv_1d_grouped) and add the Q8 and BF16 tests. Thanks!

@ggerganov

Copy link
Copy Markdown
Member

Please rebase on the latest master

@Juste-Leo2

Copy link
Copy Markdown
Contributor Author

@ggerganov Done! Rebased on the latest master.

@ggerganov ggerganov added the merge ready A maintainer can use this label to indicate that they consider the changes final and ready to merge. label Jul 14, 2026
@ggerganov
ggerganov merged commit 47a3966 into ggml-org:master Jul 14, 2026
25 of 27 checks passed
@Juste-Leo2

Juste-Leo2 commented Jul 14, 2026

Copy link
Copy Markdown
Contributor Author

Happy to be version b10000, Congratulations on the llama.cpp project ! 🎉

CowboyTim pushed a commit to aardbeiplantje/llama.cpp that referenced this pull request Jul 21, 2026
* ggml: uniformize im2col dst_type for all conv ops

* Update ggml/src/ggml.c

Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>

* ggml : uniformize im2col casting logic across all conv ops

* fix : allow im2col_f16 to accept any kernel type

---------

Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
RehanQasim-dev pushed a commit to aifoundry-org/llama.cpp that referenced this pull request Jul 23, 2026
* ggml: uniformize im2col dst_type for all conv ops

* Update ggml/src/ggml.c

Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>

* ggml : uniformize im2col casting logic across all conv ops

* fix : allow im2col_f16 to accept any kernel type

---------

Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
RehanQasim-dev pushed a commit to aifoundry-org/llama.cpp that referenced this pull request Jul 23, 2026
* ggml: uniformize im2col dst_type for all conv ops

* Update ggml/src/ggml.c

Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>

* ggml : uniformize im2col casting logic across all conv ops

* fix : allow im2col_f16 to accept any kernel type

---------

Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
satindergrewal pushed a commit to satindergrewal/llama.cpp that referenced this pull request Aug 12, 2026
* ggml: uniformize im2col dst_type for all conv ops

* Update ggml/src/ggml.c

Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>

* ggml : uniformize im2col casting logic across all conv ops

* fix : allow im2col_f16 to accept any kernel type

---------

Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ggml changes relating to the ggml tensor library for machine learning merge ready A maintainer can use this label to indicate that they consider the changes final and ready to merge. testing Everything test related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants