zefancainlp's picture
download
raw
2.12 kB
"""CPU checks for the execution-only two-GPU adapter."""
from concurrent.futures import ThreadPoolExecutor
import threading
import time
import pytest
import pool_judge
from common import atomic, IMAGE, IMAGE_MANIFEST
def make_pool(tmp_path, monkeypatch):
atomic(tmp_path / 'control/image_ready.json', dict(image_config_sha256=IMAGE,
image_manifest_sha256=IMAGE_MANIFEST, execution_image=IMAGE))
pool = pool_judge.Pool(tmp_path)
active, seen = set(), []
lock = threading.Lock()
def evaluate(self, code, rid, timeout):
with lock:
assert self.gpu not in active
active.add(self.gpu)
seen.append(self.gpu)
time.sleep(.04)
with lock:
active.remove(self.gpu)
return dict(gpu_index=self.gpu, program_sha256=pool_judge.sha(code))
monkeypatch.setattr(pool_judge.FixedJudge, 'evaluate', evaluate)
return pool, seen
def test_two_cards_with_serial_execution_per_card(tmp_path, monkeypatch):
pool, seen = make_pool(tmp_path, monkeypatch)
with ThreadPoolExecutor(4) as ex:
results = list(ex.map(lambda n: pool.evaluate('x', f'{n:032x}', 530), range(4)))
assert len(results) == 4 and set(seen) == {6, 7}
assert pool.available == {6, 7}
def test_duplicate_request_executes_once(tmp_path, monkeypatch):
pool, seen = make_pool(tmp_path, monkeypatch)
with ThreadPoolExecutor(4) as ex:
results = list(ex.map(lambda _: pool.evaluate('same', 'a'*32, 530), range(4)))
assert len(seen) == 1 and all(r == results[0] for r in results)
with pytest.raises(pool_judge.base.InfrastructureError):
pool.evaluate('different', 'a'*32, 530)
def test_calibration_pin_and_exact_budget(tmp_path, monkeypatch):
pool, seen = make_pool(tmp_path, monkeypatch)
assert pool.evaluate('x', 'b'*32, 530, gpu=7)['gpu_index'] == 7
for timeout in [529, 531]:
with pytest.raises(pool_judge.base.InfrastructureError):
pool.evaluate('x', 'c'*32, timeout)
with pytest.raises(pool_judge.base.InfrastructureError):
pool.evaluate('x', 'd'*32, 530, gpu=0)

Xet Storage Details

Size:
2.12 kB
·
Xet hash:
7ed0d712cd50e93f78dc0d2e8505cad20e744a25d98a6e06b7ba46adaa16b92f

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.