How to work with pb_utils.InferenceRequest and pb_utils.InferenceResponse on the Python backend?
#8546
Replies: 1 comment
|
The Python backend does document pb_utils.InferenceRequest/pb_utils.InferenceResponse field-by-field, but it's in the python_backend repo README, not the docs site the introduction page links to. There is no separate API reference/docstring page — the README and the triton_python_backend_utils.py stub source (which ships as the pb_utils module's pure-Python helpers) are the closest thing to a spec. Sections to read directly:
Confirmed API surface (from README + triton_python_backend_utils.py): InferenceRequest (received in execute(self, requests)):
You can also construct an InferenceRequest yourself for BLS calls: Source: BLS section, lines around inference_request.exec(). InferenceResponse (what you return from execute, or what .exec() gives back):
Minimal, complete model.py skeleton combining request read + response write (adapted from the official add_sub example, untested by me but a direct pattern lift from the documented usage): python class TritonPythonModel: Key rules called out explicitly in the README (confirmed, not hypotheses):
Version-gated features to watch for (confirmed from README changelog notes inline): parameters= on InferenceRequest constructor (23.11+), preferred_memory (23.04+), is_cancelled() (23.10+), async_exec (24.04+), sending responses via InferenceResponseSender from default mode (24.06+). If you hit a TypeError/missing-attribute error, check your container's Triton version against these. Not covered by the README and not verifiable without your specific container/version: the exact set of methods on pb_utils.Tensor, GPU/DLPack interop details beyond to_dlpack/from_dlpack/is_cpu, and any behavior differences between backend releases — see the Interoperability and GPU Support section and, if still unclear, the C++ implementation in src/pb_utils.h / src/infer_request.h and src/infer_response.h, which are the actual pybind11 bindings behind these classes. If a specific field/method you need isn't listed above, say which one and which Triton container version you're on — that narrows it to a source-code lookup instead of guessing. |
Uh oh!
There was an error while loading. Please reload this page.
I've read many pages here: https://docs.nvidia.com/deeplearning/triton-inference-server/user-guide/docs/introduction/index.html, but it seems there is no complete information about it. Some tutorials only show specific examples but I cannot find any field or method descriptions (which are needed to carefully use the classes in my case).
All reactions