mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 23:08:36 +00:00
ling32 sycl: prune_experts for --skip-tau (the int tip's engine calls it; the SYCL build did not link without it)
This commit is contained in:
1 parent
8d5efdb028
commit
920badbe8a
1 file changed
+30
@@ -31,4 +31,34 @@ void argmax_rows(const float* logits, int N, int V, int* out, cudaStream_t s) {
|
||||
});
|
||||
}
|
||||
|
||||
// Dynamic expert skip (--skip-tau, opt-in, NOT exact; port of prune_experts_kernel of ling32_layers.cu, one token per thread, the same arithmetic): a routed expert whose share of the token's routing
|
||||
// weight is below tau is dropped (its slot gets the top expert's id with weight 0), the others are rescaled so that the weight sum stays the same.
|
||||
void prune_experts(int* ridx, float* rw, int N, int top_k, float tau, cudaStream_t s) {
|
||||
sy::launch(s, (N + 31) / 32, 32, 0, [=](sy::Blk b, char*) {
|
||||
const int t = b.bid() * b.bdim() + b.tid();
|
||||
if (t >= N) return;
|
||||
int* ix = ridx + static_cast<size_t>(t) * top_k;
|
||||
float* w = rw + static_cast<size_t>(t) * top_k;
|
||||
float sum = 0.0f, wmax = -1.0f;
|
||||
int imax = 0;
|
||||
for (int j = 0; j < top_k; ++j) {
|
||||
sum += w[j];
|
||||
if (w[j] > wmax) { wmax = w[j]; imax = j; }
|
||||
}
|
||||
if (!(sum > 0.0f)) return;
|
||||
float kept = 0.0f;
|
||||
int drops = 0;
|
||||
for (int j = 0; j < top_k; ++j) {
|
||||
if (j != imax && w[j] < tau * sum) ++drops; else kept += w[j];
|
||||
}
|
||||
if (drops == 0 || !(kept > 0.0f)) return;
|
||||
const float scale = sum / kept;
|
||||
const int top_id = ix[imax];
|
||||
for (int j = 0; j < top_k; ++j) {
|
||||
if (j != imax && w[j] < tau * sum) { ix[j] = top_id; w[j] = 0.0f; }
|
||||
else w[j] *= scale;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace strata::ling32::gpu
|
||||
Reference in new issue
Block a user