Configuration option for number of concurrent requests

This commit is contained in:
sebastien committed 2026-10-06 11:00:16 +02:00
1 parent 94ca8b8256
commit f43b713590
8 files changed
+151 -16

No files matched your search

+55 -7
View File
@@ -1479,7 +1479,7 @@ class StandardCliTests(unittest.TestCase):
with tempfile.TemporaryDirectory() as directory:
workspace = EvaluationWorkspace(Path(directory))
args = module.build_parser().parse_args(
[str(workspace.root), "--overwrite"]
[str(workspace.root), "--overwrite", "--workers", "1"]
)
module.configure_runtime(
workspace,
@@ -1495,18 +1495,46 @@ class StandardCliTests(unittest.TestCase):
(workspace.root / "saved-result").write_text(task[0])
return []
with patch.object(module, "NB_THREADS", 1), patch.object(
with patch.object(
module.concurrent.futures, "ThreadPoolExecutor", wraps=ThreadPoolExecutor
) as executor, patch.object(
module, "process_single_task", side_effect=process
), patch.object(
module, "resolve_delayed_moves", return_value=[]
):
status = module.run_configured(args)
executor.assert_called_once_with(max_workers=1)
saved_result = (workspace.root / "saved-result").read_text()
self.assertEqual(status, module.ExitCode.INTERRUPTED)
self.assertEqual(processed, ["group-1.jpg"])
self.assertEqual(saved_result, "group-1.jpg")
def test_correction_concurrency_defaults_and_cli_forwarding(self) -> None:
module = self.modules["correction"]
self.assertEqual(module.build_parser().parse_args(["Exam"]).workers, 12)
with tempfile.TemporaryDirectory() as directory:
root = Path(directory)
(root / "Copies").mkdir()
with patch.object(module, "run", return_value=ExitCode.SUCCESS) as run:
self.assertEqual(module.main([str(root), "--workers", "2"]), 0)
self.assertEqual(run.call_args.args[2].workers, 2)
def test_invalid_correction_concurrency_rejected_before_changes(self) -> None:
module = self.modules["correction"]
with tempfile.TemporaryDirectory() as directory:
workspace = EvaluationWorkspace(Path(directory))
for workers in (0, -1):
args = module.build_parser().parse_args(
[str(workspace.root), "--workers", str(workers)]
)
with self.subTest(workers=workers), \
patch.object(module, "configure_runtime") as configure, \
self.assertRaises(CliError) as caught:
module.run(workspace, [], args)
self.assertEqual(caught.exception.exit_code, ExitCode.INVALID_ARGUMENTS)
configure.assert_not_called()
def test_gemini_call_finishes_inflight_stream_but_does_not_retry(self) -> None:
module = self.modules["correction"]
self.addCleanup(module.stop_requested.clear)
@@ -1562,7 +1590,7 @@ class StandardCliTests(unittest.TestCase):
api_client.models.generate_content_stream.side_effect = stream
args = module.build_parser().parse_args([str(workspace.root)])
with patch.object(module, "NB_THREADS", 1), patch.object(
with patch.object(args, "workers", 1), patch.object(
module.prompting, "generate_request", return_value=([], Mock())
):
module.configure_runtime(
@@ -1636,7 +1664,7 @@ class StandardCliTests(unittest.TestCase):
[str(workspace.root), "--overwrite"]
)
with patch.object(module, "NB_THREADS", 1), patch.object(
with patch.object(args, "workers", 1), patch.object(
module.prompting, "generate_request", return_value=([], Mock())
), patch.object(
module, "handle_label_errors", side_effect=resolve_error
@@ -2223,6 +2251,16 @@ class WorkflowTests(unittest.TestCase):
variant = next(item for item in step.variants if item.id == variant_id)
return build_command(REPOSITORY, step, variant, values, self.evaluation)
def test_label_request_concurrency_is_configurable(self) -> None:
for personal in (False, True):
step = next(step for step in build_workflow(personal) if step.id == "labels")
for values, expected in (({}, "12"), ({"workers": "2"}, "2")):
with self.subTest(personal=personal, values=values):
command = build_command(
REPOSITORY, step, step.variants[0], values, self.evaluation
)
self.assertEqual(command[command.index("--workers") + 1], expected)
def test_personal_steps_are_configurable(self) -> None:
standard_ids = {step.id for step in build_workflow(False)}
personal_ids = {step.id for step in build_workflow(True)}
@@ -2496,10 +2534,19 @@ class WorkflowTests(unittest.TestCase):
)
self.assertEqual(
command_arguments(command),
[self.evaluation, "--overwrite", "--limit", "0"],
[self.evaluation, "--workers", "12", "--overwrite", "--limit", "0"],
)
self.assertEqual(command[4], "correct")
def test_correction_concurrency_applies_to_live_requests(self) -> None:
for variant in self.steps["correction"].variants:
with self.subTest(variant=variant.id):
command = self.command("correction", variant.id, {"workers": "2"})
if variant.id in {"batch", "reset"}:
self.assertNotIn("--workers", command)
else:
self.assertEqual(command[command.index("--workers") + 1], "2")
def test_refaire_correction_does_not_offer_overwrite(self) -> None:
step = self.steps["correction"]
overwrite = next(
@@ -2520,7 +2567,7 @@ class WorkflowTests(unittest.TestCase):
"correction", "hybrid", {"target": self.evaluation, "batch_from": "Ex 4"}
)
self.assertEqual(
command_arguments(command), [self.evaluation, "--batch-from", "Ex 4"]
command_arguments(command), [self.evaluation, "--workers", "12", "--batch-from", "Ex 4"]
)
def test_only_multi_target_steps_offer_free_form_arguments(self) -> None:
@@ -2624,7 +2671,8 @@ class WorkflowTests(unittest.TestCase):
self.evaluation,
verbose=True,
)
self.assertEqual(command_arguments(labels_command), [self.evaluation, "--verbose"])
self.assertEqual(command_arguments(labels_command),
[self.evaluation, "--workers", "12", "--verbose"])
rotate = self.steps["rotate"]
rotate_command = build_command(