| 2431 | char *question = build_question_prompt(&cases[i]); |
| 2432 | if (!question) { |
| 2433 | fprintf(stderr, "ds4-eval: failed to allocate prompt\n"); |
| 2434 | exit(1); |
| 2435 | } |
| 2436 | ds4_tokens prompt = {0}; |
| 2437 | ds4_encode_chat_prompt(engine, eval_system_prompt(), question, think_mode, &prompt); |
| 2438 | if (prompt.len > max_prompt) { |
| 2439 | max_prompt = prompt.len; |
| 2440 | max_case = i; |
| 2441 | } |
| 2442 | ds4_tokens_free(&prompt); |
| 2443 | free(question); |
| 2444 | } |
| 2445 | if (max_case_out) *max_case_out = max_case; |
| 2446 | return max_prompt; |
| 2447 | } |
| 2448 | |
| 2449 | static int eval_auto_context_size(ds4_engine *engine, |
| 2450 | eval_config *cfg, |
| 2451 | const eval_case *cases, |
| 2452 | int ncases, |
| 2453 | int *max_prompt_out, |
| 2454 | int *max_case_out) |
| 2455 | { |
| 2456 | int ctx = EVAL_MAX_CONTEXT; |
| 2457 | int max_prompt = 0; |
| 2458 | int max_case = -1; |
| 2459 | const int min_ctx = cfg->think_mode == DS4_THINK_MAX ? |
| 2460 | (int)ds4_think_max_min_context() : 1; |
| 2461 | |
| 2462 | /* Think Max downgrades to normal thinking under its minimum context. Size |
| 2463 | * the prompts iteratively so the prompt tokenizer sees the same effective |
| 2464 | * thinking mode that the actual run will use. */ |
| 2465 | for (int iter = 0; iter < 3; iter++) { |
| 2466 | max_prompt = eval_max_prompt_tokens(engine, cfg, cases, ncases, ctx, &max_case); |
| 2467 | long long required = (long long)max_prompt + (long long)cfg->max_tokens; |
| 2468 | if (required < min_ctx) required = min_ctx; |
| 2469 | if (required > EVAL_MAX_CONTEXT) { |
no test coverage detected