1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
//! How many prompt tokens go through one forward pass: llama.cpp's
//! `-b` / `-ub`, and the two environment variables ferrox already had
//! for the same number.
//!
//! # Why this module exists rather than two `set_var` calls
//!
//! ferrox has two prefill paths and each grew its own spelling of the
//! same knob:
//!
//! - the private `generate` loop reads `FERROX_CHUNKED_PREFILL`
//! ([`generate::forward_prompt_batch`](crate::generate));
//! - the continuous-batching scheduler reads `FERROX_CB_PREFILL_CHUNK`
//! ([`BatcherConfig::from_env`](crate::serving::batch::BatcherConfig)).
//!
//! That is this repo's dominant bug shape -- two structures that must
//! agree about one thing, with nothing enforcing it. An operator who
//! set one and served on the other path got the default and no warning.
//! So the names live here, in [`PREFILL_CHUNK_ENV_KEYS`], and both
//! readers index that array instead of writing the string themselves:
//! adding a third path means adding an entry, not remembering one.
//!
//! # The `-b` / `-ub` mapping
//!
//! llama.cpp splits the number in two: `-b`/`--batch-size` is the
//! *logical* maximum submitted to `llama_decode`, `-ub`/`--ubatch-size`
//! the *physical* maximum computed at once
//! (`common/arg.cpp:1616-1628`). ferrox has one stage, so it has one
//! number, and the value it takes is llama.cpp's own resolution of the
//! two -- `cparams.n_ubatch = std::min(cparams.n_batch, params.n_ubatch
//! == 0 ? params.n_batch : params.n_ubatch)`
//! (`src/llama-context.cpp:265`), which is [`effective_chunk`].
//!
//! Naming neither flag leaves both paths on their own defaults, so a
//! command that does not mention batching is not silently re-tuned.
/// The environment variables that carry the prefill chunk, in the order
/// [`crate::generate`] and [`crate::serving::batch`] read them.
///
/// One array rather than two literals: see the module note. Both
/// readers index it, so a rename is a compile error at both sites
/// instead of a silent default at one of them.
pub const PREFILL_CHUNK_ENV_KEYS: =
;
/// Index of the private `generate` path's spelling.
pub const PRIVATE_PATH_KEY: usize = 0;
/// Index of the continuous-batching scheduler's spelling.
pub const BATCH_PATH_KEY: usize = 1;
/// llama.cpp's resolution of `-b` and `-ub` into the one number ferrox
/// keeps: the smaller of whichever the operator actually named, and
/// `None` when neither was named.
///
/// Mirrors `src/llama-context.cpp:265`. `-ub` alone is the physical
/// batch; `-b` alone stands in for it (llama.cpp's `params.n_ubatch ==
/// 0` branch); both together clamp to the smaller, because a physical
/// batch larger than the logical one cannot be submitted.
pub