Repository navigation
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a mechanism to reflect a self-hosted worker's authoritative output statistics (completed/failed counts and token usage) onto the batch job status before finalizing, avoiding overwriting the worker's output. Feedback suggests optimizing reflect_job_output_stats to count records and sum token usage in a single pass over the output file to avoid reading the file twice and reduce I/O latency.
|
@zhangjyr please help review this change |
zhangjyr
left a comment
There was a problem hiding this comment.
Hi @V-3604, thank you for your work on fixing k8s job finalization.
Although we are currently focused more on k8s deployment support, the k8s job path has drifted a bit from the intended design, especially after the recent state-fixing patch.
At a high level, _await_self_hosted_run() is the k8s job equivalent of execute_worker(job_id). Even though it is simplified, the expected flow should still be:
- Wait for runtime completion.
- Finalize the job.
The current _await_self_hosted_run() implementation deviates from this design because it sets the finalizing state directly, instead of calling finalize_job() and letting _progress_manager.mark_job_finalizing() handle the state transition.
I would suggest calling finalize_job() directly inside _await_self_hosted_run() rather than reimplementing the finalization logic there.
For testing, python/aibrix/tests/batch/test_e2e_openai_batch_api.py::test_openai_batch_api_success_workflow can be used for end-to-end validation by specifying the test backend with the -k k8s_job keyword. It looks like the k8s_job keyword was accidentally removed in the current version. Could you please add it back?
|
@zhangjyr Hi, I rebased on main. #2360 removed the |
|
@V-3604 After reviewing the existing code, I found there is a fundamental misunderstanding of the existing worker code. Worker: complete with other workers to win requests and process them; no finalization should be made on the worker. MDS controller: wait for the k8s_job runtime to complete and finalize. With this clarified, I think the worker will not consume metastore markers, and the existing finalize_job should work properly. |
|
Confirmed, thanks. The worker should win and process requests only, not finalize. worker.py builds the worker I'll set |
Signed-off-by: Varshith <[email protected]>
2456b28 to
989b3bf
Compare
|
Pushed the rework as a single commit over the two earlier ones: One open question: the k8s_job E2E needs a new |
|
@V-3604 Thanks. Yes, I would prefer that k8s_job be added back to E2E_BACKENDS of E2E tests. In fact, the E2E series tests support real k8s jobs. The naming conventions of backends are like:
#2415 provides an example of how to define job_using_k8s_job. |
Signed-off-by: Varshith <[email protected]>
|
Added local_job_using_k8s_job to E2E_BACKENDS in the latest commit, following the local_job_using_[xxxx] convention with local storage and metastore behind a fake runtime. A FakeBatchV1Api backs the runtime, patched in over the real-cluster fallback since the slotted InfrastructureContext has no batch_v1_api field to inject through. The worker runs in-process in worker_mode as a stand-in for the Job's pod, so it writes the output parts and per-request done markers and leaves finalization to the coordinator, which aggregates the surviving markers in finalize_job. That is the self-hosted path the deployment backend does not reach, since the deployment fake dispatches from the control plane. I kept the real job_using_k8s_job on TOS plus Redis out of this PR. It depends on the Redis-backed metastore wiring from #2415, and #2415 already notes the fake K8s Job backend should land first, so it belongs alongside that change. Verified with pytest tests/batch/test_e2e_openai_batch_api.py::test_openai_batch_api_success_workflow -k local_job_using_k8s_job (1 passed). |
Pull Request Description
In
KubernetesJob(self-hosting) mode the worker pod ran itsBaseJobDriverwithoutworker_mode, so_should_finalize()was True and the worker ranfinalize_job. Since #2360 that callsfinalize_job_output_dataunconditionally, which aggregates the per-requestbatch:<job_id>:done/*markers, completes the multipart upload, and consumes the markers, all inside the Job pod._await_self_hosted_runon the metadata service then only flipped the job toFINALIZINGwith its stale in-memory copy; when it aggregated it found the markers already consumed, recomputedcompleted/failedas 0 andusageas null, and committed an empty multipart over the worker's output. A completedKubernetesJobbatch therefore persistedcompleted = 0andusage = nullwhile the correct records had been assembled and then overwritten.The worker's
BaseJobDriveris now built withworker_mode=True, so it dispatches requests and writes its output parts and per-request done markers but does not finalize.SingleJobRunner.mark_job_doneis pod-local, so this only affects the worker's own status._await_self_hosted_runnow callsfinalize_jobon the metadata service, which aggregates from the surviving markers, assembles the output/error files, and records the realrequest_counts/usagebefore marking the job done. TheDeploymentpath keeps its endpoint and aggregates in the metadata process, so it is unchanged.test_self_hosted_run_finalizes_on_successasserts the self-hosted run aggregates throughfinalize_job; it fails on the current code, where the run only setsFINALIZING, and passes with this change.test_run_constructs_driver_in_worker_modeasserts the worker builds its driver withworker_mode=True.Both affected files pass with no regressions (
9 passed).Related Issues
Resolves #2263
Important: Before submitting, please complete the description above and review the checklist below.
Contribution Guidelines (Expand for Details)
We appreciate your contribution to aibrix! To ensure a smooth review process and maintain high code quality, please adhere to the following guidelines:
Pull Request Title Format
Your PR title should start with one of these prefixes to indicate the nature of the change:
[Bug]: Corrections to existing functionality[CI]: Changes to build process or CI pipeline[Docs]: Updates or additions to documentation[API]: Modifications to aibrix's API or interface[CLI]: Changes or additions to the Command Line Interface[Misc]: For changes not covered above (use sparingly)Note: For changes spanning multiple categories, use multiple prefixes in order of importance.
Submission Checklist
By submitting this PR, you confirm that you've read these guidelines and your changes align with the project's contribution standards.