|
8 | 8 |
|
9 | 9 | from ocr_bench.backends import ( |
10 | 10 | InferenceProviderJudge, |
| 11 | + JudgeBackend, |
11 | 12 | OpenAICompatibleJudge, |
12 | 13 | _is_retryable, |
13 | 14 | aggregate_jury_votes, |
@@ -127,13 +128,50 @@ def test_hf_endpoint_url(self, mock_get_token): |
127 | 128 | assert isinstance(backend, OpenAICompatibleJudge) |
128 | 129 | assert "endpoints.huggingface" in backend.name |
129 | 130 | assert backend.name.endswith("/v1") |
| 131 | + assert backend.temperature == 0.0 |
130 | 132 |
|
131 | 133 | def test_non_hf_url_still_openai(self): |
132 | 134 | """Non-HF URLs still route to OpenAICompatibleJudge.""" |
133 | 135 | backend = parse_judge_spec("https://my-vllm-server.example.com/v1") |
134 | 136 | assert isinstance(backend, OpenAICompatibleJudge) |
135 | 137 |
|
136 | 138 |
|
| 139 | +# --------------------------------------------------------------------------- |
| 140 | +# JudgeBackend.judge error handling |
| 141 | +# --------------------------------------------------------------------------- |
| 142 | + |
| 143 | + |
| 144 | +class _FlakyJudge(JudgeBackend): |
| 145 | + """Judge whose _call_single raises on sample_idx 1.""" |
| 146 | + |
| 147 | + name = "flaky" |
| 148 | + |
| 149 | + def __init__(self, concurrency: int = 1): |
| 150 | + self.concurrency = concurrency |
| 151 | + |
| 152 | + def _call_single(self, comp: Comparison) -> dict[str, str]: |
| 153 | + if comp.sample_idx == 1: |
| 154 | + raise RuntimeError("boom") |
| 155 | + return {"winner": "A", "reason": "ok"} |
| 156 | + |
| 157 | + |
| 158 | +class TestJudgeErrorHandling: |
| 159 | + def test_sequential_failure_yields_empty_dict(self): |
| 160 | + """A failed call on the default sequential path must not abort the run.""" |
| 161 | + comps = [_make_comparison(i) for i in range(3)] |
| 162 | + results = _FlakyJudge(concurrency=1).judge(comps) |
| 163 | + assert results[0] == {"winner": "A", "reason": "ok"} |
| 164 | + assert results[1] == {} |
| 165 | + assert results[2] == {"winner": "A", "reason": "ok"} |
| 166 | + |
| 167 | + def test_concurrent_failure_yields_empty_dict(self): |
| 168 | + comps = [_make_comparison(i) for i in range(3)] |
| 169 | + results = _FlakyJudge(concurrency=2).judge(comps) |
| 170 | + assert results[0] == {"winner": "A", "reason": "ok"} |
| 171 | + assert results[1] == {} |
| 172 | + assert results[2] == {"winner": "A", "reason": "ok"} |
| 173 | + |
| 174 | + |
137 | 175 | # --------------------------------------------------------------------------- |
138 | 176 | # aggregate_jury_votes |
139 | 177 | # --------------------------------------------------------------------------- |
|
0 commit comments