| 1219 | if (rc == 0) { |
| 1220 | fprintf(stderr, "ds4: diagnostic run completed on the native %s path.\n", |
| 1221 | ds4_backend_name(cfg->engine.backend)); |
| 1222 | } |
| 1223 | } else { |
| 1224 | if (cfg->engine.distributed.role == DS4_DISTRIBUTED_COORDINATOR || |
| 1225 | cfg->engine.tp.role == DS4_TP_LEADER || |
| 1226 | getenv("DS4_CLI_FORCE_SESSION") != NULL || |
| 1227 | cfg->gen.temperature > 0.0f || |
| 1228 | ds4_engine_mtp_draft_tokens(engine) > 1) { |
| 1229 | /* TP leaders always drive the session path: the sync/eval |
| 1230 | * mirroring that keeps the worker in lockstep lives there. |
| 1231 | * The env override exists so TP-vs-single-node validation |
| 1232 | * compares like with like. */ |
| 1233 | rc = run_sampled_generation(engine, cfg, &prompt); |
| 1234 | } else { |
| 1235 | token_printer printer = { |
| 1236 | .engine = engine, |
| 1237 | .fp = stdout, |
| 1238 | .format_thinking = ds4_think_mode_enabled(cli_effective_think_mode(&cfg->gen)), |
| 1239 | .in_think = ds4_think_mode_enabled(cli_effective_think_mode(&cfg->gen)), |
| 1240 | .use_color = isatty(fileno(stdout)) != 0, |
| 1241 | .last_output_newline = true, |
| 1242 | }; |
| 1243 | cli_prefill_progress progress = { |
| 1244 | .base_tokens = 0, |
| 1245 | .input_tokens = prompt.len, |
| 1246 | .use_color = ds4_log_is_tty(stderr), |
| 1247 | }; |
| 1248 | rc = ds4_engine_generate_argmax(engine, &prompt, cfg->gen.n_predict, |
| 1249 | cfg->gen.ctx_size, |
| 1250 | print_generated_token, |
| 1251 | generation_done, |
| 1252 | &printer, |
| 1253 | cli_prefill_progress_cb, |
| 1254 | &progress); |
| 1255 | } |
| 1256 | } |
| 1257 | |
| 1258 | ds4_tokens_free(&prompt); |
| 1259 | return rc; |
| 1260 | } |
| 1261 | |
| 1262 | static char *trim_inplace(char *s) { |
| 1263 | while (*s && isspace((unsigned char)*s)) s++; |
| 1264 | char *end = s + strlen(s); |
| 1265 | while (end > s && isspace((unsigned char)end[-1])) end--; |
| 1266 | *end = '\0'; |
| 1267 | return s; |
| 1268 | } |
| 1269 | |
| 1270 | static void print_repl_help(void) { |
| 1271 | puts("Commands:"); |
| 1272 | puts(" /help Show this help."); |
| 1273 | puts(" /think Use normal thinking mode."); |
| 1274 | puts(" /think-max Use Think Max only when context is at least 393216 tokens."); |
| 1275 | puts(" /nothink Disable thinking mode."); |
| 1276 | puts(" /ctx N Set context size for following prompts."); |
| 1277 | puts(" /power N Set GPU duty cycle percentage, 1..100."); |
| 1278 | puts(" /read FILE Read a prompt from FILE and run it."); |
no test coverage detected