Skip to content

Commit a3c2e09

Browse files
committed
test(cross-encoder): isolate simulated accelerator cleanup
1 parent 72c0b55 commit a3c2e09

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

‎packages/sie_server/tests/adapters/test_cross_encoder_cpu_alignment.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,13 @@ class CustomBert(BertForSequenceClassification):
222222
)
223223
def test_off_platform_load_does_not_invoke_alignment(monkeypatch, system, machine, device):
224224
outer = SimpleNamespace(max_length=0)
225+
cache_calls = []
225226
monkeypatch.setattr(cross_encoder.sys, "platform", system)
226227
monkeypatch.setattr(cross_encoder.platform, "machine", lambda: machine)
227228
monkeypatch.setattr(cross_encoder, "CrossEncoder", lambda *args, **kwargs: outer)
229+
# Both the model and its accelerator are simulated, including cache cleanup.
230+
monkeypatch.setattr(torch.cuda, "empty_cache", lambda: cache_calls.append("cuda"))
231+
monkeypatch.setattr(torch.mps, "empty_cache", lambda: cache_calls.append("mps"))
228232

229233
def forbidden_alignment(*args, **kwargs):
230234
raise AssertionError("off-platform load must not normalize storage")
@@ -235,6 +239,8 @@ def forbidden_alignment(*args, **kwargs):
235239
assert adapter._model is outer
236240
assert outer.max_length == 17
237241
adapter.unload()
242+
assert adapter._model is None
243+
assert cache_calls == ([] if device == "cpu" else [device.split(":", 1)[0]])
238244

239245

240246
def test_failed_normalization_never_publishes_outer(model, monkeypatch):

0 commit comments

Comments
 (0)