The routing trace's layer bound comes from the model's geometry
generate.cpp's two trace sites kept the literal 48 (outside 0..47) from Flash-Next; Drive carries the trunk layer count from ModelGeometry now (review finding 6). tools/make_profile.py's N_LAYER = 48 is step 4's (docs/qwen36-port/step2-notes.md). Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017tPVMg2wGSNR1KANEiUtwr
This commit is contained in:
1 parent
3035bef8f5
commit
db4da2f823
1 file changed
+6
-3
@@ -778,6 +778,7 @@ struct Drive {
|
||||
/// needs no locking. `d.layers` is the CURRENT layer on entry (the adapter increments it as it walks the
|
||||
/// blob), which is why the layer index comes from there rather than from a counter of our own.
|
||||
std::FILE* routing = nullptr;
|
||||
int32_t n_layers = 48; ///< the trace's layer bound, from the model's geometry (48 was Flash-Next's literal)
|
||||
};
|
||||
|
||||
void drive_pool(void* user, const float* x_f, const int32_t* ids, const float* weights, int64_t n_embd, int64_t k,
|
||||
@@ -798,8 +799,9 @@ void drive_pool(void* user, const float* x_f, const int32_t* ids, const float* w
|
||||
// unaffected - it is a per-layer split, and shifting every layer by one preserves both metrics - but
|
||||
// anything keyed on the layer index, which is exactly what a cache profile is, would have been wrong.
|
||||
const int32_t layer_idx = (int32_t) (t->d.layers - 1);
|
||||
if (layer_idx < 0 || layer_idx >= 48) {
|
||||
std::fprintf(stderr, "strata generate: the routing trace saw layer %d, outside 0..47\n", layer_idx);
|
||||
if (layer_idx < 0 || layer_idx >= t->n_layers) {
|
||||
std::fprintf(stderr, "strata generate: the routing trace saw layer %d, outside 0..%d\n", layer_idx,
|
||||
t->n_layers - 1);
|
||||
return;
|
||||
}
|
||||
const int32_t rec[2] = {layer_idx, (int32_t) k};
|
||||
@@ -822,7 +824,7 @@ void drive_pool_multi(void* user, const float* x_f, const int32_t* ids, int64_t
|
||||
// one record per token. The multi dispatch fuses the router weights into the kernel and does not surface
|
||||
// them, so records carry unit weights: tools/make_profile.py ranks pairs by routed frequency, which is the
|
||||
// signal that matters; a one-shot --dump-routing run records true weights if a weighted ranking is wanted.
|
||||
if (t->routing != nullptr && layer >= 0 && layer < 48) {
|
||||
if (t->routing != nullptr && layer >= 0 && layer < t->n_layers) {
|
||||
for (int64_t tok = 0; tok < n_tok; ++tok) {
|
||||
const int32_t rec[2] = {(int32_t) layer, (int32_t) k};
|
||||
std::fwrite(rec, sizeof rec, 1, t->routing);
|
||||
@@ -3884,6 +3886,7 @@ int main(int argc, char** argv) {
|
||||
|
||||
if (remote_opt && !remote_opt->init(err)) { std::fprintf(stderr, "strata generate: %s\n", err.c_str()); return 1; }
|
||||
Drive drive;
|
||||
drive.n_layers = (int32_t) g.n_layers;
|
||||
for (int r = 0; r < 3; ++r) if (o.expert_cache_remote[(size_t) r] > 0)
|
||||
drive.d.remote[drive.d.remote_count++] = &remote_experts[(size_t) r];
|
||||
drive.d.peer = peer.valid() ? &peer : nullptr;
|
||||
|
||||
Reference in new issue
Block a user