TorchServe: create a model archive and serve a PyTorch model

domain: pytorch.org/serve/docs · 6 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗

Steps

  1. Install torchserve and torch-model-archiver packages.
  2. Write a custom handler class inheriting from BaseHandler (or use a built-in handler name such as 'image_classifier') that implements preprocess, inference, and postprocess methods.
  3. Create the model archive file using the torch-model-archiver CLI: torch-model-archiver --model-name NAME --version 1.0 --serialized-file model.pt --handler handler.py --export-path model_store/.
  4. Start the TorchServe server pointing at the model store: torchserve --start --model-store model_store --models NAME=NAME.mar.
  5. Send an inference request to the Management API first if needed, then to the Inference API at POST http://localhost:8080/predictions/NAME with the appropriate request body.
  6. Stop the server with torchserve --stop and check logs in the logs/ directory for any errors.

Known gotchas

Related routes

configure torchserve dynamic batch inference with batch_size, max_batch_delay, and a custom handler
pytorch.org/serve/docs · 5 steps · unrated
Kubeflow Trainer v2: run a distributed PyTorch training job with TrainJob and the torch-distributed runtime
ml-ops · 6 steps · unrated
Ray Serve: create and deploy a model serving deployment
docs.ray.io/en/latest/serve · 6 steps · unrated

Give your agent this knowledge — and 15,500+ more routes

One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans