Repository navigation
common : --fit loads a model one GPU holds on that GPU alone - #514
danielhanchen wants to merge 2 commits into
Conversation
…IT_ONE_GPU=0 keeps the split) When the fit keeps the whole model on 2+ GPUs with the layer split and the GPU with the most free memory holds model, context, compute and the drafter (measured with no_alloc as -sm none) within its fit margin, the model loads there with -sm none. The host row of the measure is not used: it holds the input layers in every placement.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6e193f0aa9
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| mparams.split_mode = LLAMA_SPLIT_MODE_NONE; | ||
| mparams.main_gpu = best; | ||
| mparams.n_gpu_layers = -1; | ||
| params.split_mode = LLAMA_SPLIT_MODE_NONE; | ||
| params.main_gpu = best; |
There was a problem hiding this comment.
Keep minimum-context measurements on the selected single GPU
When this optimization succeeds during common_measure_memory() and the minimum context is smaller than the maximum, the two memory reports use different placements. That function passes a copy named mparams_fit to common_fit_apply(), but later measures info_min with its original mparams, which still has layer splitting enabled. Updating params here does not update that original struct. Consequently, the server's measure worker reports the minimum-context model spread across multiple GPUs even though loading it now selects one GPU, understating the memory required on the selected card. Update the measurement path to use the selected placement for both reports.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 660df7f: the min-context measure now takes split_mode and main_gpu from params, so it measures the same single GPU the fit chose.
| for (size_t i = 0; i < devs.size(); i++) { | ||
| if (best < 0 || dmds[i].free > best_free) { | ||
| best = int(i); | ||
| best_free = dmds[i].free; |
There was a problem hiding this comment.
Exclude host accelerators from single-GPU selection
With an explicit device list containing a host accelerator, such as --device CUDA0,BLAS, this loop can select BLAS instead of a GPU. parse_device_list() accepts non-CPU accelerator devices, and common_get_device_memory_data_impl() substitutes free host memory for BLAS's reported 0/0 memory budget. When host memory exceeds free VRAM, BLAS therefore wins; its host-backed allocations are then excluded from need, so the check succeeds and switches the entire model to CPU-backed execution instead of retaining GPU offload. Filter the eligible devices to GPU/IGPU types for both the two-GPU prerequisite and candidate selection, preserving their original indices for main_gpu.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 660df7f: only GPU / IGPU devices count toward the 2-GPU check and can be picked; no GPU picked means the split stays.
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. 👍 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Summary
The unslothai/llama.cpp prebuilt is an aged upstream
b####tag plus the pins listed inscripts/unsloth/pr-set.json, merged in order. This pin is one commit on top of upstream b12966 (9a811bab3c4), so it needs no other pin. Once upstream has an equivalent change, the pin is dropped.The problem
With 2 or more GPUs visible,
--fitkeeps the default layer split whenever the model fits across the cards, even when one card alone could hold all of it. A layer split runs the cards one after the other and copies the activations at every hop, so a model that fits one card runs slower on two. On 2x R9700, Qwen4-35B-A3B UD-Q4_K_XL at-c 32768 --fit ondecodes at 97.7 tok/s (MTP 2) over both cards and at about 127 tok/s on one.The fix
common/fit.cpp: newcommon_fit_one_gpu(), run bycommon_fit_apply()after a successful fit. It applies only when:-sm,-ts,-nglor a draft device list.-devreports host memory).--fitdoes) the model, context and compute buffers as-sm noneon the GPU with the most free memory, plus the drafter on the same GPU (in-file MTP context or-mdmodel). If free memory minus that need still leaves the fit margin (--fit-target) of that GPU, the model loads there with-sm noneand--main-gpuset to that GPU. The params are updated too, so a-mddrafter and a reload follow the same placement.common_fit_one_gpu: --fit: one GPU (0) holds the model: needs X + Y MiB, Z MiB free, margin M MiB: -sm none on it... does not hold the model ..., after which the split stays as the fit chose it.common_measure_memory()(the server's measure worker) measures its minimum-context report on the same single GPU.LLAMA_FIT_ONE_GPU=0keeps the split.common_fit_params()itself is unchanged, sollama-fit-paramsandllama-bench --fitbehave as before.Evidence
llama_pinset.py sim --tags window: b13023 aged, b13024 newest), master pr-set + open candidates #485-#498, #501, #502 (including #489, which also touchescommon/fit.cpp) + one more candidate branch + this pin, 67 pinscleanon both tags;pin_contractfor this pin: ok, 0 files with new symbols, 78 lines accounted for;merge_checks: cleansrc/llama-model-loader.cpp), #251 and #268 at b13024. They exist without this pin and touch no file it changesllama test-llama-archs test-backend-ops test-mtmd-impl, as the preflight)feature_matrixCPU: all 36 features demonstratedgit merge-treewith upstreammaster(2ed8d0971bd)llama-completion -c 4096 -fit on, greedy 48 tokens. Models: Qwen3-0.6B Q4_K_M (dense), gemma-3-1b-it Q4_K_M, granite-4.0-h-tiny Q4_K_M (hybrid), Qwen3-30B-A3B UD-Q2_K_XL (MoE), Qwen3.8-27B UD-IQ2_XXS, Inkling-2-Mini UD-IQ1_SLLAMA_FIT_ONE_GPU=0, base on 1 card and pin on 1 card. The pin on 2 cards logsone GPU (0) holds the modelfor every model (e.g.needs 11831 + 0 MiB, 182008 MiB free, margin 1024 MiBfor Qwen3-30B-A3B). The kill switch arm, both 1-card arms and the base log nothing-lv 4, greedy. Arms: base 2 cards, pin 2 cards, pin withLLAMA_FIT_ONE_GPU=0, base and pin with 1 card visible, and pin 2 cards with--fit-targetset so one card is just too small--fit-target, keeps 2 devices ("does not hold"). Qwen3.8-Flash-Next UD-IQ4_XS, which does not fit one card: 2 devices, split kept.LLAMA_FIT_ONE_GPU=0and the 1-card arms log nothingSpeed on the pin-set tree (b13023 + open candidates, HIP builds of base and pin on the box), 2x R9700, Qwen4-35B-A3B UD-Q4_K_XL, both cards visible,
-c 32768 --fit on, chat decode, 3 rotated rounds x 3 (n = 9 per arm), median [min - max] tok/s:LLAMA_FIT_ONE_GPU=0The ranges do not overlap and the kill switch matches base. Every pin launch logs
--fit: one GPU (0) holds the model: needs 23751 + 0 MiB(MTP 0) orneeds 24306 + 196 MiB(MTP 2), then-sm none on it; base and the kill switch log nothing. The output text is identical across base, pin and kill switch at MTP 0 and at MTP 2, and the greedy md5 is identical for Qwen4 (5ce5fb1edbf8) and Qwen3.8-Flash-Next (c07036e86a89, no fit line, split kept).Earlier speed on our private fork (same rule and measure). 2x R9700 (ROCm), Qwen4-35B-A3B UD-Q4_K_XL, both cards visible,
-c 32768 --fit on, 3 rounds:one GPU (0) holds the model: needs 23751 + 0 MiB, 32404 MiB free, margin 1024 MiB: -sm none on it. The ROCm0 model buffer is 22724 MiB and the other card stays idle;A model that does not fit one card keeps today's split. On 2x RTX 3090 with the same Qwen4 model at 96K context, the measure logs
one GPU (0) does not hold the model: needs 25505 + 0 MiB, 23859 MiB free, margin 1024 MiB. The model stays on both cards, and the greedy text matches the split arms 30 / 30.Not proven
--fit-target, plus Qwen3.8-Flash-Next, which does not fit one card).-mdor in-file MTP) are measured through the same extra-model path as--fit. Only Qwen4 MTP 2 on the fork exercised it.GGML_OP_COUNTstatic asserts raised from 102 to 103 to compile: Host-weight prefetch in the scheduler, faster MoE cache prompt and decode, cache seeding under llama-server #268 and model : Inkling 1 (ggml-org#25731) on b12533 for the prebuilt #378 each add an op and each set the count to 102. That is a pin-set issue unrelated to this pin. Both test arms carry the same local fix.common/.