Skip to content

Commit cb15e25

Browse files
committed
feat(wp): WP_PAGED_BATCH flag + batch_safe pinnability-governed under it
Assisted-by: Codex
1 parent f64ccfd commit cb15e25

4 files changed

Lines changed: 25 additions & 0 deletions

File tree

src/weight-pager/wp-eval-cb.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ extern "C++" void * ggml_cuda_get_wp_compute_stream();
2727

2828
namespace wp {
2929

30+
bool wp_paged_batch_enabled() {
31+
static const bool enabled = []() {
32+
const char * v = std::getenv("WP_PAGED_BATCH");
33+
return v != nullptr && std::strcmp(v, "1") == 0;
34+
}();
35+
return enabled;
36+
}
37+
3038
namespace {
3139
// Diagnostic counters. Logged only when WP_EVAL_DEBUG=1 is set in the
3240
// environment. First few ops get verbose output; afterwards we suppress

src/weight-pager/wp-eval-cb.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ bool weight_pager_eval_cb(struct ggml_tensor * t, bool ask, void * user_data);
2727
// Drain eval-callback state associated with pager before the pager tears down.
2828
void weight_pager_eval_cb_reset(WeightPager * pager);
2929

30+
bool wp_paged_batch_enabled();
31+
3032
// Diagnostic (WP_PROFILE_EVAL=1, default off): print the total host-side wall
3133
// time spent inside weight_pager_eval_cb over the run, split into the Step-2
3234
// ensure/patch phase vs page-resolution+other. Lets us see whether paged-decode

src/weight-pager/wp-pager.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,11 @@ bool WeightPager::batch_safe() const {
511511
// routed-expert TLS / pinned-slot lifetime isn't isolated -> near-null expert-pointer
512512
// GPU fault. Until the MoE-batching redesign lands (routing op must break the range
513513
// *before* it), keep MoE on the per-op sync path.
514+
if (wp_paged_batch_enabled()) {
515+
// Under WP_PAGED_BATCH, batching is governed by live pinnability and
516+
// routing-boundary breaks in wp-eval-cb.cpp, not a static eviction count.
517+
return pool_.size_class_slots_enabled();
518+
}
514519
return stats_.evictions == 0 && pool_.size_class_slots_enabled() && !catalog_.has_experts();
515520
}
516521

tests/test-weight-pager.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
// runtime — they no-op compile-out under non-HIP builds.
77

88
#include "weight-pager/wp-page-catalog.h"
9+
#include "weight-pager/wp-eval-cb.h"
910
#include "weight-pager/wp-file-io.h"
1011
#include "weight-pager/wp-host-tier.h"
1112
#include "weight-pager/wp-pager.h" // compute_advise_ranges / AdviseRange
@@ -1534,6 +1535,14 @@ static int test_routing_boundary_prepass() {
15341535
return fails;
15351536
}
15361537

1538+
static int test_wp_paged_batch_flag_default_off() {
1539+
int fails = 0;
1540+
ScopedEnv guard("WP_PAGED_BATCH");
1541+
unsetenv("WP_PAGED_BATCH");
1542+
if (wp::wp_paged_batch_enabled()) { fprintf(stderr, "FAIL: WP_PAGED_BATCH must default OFF\n"); fails++; }
1543+
return fails;
1544+
}
1545+
15371546
// ---------------------------------------------------------------------------
15381547
// main
15391548
// ---------------------------------------------------------------------------
@@ -1580,6 +1589,7 @@ int main() {
15801589
{ "pool_hot_fallback_when_all_hot", test_pool_hot_fallback_when_all_hot },
15811590
{ "pool_default_threshold_zero_lru", test_pool_default_threshold_zero_is_pure_lru },
15821591
{ "routing_boundary_prepass", test_routing_boundary_prepass },
1592+
{ "wp_paged_batch_flag_default_off", test_wp_paged_batch_flag_default_off },
15831593
};
15841594

15851595
for (const auto & t : tests) {

0 commit comments

Comments
 (0)