Skip to content

feat(params): with_tensor_split to set each device's share of the model - #1129

Merged
AsbjornOlling merged 2 commits into
utilityai:mainfrom
hxphsts:feat/with-tensor-split
Oct 27, 2026
Merged

AsbjornOlling merged 2 commits into
utilityai:mainfrom
hxphsts:feat/with-tensor-split

Conversation

@hxphsts

@hxphsts hxphsts commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

What

Adds LlamaModelParams::with_tensor_split(&[f32]), the safe setter for llama_model_params::tensor_split: the proportion of the model each device in with_devices receives. The slice is copied into the params struct's fixed-size array (LLAMA_MAX_DEVICES), with the remaining entries zeroed, so the caller never touches raw pointers or the array length. Also exposes the current value via tensor_split().

Why

with_devices selects which backends load a model, but without tensor_split llama.cpp decides the proportions by free memory alone. A caller placing a model deliberately (a small GPU beside a large one, or a device that should hold a fixed share) has no way to say so from the Rust side today, although llama-cli --tensor-split exposes it. This is the last piece of llama_model_params around device placement not reachable from the safe API.

Scope is deliberately just the params setter, in the spirit of the "safe API to the core llama.cpp features" scoping in #809.

Test

cargo check -p llama-cpp-2 on this branch; used in a downstream crate that splits a 26B model across two machines' GPUs by explicit proportions.

@MarcusDunn

Copy link
Copy Markdown
Contributor

needs a fmt

…odel

`tensor_split` was reachable only as an output of `fit_params`, so a caller who
had computed its own placement — which is the whole point of driving several
RPC devices — had no way to hand it to llama.cpp.

The pointer llama.cpp keeps addresses the `Vec`'s heap buffer rather than this
struct, so it survives the moves builder chaining performs; a test pins that.
The slice is padded to `llama_max_devices()` because the C API reads that many
entries, and an empty slice restores llama.cpp's free-memory default.
@hxphsts
hxphsts force-pushed the feat/with-tensor-split branch from db36d61 to 613299f Compare October 2, 2026 15:17
@hxphsts

hxphsts commented Oct 4, 2026

Copy link
Copy Markdown
Contributor Author

@MarcusDunn The branch was rebased from latest main, and fmt was run

@AsbjornOlling
AsbjornOlling merged commit e7af607 into utilityai:main Oct 27, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants