Talario for Laravel
How Talario will fit the Laravel app you already run: the model stays in the worker, with no serving sidecar and no IPC hop per prediction.
talario/laravel package is not yet on Packagist;
these examples use the extension's classes directly.
Contact sales.
Keep a model warm
Build the device, model and compiled graph once and reuse them for every request. Under
FrankenPHP
or Swoole/Octane the worker is long-lived, so bind an InferenceService as a singleton and it
stays resident across requests:
// config/services.php (read env() only in config, so config:cache keeps the value)
'talario' => [
'device' => env('TALARIO_DEVICE', 'auto'), // 'cpu' | 'gpu' | 'auto'
],
// app/Providers/AppServiceProvider.php
use Talario\Device;
use Talario\Linear;
use Talario\Sequential;
use Talario\InferenceService;
use function Talario\relu;
public function register(): void
{
$this->app->singleton(InferenceService::class, function () {
$dev = new Device(config('services.talario.device', 'auto'));
$in = 64; $out = 10; $h = 128;
$build = fn (Device $d) => new Sequential([
new Linear($d, $in, $h, seed: 1), relu(),
new Linear($d, $h, $out, seed: 2),
]);
// Load your trained weights into the model here (see loadState()).
return new InferenceService($dev, $build, batch: 1, inDim: $in, outDim: $out);
});
}
Infer in a controller
use Talario\InferenceService;
public function predict(Request $request, InferenceService $model)
{
$data = $request->validate([
'features' => ['required', 'array', 'size:64'],
'features.*' => ['numeric'],
]);
return response()->json(['logits' => $model->infer($data['features'])]); // warm model, no reload
}
The service is built once and resolved from the container on each request. Always validate and cap input shape on public endpoints.
Train in a queued job
Training is a normal queued job: build a Tape, run the forward pass and
backward(), step an optimizer (SGD/Adam), then persist the layer state for the serving model to load. Keep training off the request
path; the examples show the full loop.
Octane & FrankenPHP
The resident-model pattern is exactly what long-lived workers are for: construct the model at worker
boot, not per request. Under Octane, resolve the singleton in your controller; under a FrankenPHP worker
script, build the InferenceService once and reuse it in the request loop. See the
serving guide.
See the examples, the full user guide, and submit what you build to the showcase.
Using a coding agent?
Copy a prompt for Laravel integration, with 2 exact API signatures.