Archived
- Qwen3.8-Flash-Next on one card: the heat engine moves 64 experts a step (was 8), its copies and the prefill's expert staging run on the card's DMA engines instead of as copy kernels, and at decode the next layer's likeliest experts are copied onto the card ahead of its GEMMs. Against 1.3.0 at --tp 1: prefill +17-20% from 8K tokens up, throughput under load +16-20% - deploy/compose/flashnext-tp1.yaml: Qwen3.8-Flash-Next on one card and 64 GB of host RAM (4096-token prefill steps, 4 sequences, a 301K-token cache) - #61: --busy-prefill-chunk (default auto): a long prefill leaves the rest of the step to the requests decoding beside it and to new arrivals, instead of taking all of it (baKon) - LiquidAI's LFM2 and LFM2-VL, and d1's /v1/systemone (after zivius's PR #50) - a startup report: every option with its value and where it came from, the hardware, and what on it costs speed with the fix; /diagnostics serves it (behind the API key; without one, only to the same machine) - #69: a GPU memory fault names the buffer and kernel argument behind it and ends the server at once (exit status 70), instead of hanging or writing a core of tens of gigabytes - #64: a card without Resizable BAR is refused at startup, naming what to turn on, instead of crashing at the first launch - the image is built with ROCm 10.1 (the host's amdgpu driver must support it), with ROCm's libLLVM rebuilt so the same source compiles to the same kernels every time; a source build takes ROCm 10.1 or 7.2 - #71: the image ships curl, jq and a CA bundle, so --model <HF repo id> works in the container, and hfget.sh runs under its busybox (baKon) - --profile-ops shows how long each op's lane sat idle before it; cardclock.py skips an integrated GPU instead of stopping
94 lines
5.3 KiB
C++
94 lines
5.3 KiB
C++
/* xprefetch.h -- the next-layer expert prefetch at decode: what the host half (xprefetch.cpp) and the
|
|
* kernels (xprefetch.hip) share.
|
|
*
|
|
* WHAT IT DOES. Under expert-tiered placement a routed layer's GEMMs read the experts that are not on
|
|
* the card from the pinned host pool, across the link, while they run. A layer's router input predicts
|
|
* the NEXT routed layer's choice well: that layer's router applied to it ranks the experts the next
|
|
* layer will route. So at each routed layer the prefetch applies the next layer's router to this
|
|
* layer's router input, takes the likeliest experts that sit in the pinned pool, copies them onto the
|
|
* card with the DMA engine while the rest of this layer runs, and points the next layer's weight tables
|
|
* at the copies just before its GEMMs. The GEMMs then read those experts from the card.
|
|
*
|
|
* NOTHING IT DOES CHANGES A RESULT. A copy holds the bytes of the pool slot it was made from, and an
|
|
* entry is pointed at it only where it still names that slot (a compare-and-swap: a heat-engine move
|
|
* since then wins) and only once the copy has landed. Late copies are not used; nothing waits for them.
|
|
*
|
|
* THE PIECES, per routed layer l predicting layer l+1:
|
|
* - at l's router input (Ctx::xp_predict): on a stream of its own, behind the compute stream's
|
|
* dispatch that reads the input (a ride), xp_logits applies l+1's router to the input rows and
|
|
* xp_plan picks the copies and writes them to a mailbox in pinned host memory;
|
|
* - after l's routed down GEMM (Ctx::xp_mark): a ride on the compute stream that the DMA list polls,
|
|
* so the copies cross the link under l+1's attention rather than under l's own streamed experts;
|
|
* - a host thread hands each mailbox to the card's prefetch DMA queue: wait for the mark, copy, then
|
|
* write the request's number to the group's done word;
|
|
* - ahead of l+1's routed GEMMs (Ctx::xp_step, on the compute stream): xp_step puts the previous
|
|
* layer's entries back (its GEMMs are behind it in the stream) and points l+1's at the copies if
|
|
* the done word says they have landed.
|
|
* The ring holds kXpGroups layers' copies, kXpSlots each; a group is copied into again three layers
|
|
* later, after the step that put its entries back. */
|
|
#pragma once
|
|
#include <cstdint>
|
|
|
|
namespace rad {
|
|
|
|
constexpr int kXpSlots = 2; /* copies a layer: the link fits about two units between the marks */
|
|
constexpr int kXpGroups = 3;
|
|
constexpr int kXpMaxRows = 16; /* decode passes; a wider pass makes no prediction */
|
|
constexpr int kXpMaxK = 16;
|
|
constexpr int kXpMaxNe = 512;
|
|
constexpr int kXpMaxPools = 4;
|
|
constexpr int kXpParts = 4; /* the weights one expert's unit is made of */
|
|
|
|
/* One copied unit: its table entries, what they held and what they hold while patched, and where the
|
|
* layer's routing counts say whether the step used it. */
|
|
struct XpRec {
|
|
void** ent[kXpParts];
|
|
void* oldv[kXpParts];
|
|
void* newv[kXpParts];
|
|
const int32_t* cnt;
|
|
int32_t place;
|
|
int32_t pad;
|
|
};
|
|
struct XpJob {
|
|
uint64_t src, dst, bytes, tag; /* tag: the request's number, written after the rest */
|
|
};
|
|
/* A group's mailbox, in pinned host memory: xp_plan writes the jobs, then `seq`. */
|
|
struct XpBox {
|
|
XpJob jobs[kXpSlots];
|
|
int32_t n;
|
|
volatile uint32_t seq;
|
|
};
|
|
struct XpPools {
|
|
uint64_t lo[kXpMaxPools], hi[kXpMaxPools], stride[kXpMaxPools];
|
|
int32_t n;
|
|
};
|
|
/* Restored records: [0] units copied, [1] of them the step routed; [2] units planned. */
|
|
struct XpStats {
|
|
unsigned int copied, routed, planned, pad;
|
|
};
|
|
|
|
/* What the prefetch takes on the card for a model of `layers` routed layers whose largest expert unit
|
|
* is `unit` bytes: the ring and the buffers beside it (Ctx::xp_open allocates exactly these), in the
|
|
* 2 MiB grains the card's allocations come in -- the ring its own, the small buffers sharing theirs. */
|
|
inline int64_t xp_device_bytes(int64_t unit, int64_t layers) {
|
|
constexpr int64_t kGrain = (int64_t)2 << 20;
|
|
auto grains = [](int64_t b) { return (b + kGrain - 1) / kGrain * kGrain; };
|
|
const int64_t ring = (int64_t)kXpGroups * kXpSlots * unit;
|
|
const int64_t small = (int64_t)sizeof(XpRec) * kXpGroups * kXpSlots + 4 * kXpGroups + (int64_t)sizeof(XpStats) +
|
|
4 * (int64_t)kXpGroups * kXpMaxRows * kXpMaxNe + layers * kXpMaxNe * kXpParts * 8 +
|
|
layers * kXpMaxNe * 4;
|
|
return grains(ring) + grains(small);
|
|
}
|
|
|
|
} /* namespace rad */
|
|
|
|
extern "C" int rad_xp_logits_launch(const uint16_t* h, const uint16_t* w, float* logits, uint32_t rows,
|
|
uint32_t n_embd, uint32_t ne, void* stream);
|
|
extern "C" int rad_xp_plan_launch(const float* logits, uint32_t rows, uint32_t ne, uint32_t k,
|
|
void** const* map, const int32_t* place, const int32_t* cnt,
|
|
rad::XpPools pools, uint64_t ring, uint64_t ring_stride, rad::XpRec* rec,
|
|
int32_t* nrec, rad::XpBox* box, uint32_t seq, rad::XpStats* stats,
|
|
void* stream);
|
|
extern "C" int rad_xp_step_launch(const rad::XpRec* rrec, const int32_t* rn, const rad::XpRec* prec,
|
|
const int32_t* pn, const uint32_t* done, uint32_t seq, void* stream);
|