CUDA: fix bad asserts for partial offload #13337
Merged
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.
Fixup to #13320 .
The requirements for clearing the padding is that it should not be done for views since that would risk clearing valid tensor data and that the tensor memory should be in one contiguous block. The latter is to avoid having to handle the edge case of potentially having to clear memory inside the tensor.
The asserts in
mmq.cu
andmmvq.cu
were too strict becauseggml_is_contiguous
disallows both views and permutations. I added a new functionggml_is_contiguously_allocated
that only disallows views but allows permutations (to my knowledge we do not yet have a utility function for this). I changed the asserts to check that the memory is allocated contiguously and that the tensor in question is not a view of another tensor (to avoid potentially overwriting valid tensor data).The assert in
ggml_mul_mat_id
was wrong because I forgot that forMUL_MAT_ID
the number of tokens is stored in dimension 2 instead of dimension 1. But since the generic MoE code effectively creates views ofsrc0
I think it's better to mark the slices as such and to remove that assert entirely.I remembered that in the FlashAttention code the conversion of quantized KV data to FP16 implicitly assumes a contiguous block of memory and added asserts with the new function.