iq_kernels: GP100 4-bit gate/up expert slots, opt-in STRATA_EXPERT_NIBBLE=1 (#3455)
Problem: on a GP100 die the verify window's gate/up kernels for the IQ2_S,
IQ3_XXS and IQ3_S expert formats are not held by memory bandwidth but by each
block's serial chain (unpack the codebook indices, the emulated dp4a, the
16-lane reduction); the same kernel with every dot product removed still takes
about two thirds of its time.
Change: with STRATA_EXPERT_NIBBLE=1 the engine, after the expert cache is
filled and every expert is resident, transcodes the gate/up blocks of every
fully resident IQ2_S / IQ3_XXS / IQ3_S layer (n_embd 2560, n_ff 640) into slots
of 4-bit codes, 16 bytes per 32 weights, with the integer scales and fp16 d kept
as they are; the down rows stay GGUF. The decode gate/up reads those slots with
kernels that run the production integer chain and float tail in the production
order (R4S / R4P / R4SV / R4PX by format and group size); the prompt path's MMQ
gather rebuilds the GGUF blocks from a slot on the fly. At load every item is
round-tripped and every slot's rebuilt GGUF blocks are compared with the staged
blob before the cache is sealed (ExpertCache:🦭 a later fill_slot stops the
engine). New: include/strata/core/expert_nibble.hpp (slot contract, switches,
per-layer table), nib_gu_proto.cuh (STRATA_NIB_GU_PROTO=1 variant), the
transcoder, hash and rebuild kernels and the 4-bit gate/up kernels in
iq_kernels.cu, generate.cpp (the fill, the VRAM accounting, STRATA_EXPERT_NIBBLE_
RECHECK), iq_nibble_parity and native_expert_bench --nibble.
Review changes against the PR:
- An option the switch cannot work with (--peer-device, --kv-grow, --vram-elastic,
remote caches, STRATA_MMQ_DIRECT, ..., a card that is not cc 6.0, a build
without the kernels) now prints a warning and the start goes on with the usual
GGUF slots, where the PR refused the start. What is known only later (an expert
out of VRAM, a loan, the prompt chunk) still refuses, since slots are
converted by then.
- The checks this switch adds to expert_source.cpp and prefill.cpp are compiled
out of every build that has no 4-bit kernels, so the default builds add nothing
to the hit split or the prompt loop.
- iq_nibble_parity gets --synthetic-only (every gate/up format x both down
types on random experts, no model file), skips with 77 on a card that is not a
GP100, and the synthetic and --header runs are ctests.
- The PR's docs section is rewritten for these changes and its measurements are
labeled as the author's.
Default path (switch unset): the table is empty, nibble::slot_bytes(l) is
expert_layout().blob_bytes(l) and nibble_max_slot_bytes() is max_blob, every
sizing the PR touched returns what it returned before, and the new branches in
generate.cpp (guard_raw before the adaptive tier's copies, the profile fill's
test), expert_cache.cpp (one bool in the fill calls and admit) and verify.cpp
(a capture-time layout choice, compiled out without the kernels) are not taken.
Proof on the kernels: in the sm_60 build (CUDA 12.9) the SASS of all 446
kernels iq_kernels.cu had before is identical with and without this change,
as is that of the 603 in native_mmvq.cu, 29 in qsa_select.cu and 10 in
moe_mmq.cu; 21 kernels are new.
Tests: iq_nibble_parity --header passes on z440 and boston (the host half of the
contract; also a ctest). The GPU parts (--synthetic-only, a model shard) refuse a
card that is not a GP100, so they were only compiled here (sm_60, CUDA 12.9,
P1004: iq_nibble_parity and native_expert_bench build; the whole tree builds).
sm_86 build without the SM60 option (z440): exit 0, the 4-bit paths compiled out.
Not covered: no GP100 run. The model gate is
phaseA-tests/gh027/gates/3455-expert-nibble.sh: iq_nibble_parity --synthetic-only
and on a model's layers on a P100, then identical replies with the switch on and
off (a layer is converted only when every expert of every layer is resident, so
the rig needs the pack to fit whole), then the decode A/B. The contributor's
numbers (four GP100 dies, Swift 1.5 IQ3_S, 47 of 48 layers converted, +12.7 GiB
VRAM, decode 47.3 -> 51.9 tok/s, +9.7%; prompt reading 2.3-3.0% slower; replies
of 15 requests equal) were not re-measured, and the enabled path was written
against an older base than this branch's.
This commit is contained in:
1 parent
5dbd8774d8
commit
9067cc64d3
15 files changed
+3605
-34
No files matched your search
@@ -24,6 +24,17 @@
|
||||
|
||||
namespace strata::core {
|
||||
|
||||
namespace {
|
||||
// STRATA_EXPERT_NIBBLE: a write into a sealed cache (see ExpertCache::seal). Says which call and stops: the slots hold
|
||||
// 4-bit codes the GGUF bytes would overwrite, or a GGUF expert where a 4-bit one is expected - a wrong reply, not an error.
|
||||
[[noreturn]] void sealed_write(const char* call, int32_t slot) {
|
||||
std::fprintf(stderr, "strata: STRATA_EXPERT_NIBBLE: ExpertCache::%s(slot %d) after the cache was sealed - a GGUF "
|
||||
"blob would be written into the 4-bit expert slots: stopping\n", call, (int) slot);
|
||||
std::fflush(stderr);
|
||||
std::abort();
|
||||
}
|
||||
} // namespace
|
||||
|
||||
// See the header. NVIDIA's DGX Spark Porting Guide (section 5.5, "Memory reporting on UMA systems") recommends the same:
|
||||
// not to rely on cudaMemGetInfo alone but to count the memory the OS can reclaim. Swap is not counted here (unlike
|
||||
// NVIDIA's reference snippet): an expert cache that pushes the system into swap would be far slower than a smaller one.
|
||||
@@ -621,6 +632,7 @@ void ExpertCache::close() {
|
||||
next_free_ = 0;
|
||||
fills_ = 0;
|
||||
admitted_ = 0;
|
||||
sealed_ = false;
|
||||
layer_next_.clear();
|
||||
}
|
||||
|
||||
@@ -641,6 +653,7 @@ int32_t ExpertCache::slot_of(int64_t layer, int64_t expert) const {
|
||||
}
|
||||
|
||||
int32_t ExpertCache::admit(int64_t layer, int64_t expert) {
|
||||
if (sealed_) return kNotResident; // STRATA_EXPERT_NIBBLE: nothing is admitted (and so filled) after the startup fill
|
||||
if (layer < 0 || layer >= n_layers_ || expert < 0 || expert >= n_expert_) return kNotResident;
|
||||
const size_t at = (size_t) (layer * n_expert_ + expert);
|
||||
if (residency_[at] != kNotResident) return residency_[at];
|
||||
@@ -673,6 +686,7 @@ const uint8_t* ExpertCache::device_slot(int32_t slot) const {
|
||||
}
|
||||
|
||||
bool ExpertCache::fill_slot(int32_t slot, const uint8_t* host_blob, void* stream, std::string& err, int64_t bytes) {
|
||||
if (sealed_) sealed_write("fill_slot", slot);
|
||||
const size_t n = (size_t) (bytes > 0 && bytes <= blob_ ? bytes : blob_);
|
||||
uint8_t* dst = device_slot(slot);
|
||||
if (dst == nullptr) {
|
||||
@@ -695,6 +709,7 @@ bool ExpertCache::fill_slot(int32_t slot, const uint8_t* host_blob, void* stream
|
||||
}
|
||||
|
||||
bool ExpertCache::fill_slot_blocking(int32_t slot, const uint8_t* host_blob, std::string& err, int64_t bytes) {
|
||||
if (sealed_) sealed_write("fill_slot_blocking", slot);
|
||||
const size_t n = (size_t) (bytes > 0 && bytes <= blob_ ? bytes : blob_);
|
||||
uint8_t* dst = device_slot(slot);
|
||||
if (dst == nullptr) {
|
||||
@@ -726,6 +741,7 @@ bool ExpertCache::fill_slot_blocking(int32_t slot, const uint8_t* host_blob, std
|
||||
}
|
||||
|
||||
bool ExpertCache::fill_slot_queued(int32_t slot, const uint8_t* host_blob, std::string& err, int64_t bytes) {
|
||||
if (sealed_) sealed_write("fill_slot_queued", slot);
|
||||
const size_t n = (size_t) (bytes > 0 && bytes <= blob_ ? bytes : blob_);
|
||||
uint8_t* dst = device_slot(slot);
|
||||
if (dst == nullptr || host_blob == nullptr) {
|
||||
@@ -743,6 +759,7 @@ bool ExpertCache::fill_slot_queued(int32_t slot, const uint8_t* host_blob, std::
|
||||
}
|
||||
|
||||
bool ExpertCache::fill_slot_queued_parts(int32_t slot, const BlobPart* parts, int n, std::string& err) {
|
||||
if (sealed_) sealed_write("fill_slot_queued_parts", slot);
|
||||
uint8_t* dst = device_slot(slot);
|
||||
if (dst == nullptr || parts == nullptr || n <= 0) {
|
||||
err = "ExpertCache::fill_slot_queued_parts: slot outside the arena or no pieces";
|
||||
|
||||
Reference in new issue
Block a user