TECHNOLOGY

Request Triton binary outputs without assuming JSON arrays

In this article
THE QUICK TAKE

Drive binary-output decoding from returned tensor metadata and boundaries, including per-output representation overrides.

A consumer requests a binary Triton output to avoid parsing a large JSON array, but then sends the entire response to a JSON decoder. The response contains a JSON metadata prefix and a binary tail. Output selection, returned boundaries and tensor layout must all agree before the consumer can reconstruct values safely.

Request the output representation explicitly

The binary extension supports output-level binary selection and a request-level default, with the documented per-output override. Specify only the tensors the consumer needs and keep their intended representation clear. A server may legitimately return some outputs as JSON and others as binary under those settings. Do not infer the encoding of every tensor solely from a request-wide preference if an individual output overrides it.

Parse metadata before tensor bytes

Use the received inference-header length to delimit the JSON prefix. Parse that prefix to obtain output names, shapes, data types and binary block sizes. The metadata describes the actual returned outputs and must drive decoding. A client-side assumption about the model’s usual order can become wrong after an intentional output selection or version change. Do not search for a brace or newline to discover where JSON ends inside arbitrary binary content.

Decode the documented layout

The extension defines binary tensor ordering and layout, including byte order and contiguous element representation. Interpret each block under its declared type and shape. A host-language array view can have a different native byte order or alignment assumption. Use an appropriate decoder or client utility and verify the resulting element count. BYTES output requires its own element-length handling rather than a fixed-width numeric view.

Keep limits around received sizes

Check that every declared block fits within the received body and that size arithmetic cannot overflow the chosen integer representation. A malformed response should fail before the client allocates an unreasonable buffer. Distinguish a complete but schema-incompatible tensor from a truncated HTTP body. The former is an API contract problem; the latter is a delivery failure. Preserve enough safe metadata to diagnose the difference without logging all generated content.

Compare against a small reference

Use a deterministic synthetic model or fixture whose output values are known. Request the same tensor in JSON and binary forms and compare decoded values under the intended numerical tolerance. Exercise mixed output representations and a deliberately truncated response. Acceptance means correct tensor reconstruction and bounded failure handling across the selected forms. It does not establish that binary transfer is always faster: serialization, copy behavior and workload size affect the result. Measure the full consumer path separately from model execution and retain the simpler representation when it better serves a small output.

Primary references

Triton Binary Tensor Data Extension. Defines binary output controls, per-output overrides and response layout.

KServe Inference Protocol required APIs. Defines output names, shapes and response tensor metadata.

Triton Model Configuration. Defines model output types and dimensions that a consumer must interpret correctly.

Related reading: Define variable-length token input contracts for Triton ragged batching; Separate Triton queue, input, inference and output latency.

Earn rental income from GPUs

Have idle GPUs or looking to fund AI infrastructure? Retrivium finds a rental platform, sets up the server and helps you assess income and costs with a pilot.

Explore GPU hosting
← All articles