Skip to content

add --split-output-tensor / -sot CLI parameter#2056

Draft
Nexesenex wants to merge 4 commits into
ikawrakow:mainfrom
Nexesenex:arg_split_output_tensor
Draft

add --split-output-tensor / -sot CLI parameter#2056
Nexesenex wants to merge 4 commits into
ikawrakow:mainfrom
Nexesenex:arg_split_output_tensor

Conversation

@Nexesenex

Copy link
Copy Markdown
Contributor

Adds a CLI flag to force-split the output tensor (output.weight,
output_extra.weight) across GPUs when using split mode graph. When
enabled, the output tensor is allocated on buft_matrix (split-capable
buffer type) instead of buft_output, allowing it to participate in
tensor parallelism. The output norm tensors remain on buft_output
(except gemma4/gemma4_mtp, which also split output_norm).

  • common/common.h: split_output_tensor field in gpt_params
  • common/common.cpp: -sot / --split-output-tensor CLI arg, help, yaml
  • include/llama.h: split_output_tensor field in llama_model_params
  • src/llama-model.h: split_output_tensor flag in llama_model
  • src/llama.cpp: pass split_output_tensor to llm_load_tensors
  • src/llama-load-tensors.cpp:
    • LOADING_PRELUDE sets ctx_output_split conditionally
    • get_context_for_tensor skips -ot overrides for output tensor names
    • create_embd_output / create_default_embd_output use ctx_output_split
    • All architecture tensor functions use ctx_output_split for output
    • Single centralized log when split_output_tensor = ON

Note : @ikawrakow, we talked about it a while ago, but that was BEFORE -wgt N (with a low value, up to 64 on GLM 4.5 Air), which solves the buffer inflation. And it can be activated or not. Works on my GLM model, performances are on par with the monolithic output, but VRAM management is much nicer, especially for heterogenous GPU setups like mine: I'm already VRAM tight for big MOEs!

I'll be back tonight or tomorrow for corrections.

@ikawrakow

Copy link
Copy Markdown
Owner

The output norm tensors remain on buft_output

If you want to do this, then please do it properly. The output normalization needs to be mirrored, and the build_output function needs to work correctly (including setting the result_norm name for MTP embedding usage).

@Nexesenex
Nexesenex marked this pull request as draft June 30, 2026 12:38
@Nexesenex

Copy link
Copy Markdown
Contributor Author

I will. Thanks for the hints!

@Nexesenex
Nexesenex force-pushed the arg_split_output_tensor branch from 436ea72 to 974f073 Compare June 30, 2026 13:06
Nexesenex added 3 commits July 8, 2026 03:58
Adds a CLI flag to force-split the output tensor (output.weight,
output_extra.weight) across GPUs when using split mode graph. When
enabled, the output tensor is allocated on buft_matrix (split-capable
buffer type) instead of buft_output, allowing it to participate in
tensor parallelism. The output norm tensors remain on buft_output
(except gemma4/gemma4_mtp, which also split output_norm).

- common/common.h: split_output_tensor field in gpt_params
- common/common.cpp: -sot / --split-output-tensor CLI arg, help, yaml
- include/llama.h: split_output_tensor field in llama_model_params
- src/llama-model.h: split_output_tensor flag in llama_model
- src/llama.cpp: pass split_output_tensor to llm_load_tensors
- src/llama-load-tensors.cpp:
  * LOADING_PRELUDE sets ctx_output_split conditionally
  * get_context_for_tensor skips -ot overrides for output tensor names
  * create_embd_output / create_default_embd_output use ctx_output_split
  * All architecture tensor functions use ctx_output_split for output
  * Single centralized log when split_output_tensor = ON
I mistakenly added routed
output_norm for GEMMA4 and GEMMA4_MTP to ctx_output_split.
output_norm is a 1D vector that gains no benefit from being split
across GPUs and incurs unnecessary communication overhead.
Reverted it to ctx_output instead.
Ikawrakow's review: output norm tensors remain on buft_output.buft
(the per-device offload buft) instead of being on the split context.
With -sot, the output weight IS split across devices, but the norm
weights stay on a single device and never get mirrored.

Fix: in get_context_for_tensor(), when split_output_tensor is on,
route output_norm (and output_norm_bias, output.bias) to
ctx_output_split (= split_buft context). This puts them in
split_tensors so prepare_split_tensors(-1, ...) at tensor-load
time creates per-device mirrored copies. build_output() already
handles output_norm->extra correctly: line 2107 checks for it
and line 2115 uses per-device norm copies when available.
@Nexesenex
Nexesenex force-pushed the arg_split_output_tensor branch from 974f073 to 550fde8 Compare July 8, 2026 02:00
…stead of per-site ctx_output_split

Instead of changing ctx_output to ctx_output_split at 67 per-architecture
create_tensor call sites, route output.weight, output_extra.weight,
token_embd.weight (when ctx==ctx_output), output_norm.*, and output.bias
through get_context_for_tensor(). This centralizes the split-output logic
to a single location and reverts all per-site changes back to plain ctx_output.
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.

2 participants