feat: add tensor dumping functionality with shape information

- Add --dump-folder CLI argument to enable tensor dumping during network communication
- Implement binary dump format with tensor shape metadata (n_embed, n_tokens)
- Dump both send and receive tensors with unique filenames and counters
- Include proper parameter passing from CLI to llama_send_tensors/llama_recv_tensors functions

The dump format includes: element_type(1B) + n_embed(8B) + n_tokens(8B) + tensor_size(8B) + data
This commit is contained in:
DandinPower
2025-07-28 09:57:07 +00:00
parent eb0cac1da5
commit 9bc57a10f6
5 changed files with 109 additions and 4 deletions
+7
View File
@@ -2059,6 +2059,13 @@ gpt_params_context gpt_params_parser_init(gpt_params & params, llama_example ex,
}
}
));
add_opt(llama_arg(
{"--dump-folder"}, "FOLDER",
"folder to dump network communication tensors (no dumping if unset)",
[](gpt_params & params, const std::string & value) {
params.dump_folder = value;
}
));
add_opt(llama_arg(
{"--positive-file"}, "FNAME",
format("positive prompts file, one prompt per line (default: '%s')", params.cvector_positive_file.c_str()),
+9
View File
@@ -2011,6 +2011,15 @@ struct llama_context_params llama_context_params_from_gpt_params(const gpt_param
}
cparams.next_node_ip = new char[params.next_node_ip.length() + 1];
std::strcpy(cparams.next_node_ip, params.next_node_ip.c_str());
if (cparams.dump_folder != nullptr) {
delete[] cparams.dump_folder;
}
if (!params.dump_folder.empty()) {
cparams.dump_folder = new char[params.dump_folder.length() + 1];
std::strcpy(const_cast<char*>(cparams.dump_folder), params.dump_folder.c_str());
} else {
cparams.dump_folder = nullptr;
}
cparams.n_ctx = params.n_ctx;
cparams.n_predict = params.n_predict;
+3
View File
@@ -356,6 +356,9 @@ struct gpt_params {
// batched-bench params
bool batched_bench_output_jsonl = false;
// tensor dumping
std::string dump_folder = ""; // folder to dump network communication tensors
};
// call once at the start of a program if it uses libcommon