From da8478082eeddb8f469c49620823886d85fcbcd7 Mon Sep 17 00:00:00 2001 From: pyr0ball Date: Sun, 15 Mar 2026 10:56:47 -0700 Subject: [PATCH] fix(avocet): FineTunedAdapter GPU device routing + precise body truncation test --- scripts/classifier_adapters.py | 5 +++-- tests/test_classifier_adapters.py | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/scripts/classifier_adapters.py b/scripts/classifier_adapters.py index c0b3177..f2b4fff 100644 --- a/scripts/classifier_adapters.py +++ b/scripts/classifier_adapters.py @@ -291,8 +291,9 @@ class FineTunedAdapter(ClassifierAdapter): import scripts.classifier_adapters as _mod # noqa: PLC0415 _pipe_fn = _mod.pipeline if _pipe_fn is None: - raise ImportError("transformers not installed") - self._pipeline = _pipe_fn("text-classification", model=self._model_dir) + raise ImportError("transformers not installed — run: pip install transformers") + device = 0 if _cuda_available() else -1 + self._pipeline = _pipe_fn("text-classification", model=self._model_dir, device=device) def unload(self) -> None: self._pipeline = None diff --git a/tests/test_classifier_adapters.py b/tests/test_classifier_adapters.py index 9741949..13f8a94 100644 --- a/tests/test_classifier_adapters.py +++ b/tests/test_classifier_adapters.py @@ -219,8 +219,9 @@ def test_finetuned_adapter_truncates_body_to_400(): adapter.classify("Subject", long_body) call_text = mock_pipe_instance.call_args[0][0] - # "Subject [SEP] " prefix + 400 body chars = 414 chars max - assert len(call_text) <= 420 + parts = call_text.split(" [SEP] ", 1) + assert len(parts) == 2, "Input must contain ' [SEP] ' separator" + assert len(parts[1]) == 400, f"Body must be exactly 400 chars, got {len(parts[1])}" def test_finetuned_adapter_returns_label_string():