Initial vLLM agent strategy
This commit is contained in:
0
tests/__init__.py
Normal file
0
tests/__init__.py
Normal file
12
tests/test_download_slot_policy.py
Normal file
12
tests/test_download_slot_policy.py
Normal file
@@ -0,0 +1,12 @@
|
||||
from app.storage.db import connect
|
||||
from app.storage.repositories import Repository
|
||||
|
||||
|
||||
def test_active_self_download_count(tmp_path):
|
||||
conn = connect(str(tmp_path / "state.db"))
|
||||
repo = Repository(conn)
|
||||
for i in range(8):
|
||||
repo.upsert_download(f"owner/model-{i}", "HUGGING_FACE", "RUNNING", "self", True)
|
||||
repo.upsert_download("owner/other", "HUGGING_FACE", "RUNNING", "others", False)
|
||||
assert repo.count_active_self_downloads() == 8
|
||||
conn.close()
|
||||
5
tests/test_priority_order.py
Normal file
5
tests/test_priority_order.py
Normal file
@@ -0,0 +1,5 @@
|
||||
from app.domain.priorities import PRIORITY_BOUNTY, PRIORITY_PROMOTE, PRIORITY_OTHERS_DOWNLOADED, PRIORITY_SELF_DOWNLOAD
|
||||
|
||||
|
||||
def test_priority_order():
|
||||
assert PRIORITY_BOUNTY < PRIORITY_PROMOTE < PRIORITY_OTHERS_DOWNLOADED < PRIORITY_SELF_DOWNLOAD
|
||||
21
tests/test_strategy_id_payload.py
Normal file
21
tests/test_strategy_id_payload.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from app.clients.modelhub import ModelHubClient
|
||||
from app.settings import Settings
|
||||
|
||||
|
||||
def test_strategy_id_payload_field_configurable():
|
||||
settings = Settings(
|
||||
auth_token="a", hf_token="h", contest_api_token="c", email="e", user_id="1",
|
||||
contributors="u", strategy_id="sid", contest_task_strategy_field="strategy_id"
|
||||
)
|
||||
payload = ModelHubClient(settings).build_contest_payload("owner/model", "hygon_k100-ai", "cfg")
|
||||
assert payload["strategy_id"] == "sid"
|
||||
assert payload["taskType"] == "text-generation"
|
||||
|
||||
|
||||
def test_strategy_id_payload_can_disable_injection():
|
||||
settings = Settings(
|
||||
auth_token="a", hf_token="h", contest_api_token="c", email="e", user_id="1",
|
||||
contributors="u", strategy_id="sid", inject_strategy_id=False
|
||||
)
|
||||
payload = ModelHubClient(settings).build_contest_payload("owner/model", "hygon_k100-ai", "cfg")
|
||||
assert "strategyId" not in payload
|
||||
38
tests/test_submit_result_mapping.py
Normal file
38
tests/test_submit_result_mapping.py
Normal file
@@ -0,0 +1,38 @@
|
||||
from app.clients.modelhub import ModelHubClient
|
||||
from app.settings import Settings
|
||||
|
||||
|
||||
class FakeResponse:
|
||||
def __init__(self, body):
|
||||
self.body = body
|
||||
def json(self):
|
||||
return self.body
|
||||
|
||||
|
||||
class FakeSession:
|
||||
def __init__(self, body):
|
||||
self.body = body
|
||||
def post(self, *args, **kwargs):
|
||||
return FakeResponse(self.body)
|
||||
|
||||
|
||||
def make_client(body):
|
||||
settings = Settings(
|
||||
auth_token="a", hf_token="h", contest_api_token="c", email="e", user_id="1",
|
||||
contributors="u", strategy_id="s", submit_dry_run=False
|
||||
)
|
||||
client = ModelHubClient(settings)
|
||||
client.session = FakeSession(body)
|
||||
return client
|
||||
|
||||
|
||||
def test_submit_success_mapping():
|
||||
assert make_client({"code": 0, "message": "ok"}).create_contest_task("m", "hygon_k100-ai", "cfg").result == "success"
|
||||
|
||||
|
||||
def test_submit_queue_full_mapping():
|
||||
assert make_client({"code": 60007, "message": "full"}).create_contest_task("m", "hygon_k100-ai", "cfg").result == "queue_full"
|
||||
|
||||
|
||||
def test_submit_conflict_mapping():
|
||||
assert make_client({"code": 40000, "message": "正在验证中"}).create_contest_task("m", "hygon_k100-ai", "cfg").result == "conflict"
|
||||
16
tests/test_task_granularity.py
Normal file
16
tests/test_task_granularity.py
Normal file
@@ -0,0 +1,16 @@
|
||||
from app.scheduler.budget import Budget
|
||||
from app.scheduler.planner import Planner
|
||||
from app.storage.db import connect
|
||||
from app.storage.repositories import Repository
|
||||
|
||||
|
||||
def test_task_granularity_per_model_gpu(tmp_path):
|
||||
conn = connect(str(tmp_path / "state.db"))
|
||||
repo = Repository(conn)
|
||||
repo.upsert_candidate("owner/model", "HUGGING_FACE", "manual_bounty", 0, True, target_gpu_aliases="k100,p800")
|
||||
created = Planner(repo, Budget(repo, 2000), ["k100"]).materialize_tasks()
|
||||
assert created == 2
|
||||
rows = repo.due_tasks(("pending",), limit=10)
|
||||
assert {row["gpu_type"] for row in rows} == {"hygon_k100-ai", "Kunlunxin_p-800"}
|
||||
assert Planner(repo, Budget(repo, 2000), ["k100"]).materialize_tasks() == 0
|
||||
conn.close()
|
||||
Reference in New Issue
Block a user