Archived
sampler: read suppress_tokens
generation_config.json's suppress_tokens (Gemma 4: the end-of-image and end-of-audio markers, ids 258883 and 258882) are never sampled. The ids reach the sampler as SamplingParams::suppress_tokens and leave the row the way a grammar's mask does. A container carries them already, as the space-separated generation.suppress_tokens.
This commit is contained in:
1 parent
c1c05e9029
commit
a72686b7e7
6 files changed
+83
-2
No files matched your search
@@ -980,6 +980,7 @@ int Sampler::build_step(const std::vector<Request*>& reqs, int64_t step) {
|
||||
|
||||
if (budget && think.inside() && think.body >= sp.thinking_budget)
|
||||
force_close(p, row, sp.reasoning.close);
|
||||
if (!sp.suppress_tokens.empty()) suppress(p, row, sp.suppress_tokens);
|
||||
|
||||
if (want_lp) {
|
||||
/* Temperature the candidate value carries: early and late, each counted only
|
||||
@@ -1038,6 +1039,19 @@ void Sampler::force_close(DeviceSampleParams& p, int64_t row, int32_t close) {
|
||||
p.flags |= RAD_SP_MASK;
|
||||
}
|
||||
|
||||
void Sampler::suppress(DeviceSampleParams& p, int64_t row, const std::vector<int32_t>& ids) {
|
||||
uint32_t* dst = mask_stage_ + row * mask_words_;
|
||||
if (!(p.flags & RAD_SP_MASK)) {
|
||||
std::memset(dst, 0xff, (size_t)mask_words_ * 4);
|
||||
p.mask_row = (int32_t)row;
|
||||
p.flags |= RAD_SP_MASK;
|
||||
}
|
||||
for (int32_t id : ids) {
|
||||
const int64_t at = (int64_t)id - cfg_.vocab_off;
|
||||
if (at >= 0 && at < cfg_.n_vocab_local) dst[at >> 5] &= ~(1u << (uint32_t)(at & 31));
|
||||
}
|
||||
}
|
||||
|
||||
int Sampler::build_greedy(int64_t n) {
|
||||
if (!declared_) return RAD_E_STATE;
|
||||
if (n < 0) return RAD_E_INVAL;
|
||||
|
||||
Reference in new issue
Block a user