Skip to content

Commit 92900a3

Browse files
committed
add --split-output-tensor / -sot CLI parameter (port from custom_neo)
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
1 parent f74a6fb commit 92900a3

6 files changed

Lines changed: 112 additions & 85 deletions

File tree

common/common.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2177,6 +2177,10 @@ bool gpt_params_find_arg(int argc, char ** argv, const std::string & arg, gpt_pa
21772177
params.split_mode_graph_scheduling = true;
21782178
return true;
21792179
}
2180+
if (arg == "-sot" || arg == "--split-output-tensor") {
2181+
params.split_output_tensor = true;
2182+
return true;
2183+
}
21802184
if (arg == "-sas" || arg == "--scheduler-async") {
21812185
params.scheduler_async = true;
21822186
return true;
@@ -3029,6 +3033,7 @@ void gpt_params_print_usage(int /*argc*/, char ** argv, const gpt_params & param
30293033
options.push_back({ "*", "-grt, --graph-reduce-type", "Type for data exchange between GPUs (default: %s)", "f32"});
30303034
options.push_back({ "*", "-gap, --graph-attn-precision", "Flash-attn precision under -sm graph (default: %s)", "f16"});
30313035
options.push_back({ "*", "-smgs, --split-mode-graph-scheduling,", "Force Split Mode Graph Scheduling (default: %d)", params.split_mode_graph_scheduling});
3036+
options.push_back({ "*", "-sot, --split-output-tensor,", "Force split of the Output Tensor in Split Mode Graph (default: %d)", params.split_output_tensor});
30323037
options.push_back({ "*", "-sas, --scheduler_async,", "Async evaluation of compute graphs: %d)", params.scheduler_async});
30333038
options.push_back({ "*", "-vq, --validate-quants", "validate quantized data while loading the model (default: %d)", params.validate_quants});
30343039
options.push_back({ "*", "-p, --prompt PROMPT", "prompt to start generation with\n"
@@ -4171,6 +4176,7 @@ struct llama_model_params common_model_params_to_llama(const gpt_params & params
41714176
mparams.use_mlock = params.use_mlock;
41724177
mparams.check_tensors = params.check_tensors;
41734178
mparams.repack_tensors = params.repack_tensors;
4179+
mparams.split_output_tensor = params.split_output_tensor;
41744180
mparams.use_thp = params.use_thp;
41754181
mparams.validate_quants = params.validate_quants;
41764182
mparams.merge_qkv = params.merge_qkv;
@@ -5301,6 +5307,7 @@ void yaml_dump_non_result_info(FILE * stream, const gpt_params & params, const l
53015307
fprintf(stream, "k_cache_hadamard: %s # default: false\n", params.k_cache_hadamard ? "true" : "false");
53025308
fprintf(stream, "v_cache_hadamard: %s # default: false\n", params.v_cache_hadamard ? "true" : "false");
53035309
fprintf(stream, "split_mode_graph_scheduling: %s # default: false\n", params.split_mode_graph_scheduling ? "true" : "false");
5310+
fprintf(stream, "split_output_tensor: %s # default: false\n", params.split_output_tensor ? "true" : "false");
53045311
//fprintf(stream, "split_mode_f16: %s # default: true\n", params.split_mode_f16 ? "true" : "false");
53055312
fprintf(stream, "reduce_type: %s # default f16\n", params.reduce_type.c_str());
53065313
fprintf(stream, "scheduler_async: %s # default: false\n", params.scheduler_async ? "true" : "false");

common/common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ struct gpt_params {
444444
bool v_cache_hadamard = false; // if true, use Hadamard transform for the V-cache (only makes sense with quantized cache, which requires FA)
445445
bool split_mode_graph_scheduling = false; // if true, force split mode graph scheduling
446446
//bool split_mode_f16 = true; // if true, intermediate results will be cast to f16 before copying to other GPUs to perform reduce ops
447+
bool split_output_tensor = false; // if true, force split the output tensor in split mode graph
447448
bool scheduler_async = false; // if true, in split mode graph the scheduler will use multiple threads to evaluate the graph
448449
int fused_delta_net = 0; // use fused delta-net if number of tokens in the batch is less than this value
449450
bool has_mtp = false; // enable MTP if supported by the model

include/llama.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,7 @@ extern "C" {
429429
bool merge_up_gate_exps; // if true, merge ffn_up_exps and ffn_gate_exps tensors into a single, contiguous tensor
430430
bool mtp; // if true, load MTP layers if present
431431
bool dry_run; // skip loading tensors
432+
bool split_output_tensor; // if true, force split the output tensor in split mode graph
432433
bool flash_attn;
433434
bool defer_experts; // defer expert mmap residency to speed up model loading (Linux only)
434435
};

0 commit comments

Comments
 (0)