metal loop adapter: DFlash2 taps read a core layer's last pass

This commit is contained in:
hotocoo committed 2026-12-04 11:58:30 +08:00
1 parent c853008916
commit f3eb04075b
3 files changed
+5 -3

No files matched your search

+2 -2
View File
@@ -178,8 +178,8 @@ the checkpoint groups them). `engine/metal/tests/loop_parity.cpp` checks the ker
the head map against the converter's permutation. Without `--loop-adapter` nothing of it is loaded or encoded.
Each token reads 64 layers' experts instead of 48, so decode is slower. Limits: the prompt is read in decode windows (no prompt
chain or prompt GEMMs, so long prompts are slow), `--batch` is refused, the conversation cache is off, and DFlash2 drafting has
not been tried with it (a tapped core layer's tap is written on every pass, the last one stays).
chain or prompt GEMMs, so long prompts are slow), `--batch` is refused, the conversation cache is off. DFlash2 drafting works with it
(a tapped core layer is tapped on its last pass): greedy output is the same with and without the drafter.
## Measured (M5 Max, 128 GB)
+1
View File
@@ -277,6 +277,7 @@ int Window::loop_qi(int l) const {
for (int k = lp_->core_start; k < l; ++k) r += k % G_QI == G_QI - 1;
return G_NL / G_QI + (pass_ - 1) * lp_->nqc + r;
}
bool Window::loop_tap_here(int l) const { return !lp_ || (lp_->core(l) ? pass_ == lp_->T - 1 : pass_ == 0); }
int Window::loop_extra_qsa() const { return lp_ ? (lp_->T - 1) * lp_->nqc : 0; }
// every GDN state slot with the physical layer whose weights it runs (fold, the slot lists)
std::vector<std::pair<int, int>> Window::gdn_slots() const {
+2 -1
View File
@@ -424,6 +424,7 @@ private:
int loop_qi(int l) const;
std::vector<std::pair<int, int>> gdn_slots() const;
int loop_extra_qsa() const; // the looped core's extra QSA slots (0 when stock)
bool loop_tap_here(int l) const; // DFlash2 taps: a core layer's on its last pass, the others' on pass 0
bool loop_has(int l, int t) const;
void loop_lora(std::vector<mtl::Dispatch>& ds, int l, int t, const mtl::Buffer& x, uint32_t xs, const mtl::Buffer& y,
size_t y_off, uint32_t ys, int ntok);
@@ -1485,7 +1486,7 @@ void Window::layer(std::vector<mtl::Dispatch>& ds, int l, int ntok, int64_t pos0
d.tg[0] = 256;
push(ds, d);
}
if (taps_on_ && tap_slot_[l] >= 0) tap_dispatch(ds, l, R_, bo_, inj_[cur_inj_], tap_dec_, ntok); // DFlash2: the layers completed output (dflash2.inc)
if (taps_on_ && tap_slot_[l] >= 0 && loop_tap_here(l)) tap_dispatch(ds, l, R_, bo_, inj_[cur_inj_], tap_dec_, ntok); // DFlash2: the layers completed output (dflash2.inc)
}
namespace {