Repository navigation
meta: clear inactive AllReduce shards with FILL, not SCALE - #29793
Merged
Merged
Conversation
The butterfly allreduce fallback zeroed the data of a backend whose slice was empty (GGML_TENSOR_FLAG_COMPUTE cleared, so the tensor was never written) by scaling it with 0.0f. The buffer still held uninitialized memory, and per IEEE-754 0.0f * inf == nan and 0.0f * nan == nan, so the garbage became NaNs which the reduction then summed into every backend's result - NaN logits for the whole graph. This showed up with >2 devices, e.g. GGML_CUDA_DEVICES=4 on qwen4exp: 4-way tensor split granularity leaves some devices with empty slices, and both the NCCL and internal CUDA AllReduce paths (used with 2 devices) zero such shards with an actual memset instead. GGML_OP_FILL writes 0.0f to every element without reading the old contents and runs on the backend's own stream, keeping it ordered after the subgraph compute and before the reduction. ggml_fill currently supports F32/F16 only. Assisted-by: pi:llama.cpp/MiMo-V2.6-Flash-MOPD
ggerganov
force-pushed
the
fix/meta-allreduce-nan
branch
from
October 1, 2026 09:10
55e6291 to
97c34e5
Compare
JohannesGaessler
approved these changes
Oct 1, 2026
JohannesGaessler
left a comment
Contributor
There was a problem hiding this comment.
Thank you, this is definitely a way better solution. I think to remember though that I did it like this because in some other part of the code memory was zeroed like this and I had assumed there was (as of yet) no better solution. So it may make sense to get a clanker to check the codebase for more instances of this.
CISC
approved these changes
Oct 1, 2026
1 task
frostyautumnleaf
pushed a commit
to frostyautumnleaf/llama.cpp
that referenced
this pull request
Oct 5, 2026
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
Fixes NaN logits in tensor-parallel inference with more than 2 devices: the meta-backend butterfly AllReduce fallback zeroed the shard of a backend whose slice is empty (
GGML_TENSOR_FLAG_COMPUTEcleared, tensor never written) by computingGGML_OP_SCALEwith 0.0f, but that uninitialized memory can contain Inf/NaN. UseGGML_OP_FILLinstead.Additional information
Repro:
GGML_CUDA_DEVICES=4 ./bin/test-llama-archs -a qwen4exp -v 4-> nan logitRequirements