feat: add queue-aware adaptive scheduling
This commit is contained in:
@@ -49,6 +49,15 @@ class HistoryClient:
|
||||
return list(self.tasks)
|
||||
|
||||
|
||||
class WeightedMarket:
|
||||
def gpu_weight(self, gpu: str, *, category: str) -> float:
|
||||
del category
|
||||
return {"gpu-a": 3.0, "gpu-b": 0.1, "gpu-c": 0.1, "gpu-d": 0.1}[gpu]
|
||||
|
||||
def gpu_metadata(self, gpu: str) -> dict:
|
||||
return {"marketWeight": self.gpu_weight(gpu, category=ALL_SUPPORTED)}
|
||||
|
||||
|
||||
class GPUStrategyTests(unittest.TestCase):
|
||||
def test_long_term_ranking_rejects_tiny_high_rate_sample(self) -> None:
|
||||
start = datetime(2026, 1, 1, tzinfo=timezone.utc)
|
||||
@@ -117,6 +126,28 @@ class GPUStrategyTests(unittest.TestCase):
|
||||
self.assertEqual(200, manager.state["acceptedTotal"])
|
||||
self.assertEqual(0, manager.state["acceptedSinceRefresh"])
|
||||
|
||||
def test_market_weights_change_gpu_mix_without_changing_50_30_20_split(self) -> None:
|
||||
supported = ["gpu-a", "gpu-b", "gpu-c", "gpu-d"]
|
||||
manager = GPUStrategyManager("unused.json", market_intelligence=WeightedMarket())
|
||||
manager.state = build_strategy_snapshot([], supported_gpus=supported)
|
||||
candidates = [
|
||||
{"repoId": f"owner/model-{model}", "targetGpu": gpu}
|
||||
for model in range(300)
|
||||
for gpu in supported
|
||||
]
|
||||
|
||||
ordered = manager.order_candidates(candidates)[:200]
|
||||
category_counts = Counter(candidate["strategyCategory"] for candidate in ordered)
|
||||
exploration_counts = Counter(
|
||||
candidate["targetGpu"]
|
||||
for candidate in ordered
|
||||
if candidate["strategyCategory"] == ALL_SUPPORTED
|
||||
)
|
||||
|
||||
self.assertEqual({LONG_TERM: 100, ALL_SUPPORTED: 60, RECENT: 40}, category_counts)
|
||||
self.assertGreater(exploration_counts["gpu-a"], exploration_counts["gpu-b"])
|
||||
self.assertTrue(all(exploration_counts[gpu] > 0 for gpu in supported))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user