Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions common/speculative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1080,6 +1080,29 @@ struct common_speculative_impl_draft_dflash : public common_speculative_impl {
}
}

// sanitize non-finite feature values before fusing. on Metal, the
// mat-mat kernels stage f32 activations as f16 for the simdgroup
// multiply; Laguna's massive-activation rows (attention-sink tokens,
// |x| ~ 1e6 in the pre-final-norm residual) overflow f16 -> inf/nan.
// one poisoned row would otherwise NaN the whole drafter KV cache.
{
size_t n_bad = 0;
for (auto & v : features_buf) {
if (!std::isfinite(v)) {
v = v != v ? 0.0f : (v > 0.0f ? 65504.0f : -65504.0f);
n_bad++;
}
}
if (n_bad > 0) {
static bool warned = false;
if (!warned) {
LOG_WRN("%s: sanitized %zu non-finite target feature values (f16 overflow on massive activations); "
"draft quality may degrade slightly on affected rows\n", __func__, n_bad);
warned = true;
}
}
}

// fuse extracted features through DFlash encoder
llama_batch enc_batch = {
/*.n_tokens =*/ n_chunk,
Expand Down