Keras–TensorFlow concurrency: Can one shared model serve requests predictably?
0 reputation · 30 Jul 2023, 14:01 UTC
0 reputation · 30 Jul 2023, 14:01 UTC
A service built with Keras 3 on the TensorFlow backend needs to determine whether a single shared model instance can handle concurrent inference requests without unpredictable tail latency. The integration boundary matters because Keras delegates execution to the active backend, while the TensorFlow runtime controls graph execution, thread pools, and accelerator resource scheduling. No Keras-level contract establishes bounded latency for concurrent predict calls.
The target is TensorFlow 2.x with Keras 3, but equivalent deployments may use the JAX or PyTorch backend, where the same sharing pattern may behave differently. Thread configuration, eager versus compiled execution, GPU memory growth, and request-handler overhead can confound the result. A useful evaluation must compare sequential and concurrent latency for the same instance, including p50 and p99, while distinguishing backend contention from application scheduling.
Which Keras 3 and TensorFlow versions should define the supported baseline? What benchmark can distinguish backend-level contention from request-handler overhead before choosing a shared-instance deployment model?
35505 reputation · 31 Jul 2023, 01:51 UTC
No. Keras 3 on the TensorFlow backend publishes no bounded-latency contract for concurrent predict calls on one shared model instance. A shared instance can serve requests predictably only after you constrain inputs, warm up execution, pin thread and memory settings, and verify tail latency under load. Without those controls, p99 spikes are expected from thread-pool contention, retracing, accelerator scheduling, or request-handler overhead—not from model sharing itself.
Use Keras 3 with a TensorFlow 2.x backend, not Keras 2 or TensorFlow 1.x. Pin one Keras 3 / TensorFlow 2.x minor pair verified together in staging. Exact minor versions cannot be certified here; record the pair in the test environment and treat it as a deployment unit.
tf.config.threading intra-op and inter-op threads only before model creation; settings are process-wide.python -c "import keras, tensorflow as tf; print(keras.config.backend(), keras.__version__, tensorflow.__version__)"
Assumption: fixed input shapes and eager or compiled execution are used; variable shapes or unbounded automatic batching invalidate the baseline. Uncertainty: exact Keras 3 / TensorFlow 2.x minor versions and accelerator-specific behavior require current release verification.
Missing diagnostic that can change the recommendation: Is the target accelerator CPU or GPU? On GPU, enable memory growth before model initialization; on CPU, thread-pool sizing is usually the dominant tuning variable.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.