layer split auto: a two-GPU rig whose first pick has a tiny stage tries each card's share of the room before the three-layer rule (#2644)

On RTX 4060 Ti 16 GB + RTX 3060 12 GB (48 layers, IQ3_S) the first pick was K=2 and the #1616 retry
(every stage at least 3 layers) landed on its own edge, K=3: the 3060 ran 3 layers, 12 GB idle, 452 tok/s of
prefill against 802 at 28 layers (the prompt flows through the stages as a pipeline). For two GPUs the retry
now first asks for a placement in which each stage owns at least floor(layers x its room / all rooms) layers
(split_rules::share_floors, at least 3, trimmed to fit); the three-layer rule stays the second try and the
first pick the last, and the log says which one was taken. Nothing changes where the first pick has no
one- or two-layer stage (equal cards), and three or more GPUs keep the #1616 rule alone.

Reported by @Tworks25 on #2644, with the sweep of layer_split 12..32 (PR #2643). split_rules_test gets the
reporter's rooms (14.2 GiB and 5.50 GiB) and the identical-card and degenerate cases.
This commit is contained in:
Niko1221 committed 2026-10-15 16:31:45 +02:00
1 parent 8101a8903b
commit 3b848837fa
3 files changed
+151 -17

No files matched your search

+52
View File
@@ -6,6 +6,7 @@
// only falls back to the unrestricted best when no such placement can start the prompt path.
#pragma once
#include <algorithm>
#include <cstdint>
#include <vector>
@@ -35,6 +36,57 @@ inline bool has_tiny_stage(const std::vector<int64_t>& cuts, int64_t n_layers) {
return smallest_stage(cuts, n_layers) < kMinStageLayers;
}
// ---- #2644: the #1616 floor must not starve a card. On an asymmetric pair (RTX 4060 Ti 16 GB + RTX 3060 12 GB, 48
// layers, IQ3_S) the predicted decode window prefers almost every layer on the faster card, the first pick was K=2, and the
// #1616 retry (every stage at least kMinStageLayers) landed on the edge of that restriction: K=3, the 3060 with 3 layers,
// 12 GB idle, 452 tok/s of prefill against 802 at 28 layers (the prompt flows through the stages as a pipeline, so one
// busy card is the whole rig). So before that retry, a two-stage rig is asked for a placement in which each stage owns at
// least its share of the layers by its room for experts; the three-layer rule stays the second try, and the first pick
// the last.
/// Per stage, the fewest layers the share-of-room retry accepts: floor(n_layers x room_i / sum of rooms), at least
/// kMinStageLayers, and (when the floors would not fit) trimmed from the largest back toward kMinStageLayers until
/// they do. Rooms <= 0 count as 0; no room anywhere gives every stage kMinStageLayers.
inline std::vector<int64_t> share_floors(const std::vector<int64_t>& room, int64_t n_layers) {
std::vector<int64_t> floors(room.size(), kMinStageLayers);
double total = 0.0;
for (const int64_t r : room) total += r > 0 ? (double) r : 0.0;
if (total <= 0.0) return floors;
int64_t sum = 0;
for (size_t i = 0; i < room.size(); ++i) {
const double share = (room[i] > 0 ? (double) room[i] : 0.0) / total * (double) n_layers;
floors[i] = std::max<int64_t>(kMinStageLayers, (int64_t) share); // truncated: the floors sum to <= n_layers
sum += floors[i];
}
while (sum > n_layers) { // only through the kMinStageLayers lift of a small share
size_t big = 0;
for (size_t i = 1; i < floors.size(); ++i)
if (floors[i] > floors[big]) big = i;
if (floors[big] <= kMinStageLayers) break;
--floors[big];
--sum;
}
return floors;
}
/// True when some stage of `cuts` owns fewer layers than its floor.
inline bool below_floors(const std::vector<int64_t>& cuts, int64_t n_layers, const std::vector<int64_t>& floors) {
int64_t prev = 0;
for (size_t i = 0; i <= cuts.size() && i < floors.size(); ++i) {
const int64_t end = i < cuts.size() ? cuts[i] : n_layers;
if (end - prev < floors[i]) return true;
prev = end;
}
return false;
}
/// The share-of-room retry is worth running when some floor is above the plain three-layer rule's.
inline bool floors_exceed_minimum(const std::vector<int64_t>& floors) {
for (const int64_t f : floors)
if (f > kMinStageLayers) return true;
return false;
}
// ---- #1440: headroom among (near-)ties. The search scores a placement by its predicted window time alone, so on two
// equal cards every K whose caches hold all the profiled pairs ties, and the first one tried wins: the smallest K, which
// gives the LAST stage (the one that also carries the MTP drafter) the most layers and lets its cache fill the card to