pub struct RecommendedSampling {
pub temperature: Option<f32>,
pub top_p: Option<f32>,
pub top_k: Option<usize>,
}Expand description
The sampling a checkpoint recommends for itself, one Option
per field so that “this model says nothing about top_p” stays
distinguishable from “this model recommends top_p = 1.0”. This is
sglang’s sampling_defaults='model', ported from FreeToken
python/freetoken/utils/hf.py:92 load_generation_sampling.
Every field is None for a checkpoint that recommends nothing,
which is the overwhelming majority, and
RecommendedSampling::resolve then reproduces ferrox’s existing
defaults exactly – a recommendation may only fill a gap the request
left, never override it.
Why this exists at all: reasoning checkpoints are tuned for a specific sampler (Qwen3.5 ships temperature 1.0, top_k 20, top_p 0.95) and ship those numbers with the weights. Served under a generic greedy-or-0.8 default they fall into repetition loops – fluent output that never terminates – which reads as a broken model rather than as a serving default nobody read off the file.
Fields§
§temperature: Option<f32>§top_p: Option<f32>§top_k: Option<usize>Implementations§
Source§impl RecommendedSampling
impl RecommendedSampling
Sourcepub fn from_gguf(file: &impl TensorSource) -> Self
pub fn from_gguf(file: &impl TensorSource) -> Self
The sampling a GGUF recommends for itself, from the
general.sampling.* metadata keys llama.cpp’s converter writes
when the source checkpoint carried a generation_config.json.
This is the GGUF half of FreeToken’s load_generation_sampling
(python/freetoken/utils/hf.py:92), which checks the GGUF
metadata first and only falls back to a generation_config.json
sidecar for non-GGUF checkpoints – a GGUF is a single file and
has no sidecar to read.
Key names are llama.cpp’s own (general.sampling.temp, not
temperature). Each key is independent: a file that names only
top_k recommends only top_k, and the two fields it did not
mention stay None so the server’s own defaults keep speaking
for them.
temp / top_p are read as float or integer, because a
converter that wrote temp = 1 stores a GGUF integer and
dropping that value would silently serve the checkpoint greedy –
the exact repetition-loop failure the recommendation exists to
prevent.
Source§impl RecommendedSampling
impl RecommendedSampling
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
True when the checkpoint recommended nothing at all, i.e.
Self::resolve is guaranteed to return the framework defaults
for any request. Useful for telling an operator whether
“model defaults” had anything to act on.
Sourcepub fn resolve(
&self,
requested: RequestedSampling,
framework: SamplingParams,
) -> SamplingParams
pub fn resolve( &self, requested: RequestedSampling, framework: SamplingParams, ) -> SamplingParams
Precedence, exactly as FreeToken’s resolve_sampling.pick
(python/freetoken/server/generation.py:170) applies it: the
request’s own value, else the checkpoint’s
recommendation, else the framework default carried by
framework (ferrox’s SamplingParams::default() unless a caller
has its own).
The penalty fields are taken from framework untouched: nothing
in the reference reads a recommended penalty, and inventing one
here would be this function changing generation on its own.
Getting the order wrong in either direction is a silent
behaviour change: recommendation-over-request makes a client’s
explicit temperature: 0 unreachable on a model that recommends
1.0, and framework-over-recommendation is the greedy repetition
loop this whole path exists to avoid.
Sourcepub fn from_generation_config(json: &str) -> Self
pub fn from_generation_config(json: &str) -> Self
The recommendation in a HuggingFace-style generation_config.json
body.
Two rules, both from the reference
(hf.py:92 load_generation_sampling):
do_sample: falsemeans the checkpoint recommends greedy, which is returned astemperature = 0and nothing else – the top_k/top_p in such a file describe a sampler the model asks not to be used.- otherwise only the keys actually present are returned. An
absent key stays
None; filling it with a house default (the naive reading, and what HF’s ownGenerationConfigobject does for you) would turn silence into a recommendation and let a file that says onlytemperature: 0.6also pin top_p to 1.0, overriding the server’s own default for a value the checkpoint never expressed.
A file that does not parse, or is not a JSON object, recommends nothing – a malformed sidecar must not be able to change how a model is sampled.
Sourcepub fn from_model_dir(dir: &Path) -> Self
pub fn from_model_dir(dir: &Path) -> Self
Self::from_generation_config for the generation_config.json
beside a checkpoint’s weights (an HF-format model directory).
A directory with no such file recommends nothing, exactly like a
GGUF with no general.sampling.* keys: the absence of a
recommendation is the normal case and must never be an error that
stops a model from loading.
Trait Implementations§
Source§impl Clone for RecommendedSampling
impl Clone for RecommendedSampling
Source§fn clone(&self) -> RecommendedSampling
fn clone(&self) -> RecommendedSampling
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for RecommendedSampling
Source§impl Debug for RecommendedSampling
impl Debug for RecommendedSampling
Source§impl Default for RecommendedSampling
impl Default for RecommendedSampling
Source§fn default() -> RecommendedSampling
fn default() -> RecommendedSampling
Source§impl PartialEq for RecommendedSampling
impl PartialEq for RecommendedSampling
impl StructuralPartialEq for RecommendedSampling
Auto Trait Implementations§
impl Freeze for RecommendedSampling
impl RefUnwindSafe for RecommendedSampling
impl Send for RecommendedSampling
impl Sync for RecommendedSampling
impl Unpin for RecommendedSampling
impl UnsafeUnpin for RecommendedSampling
impl UnwindSafe for RecommendedSampling
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more