Skip to content

Commit 4864d6b

Browse files
Fix: ensure unique tensor and output path when running multiple instances
1 parent 25b0313 commit 4864d6b

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

examples/eval-callback/eval-callback.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,11 @@ static bool run(llama_context * ctx, const common_params & params, callback_data
146146

147147

148148
int main(int argc, char **argv) {
149-
prompt_output_file.open("prompt_output.txt");
150-
tensor_output_file.open("tensor_output.txt");
149+
std::string output_prefix = "default";
150+
151+
prompt_output_file.open(output_prefix + "_prompt_output.txt");
152+
tensor_output_file.open(output_prefix + "_tensor_output.txt");
153+
151154

152155
if (!prompt_output_file || !tensor_output_file) {
153156
std::cerr << "❌ Failed to open output files.\n";
@@ -180,6 +183,7 @@ int main(int argc, char **argv) {
180183
return 1;
181184
}
182185
continue;
186+
183187
} else if (arg == "--prompt") {
184188
if (i + 1 < argc) {
185189
prompts.emplace_back(argv[++i]);
@@ -188,6 +192,16 @@ int main(int argc, char **argv) {
188192
return 1;
189193
}
190194
continue;
195+
196+
} else if (arg == "--output-prefix") {
197+
if (i + 1 < argc) {
198+
output_prefix = argv[++i];
199+
} else {
200+
fprintf(stderr, "error: --output-prefix requires a string argument\n");
201+
return 1;
202+
}
203+
continue;
204+
191205
} else if (arg == "--n-gpu-layers") {
192206
if (i + 1 < argc) {
193207
params.n_gpu_layers = std::stoi(argv[++i]); // override default
@@ -196,8 +210,8 @@ int main(int argc, char **argv) {
196210
return 1;
197211
}
198212
continue;
199-
}
200-
else if (arg == "--list-layers") {
213+
214+
} else if (arg == "--list-layers") {
201215
list_layers = true;
202216
if (i + 1 < argc && argv[i + 1][0] != '-') {
203217
list_layers_filter = argv[++i]; // take optional argument
@@ -209,6 +223,7 @@ int main(int argc, char **argv) {
209223
}
210224

211225

226+
212227
if (!common_params_parse((int)filtered_argv.size(), filtered_argv.data(), params, LLAMA_EXAMPLE_COMMON)) {
213228
return 1;
214229
}

0 commit comments

Comments
 (0)