sycl: make --fit respect --fit-target better - #27629
Conversation
|
Hi @nicois, thanks for your contribution! Per our contribution guidelines, the automated PR checker found the following issue(s) that need your attention:
Please note that maintainers reserve the right to make final decisions on PRs. If you believe there is a mistake, please comment below. |
399aaf8 to
7b06245
Compare
|
It's good job! Thank you! |
7b425d3 to
c5c243f
Compare
|
Thanks for that feedback. I believe I've incorporated all of it. |
|
@nicois thank you for your contribution! I like the changes and good thinking, I like the code in some areas too. Had some comments and attached those. Looking forward to seeing this get merged :) |
|
Thanks for the further feedback. I'll definitely remove the verbosity and unslop what remains. |
|
@nicois No problem. I know it is very useful, and I think I tend to overuse sometimes too, but we (as-in people in general) have to think a bit about the code and how to describe it and not just rely on the AI comments. Human written comments tend to make more sense and have more character in my opinion. |
d6d1c9a to
0a30dd4
Compare
|
@nicois Can you show it actually working? Like setting a fit-target before, and after your change, and showing vram usage and ctx size being different? |
improve the --fit algorithm to take into account the actual peak required VRAM for a given context size on a SYCL backend. This includes both properly accounting for how much VRAM is required when the allocated context is fully used (which makes the reported context drop below what it did before, but stop it OOMing) as well as preventing some overly-conservative calculations which meant too much VRAM was being reserved. Tested on a Arc b70 with unsloth's qwen3.8 (Q4_K_XL), able to get 262144 context, fully usable, with q8_0 KV and MTP and 4k ubatch size using --fit-target 1
0a30dd4 to
165bae3
Compare
|
With this patch, on my Arc b70 (32Gb of VRAM), this is what I see. First scenario (omitting args which don't affect memory usage, such as temperature etc.) is llama-server --no-mmproj-auto --spec-draft-n-max 3 --spec-type draft-mtp --batch-size 8192 --cache-type-k q8_0 --cache-type-v q8_0 --flash-attn on --fit on --fit-target 1 --hf-repo unsloth/Qwen3.8-27B-GGUF:Q8_0 --ubatch-size 1024which yields Using the .. and this context is fully usable; I have filled it and not OOMed. Using the unpatched version, with the Q8 model and with With Q4 and same as with the patch, but then crashes at around X tokens: |
|
Fantastic! Thank you <3 |
Applies the approach merged in ggml-org#27629 to MUL_MAT's dequant/conversion scratch, which is still allocated outside any ggml_backend_buffer and so invisible to --fit. NOT PR-ready: the f32 and bf16 paths are uncovered. Motivation is measured -- a 27B Q8_0 at --fit-target 1 aborts during warmup on a 32656 MiB B70 with UR_RESULT_ERROR_OUT_OF_DEVICE_MEMORY and "Error OP MUL_MAT".
Local working notes, not upstream material. Records the path to ggml-org#27595 and ggml-org#27629, including the theories that were measured and ruled out first: the weight-reorder scratch, the vision encoder, and async-allocation retention.
improve the --fit algorithm to take into account the actual peak required VRAM for a given context size on a SYCL backend. This includes both properly accounting for how much VRAM is required when the allocated context is fully used (which makes the reported context drop below what it did before, but stop it OOMing) as well as preventing some overly-conservative calculations which meant too much VRAM was being reserved. Tested on a Arc b70 with unsloth's qwen3.8 (Q4_K_XL), able to get 262144 context, fully usable, with q8_0 KV and MTP and 4k ubatch size using --fit-target 1
improve the --fit algorithm to take into account the actual peak required VRAM for a given context size on a SYCL backend. This includes both properly accounting for how much VRAM is required when the allocated context is fully used (which makes the reported context drop below what it did before, but stop it OOMing) as well as preventing some overly-conservative calculations which meant too much VRAM was being reserved. Tested on a Arc b70 with unsloth's qwen3.8 (Q4_K_XL), able to get 262144 context, fully usable, with q8_0 KV and MTP and 4k ubatch size using --fit-target 1
Applies the approach merged in ggml-org#27629 to MUL_MAT's dequant/conversion scratch, which is still allocated outside any ggml_backend_buffer and so invisible to --fit. NOT PR-ready: the f32 and bf16 paths are uncovered. Motivation is measured -- a 27B Q8_0 at --fit-target 1 aborts during warmup on a 32656 MiB B70 with UR_RESULT_ERROR_OUT_OF_DEVICE_MEMORY and "Error OP MUL_MAT".
Local working notes, not upstream material. Records the path to ggml-org#27595 and ggml-org#27629, including the theories that were measured and ruled out first: the weight-reorder scratch, the vision encoder, and async-allocation retention.
Overview
Make
--fitwork properly on SYCL, so--fit-target 1is viableAdditional information
There are two problems which make --fit not work as well as it should for SYCL devices:
This means that SYNC users have to spend a long time adjusting
---fit-targetto find a value large enough that it doesn't OOM when all the context is used.This is a bigger problem for users who can fit all their KV cache onto their GPU, like me with a Arc b70 running unsloth's qwen 3.8. If only 12Gb of VRAM is available, most of the KV cache is in normal RAM anyway, so the under-estimate is less obvious.
With this PR applied, you should be able to run with
--fit-target 1and not have it OOM. The maximum context size might be a little lower than--fitcalculated previously, but this time it's calculated correctly and won't crash mid-run.To properly log memory allocations and deallocations I used a sibling PR, but as this is my first contribution I'll keep the other PR in draft until this is merged.
Requirements