Add guide: Serving KerasHub models with vLLM using Kinetic - #267
Add guide: Serving KerasHub models with vLLM using Kinetic#267Dhiraj099 wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a new guide and example script for exporting KerasHub models to Hugging Face Transformers format and serving them with vLLM on Cloud GPUs or TPUs using Kinetic. The feedback focuses on improving robustness and resource utilization: first, by uploading the exported model directory directly to GCS using transfer_manager instead of creating a large .tar archive in /tmp which could cause GKE pod eviction; second, by persisting the exported model to GCS before initializing the high-risk vLLM engine; and finally, updating the documentation to reflect these direct directory transfer workflows.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
What this adds
examples/vllm_serving.py+examples/export_worker.py— a self-contained example that exports a KerasHub causal LM withexport_to_transformers()and serves it with vLLM in a single Kinetic job, on TPU or GPU, with any Keras backend (jax / torch / tensorflow).docs/guides/vllm_serving.md— the guide.How it works
One Kinetic job: download the KerasHub preset → export with
export_to_transformers()in a child process → the child exits and the OS reclaims its framework state and device memory → vLLM starts on the exported directory in the now-clean process → continuous-batched completions are returned to the local machine.DEVICE = "tpu" | "gpu"selects the accelerator, requirements, and serve config;BACKENDselects the Keras export backend (defaults to the one natural to the device, which needs no extra deps).Design notes
Why a subprocess for the export (instead of doing it in-process). Exporting and serving in the same process only works cleanly for one combination — torch on GPU (no libtpu, and
torch.cuda.empty_cache()returns VRAM). Everywhere else, in-process breaks or is fragile:Running the export in a child process that exits first reclaims its entire memory/state and is the single pattern correct for every device × backend, with no hardcoded backend and no manual cleanup. (Kinetic unpacks job files onto
sys.path; the parent resolves the worker withfind_specwithout importing it, so Keras/TF never load in the serve process.)architectureskey — handled upstream, not patched here. vLLM routes checkpoints via thearchitectureskey inconfig.json. Gemma 3's exporter writes it, so this example (published for Gemma 3) needs no patch. The GPT-2 / Qwen / Gemma exporters don't write it yet — that should be fixed in those keras-hub exporters (follow-up) rather than worked around in user-facing example code._setup_gpu_runtime()(GPU only) — exposes the GKE-mounted NVIDIA driver onLD_LIBRARY_PATH(inherited by the export child, so the export loads onto the GPU, not host RAM) and disables FlashInfer'snvccJIT. Runs before the export. No-op once the GPU image ships the driver on the path (#269).Validated runs
gemma3_4bontpu-v5litepod-1gemma3_4bon L4.Contributor Agreement
Please check all boxes below before submitting your PR for review: