Persistent serving
Requires a Talario build. Licensed builds are available through sales. There is no public download. Availability
Because Talario is a PHP extension rather than a separate inference server, a model and its parameters can stay warm inside a long-lived PHP worker (FrankenPHP or Swoole) and serve requests with no IPC or serialization.
InferenceService#
InferenceService builds the device, the model, and a compiled forward graph
once, then replays the warm graph per request.
use Talario\{Device, InferenceService, Sequential, Linear, Activation}; $svc = new InferenceService( new Device('gpu'), fn ($dev) => new Sequential([ new Linear($dev, $inDim, 128), new Activation('relu'), new Linear($dev, 128, $outDim), ]), batch: 1, inDim: $inDim, outDim: $outDim, ); // per request: $logits = $svc->infer($features); // warm forward, zero sidecar $class = $svc->classify($features);
Under a persistent worker the Device, parameters and compiled graph are
constructed at boot and reused across requests; a request passes its features
as a PHP array, which infer() writes into the compiled graph's existing input
tensor with Tape::setInput() (no reallocation) before replaying the graph.
Runnable today: serve.php (NTS, no root)#
The resident-model pattern runs now over a plain userland HTTP socket, with no threads, no FrankenPHP, works with the default NTS PHP:
bin/kphp php/serve.php http cpu 127.0.0.1:5055 # or: gpu curl http://127.0.0.1:5055/health # {"status":"ok",...} curl -X POST http://127.0.0.1:5055/infer --data '[<floats>]'
The model (device + weights + compiled forward graph) is built once; each request
is setInput + one submit. php/serve_bench.php measures warm vs. cold.
Production: FrankenPHP worker mode#
php/serve_frankenphp.php is the worker reference; it loads optional trained
weights (KX_WEIGHTS=model.tal) and serves /infer + /health from a resident
model. Deploy with the sample Caddyfile:
frankenphp run --config docs/operations/Caddyfile.example
Config via env: KX_DEVICE (cpu|gpu), KX_IN/KX_H/KX_OUT, KX_WEIGHTS (.tal).
ZTS build (important prerequisite)#
FrankenPHP is thread-based and requires a ZTS (thread-safe) PHP, so
talario.so must be built ZTS to load into a FrankenPHP worker. The default
build targets the system NTS PHP (/usr/bin/php, Thread Safety => disabled)
and will not load into FrankenPHP. To productionize FrankenPHP serving:
- Obtain/point
phpize/php-configat a ZTS PHP 8.4 (e.g. FrankenPHP's embedded PHP, or a ZTS system build; installing one needs root). - Rebuild:
./build.shagainst that ZTS PHP → a ZTStalario.so. - Verify:
php -r 'echo PHP_ZTS ? "ZTS\n" : "NTS\n";'reportsZTS.
Threads: CPU devices are per object.
Until then, use serve.php (above) for the same resident-model, zero-IPC behavior
in an NTS environment.
Data-parallel training#
For multi-replica training on one node, DataParallel holds N identical
Sequential replicas and allReduce() averages each parameter's gradient across
them in place. A device-level peer-to-peer all-reduce in the HAL is not yet
implemented.
Using a coding agent?
Copy a prompt for Persistent serving, with 2 exact API signatures.