diff --git a/engine/src/poly/engine.cpp b/engine/src/poly/engine.cpp index 35005b37e..47e8b503c 100644 --- a/engine/src/poly/engine.cpp +++ b/engine/src/poly/engine.cpp @@ -6987,6 +6987,7 @@ void Engine::run(const int32_t* tokens, int n) { bool replay = opt_.graphs && n <= opt_.window && (windowed_ || block_pass_ || n == 1) && !opt_.dump && !prompt_scratch_; for (int t = 0; t < n && replay; ++t) replay = !image_at(pos_ + t); + if (replay && n == 1 && !layer_records() && !card_routes() && !bell_on(n)) replay = false; // a token's own launches const auto replayed = [&](std::vector& made, size_t key, auto&& work) { if (made.size() <= key) made.resize(key + 1, nullptr); if (!made[key]) made[key] = record(work); diff --git a/engine/src/poly/engine.hpp b/engine/src/poly/engine.hpp index ab0e27454..fa844fca1 100644 --- a/engine/src/poly/engine.hpp +++ b/engine/src/poly/engine.hpp @@ -626,6 +626,10 @@ class Engine { /// True: a call's whole pass is recorded with programmatic dependent launches (pdl.hpp, pdl_scope()): a kernel /// launched with launch_pdl() starts while the one before it ends, and waits for it in pdl_wait(). virtual bool whole_pdl() const { return false; } + /// False: a token's layers (run() of one token) are recorded and replayed only while its experts are routed on + /// the card (card_routes(): its whole pass can be one recording), and are otherwise launched one by one. Windows + /// and step()'s rows keep their recordings. + virtual bool layer_records() const { return true; } /// layer_head() takes step()'s rows in one call: the products for every row at once, and each row's recurrent /// state and attention rows from its own sequence (rows_of_, seq_state(), seq_buf()), its position from at_. /// Otherwise step() runs the head a row at a time, with the row's sequence bound. diff --git a/engine/src/poly/inkling2.cpp b/engine/src/poly/inkling2.cpp index c20d37404..a7b236e78 100644 --- a/engine/src/poly/inkling2.cpp +++ b/engine/src/poly/inkling2.cpp @@ -1290,9 +1290,11 @@ void Inkling2::layer_head(Layer& L, int il, int n) { // an output, the card's memory idle: in a whole pass's recording they run beside the Q8_0 ones, a branch off // the stream that it joins after them. gemv_bf16() is lin()'s launch for them. Not on Metal: a recording there // is the capturing stream's alone, so the branch's launches ran once as it was made and never in its replays (the - // sink and the taps stayed the recording token's), and each event committed a command buffer. + // sink and the taps stayed the recording token's), and each event committed a command buffer. Not on HIP: there + // the branch and its join inside the recording made a token slower, not faster (UD-Q2_K_XL's BF16 sink and taps, + // 256 tokens after 302: RX 9070 XT 60.0 tokens/s with it, 83.7 without; RX 7800 XT 38.0 and 65.7). const auto plain_bf16 = [](const Dev& d) { return !d.p || (d.type == kTypeBF16 && d.scale == 1.0f); }; -#if defined(STRATA_GPU_METAL) +#if defined(STRATA_GPU_METAL) || defined(STRATA_USE_HIP) constexpr bool kBranch = false; #else constexpr bool kBranch = true; diff --git a/engine/src/poly/inkling2.hpp b/engine/src/poly/inkling2.hpp index 9b3b44293..be979bc57 100644 --- a/engine/src/poly/inkling2.hpp +++ b/engine/src/poly/inkling2.hpp @@ -56,6 +56,11 @@ class Inkling2 final : public Engine { int whole_first_layers() const override { return 4; } // its kernels in inkling2.cu wait for the launch before them in pdl_wait() bool whole_pdl() const override { return true; } +#if defined(STRATA_USE_HIP) + // On AMD a token's layers recorded one by one (some experts outside VRAM) took longer than the launches alone: + // RX 9070 XT, IQ4_NL, 41.4 against 44.2 tokens/s after 302. The whole pass's recording is kept. + bool layer_records() const override { return false; } +#endif int head_key(int il, int n) const override; int tail_key(int il, int n) const override; // step()'s rows in one head: the products, mixes, norms, controllers and router for all of them, and what reads or