private Tensor createTensorFromRawOutput(ByteBuffer buffer, String tritonType, List<Long> shape) {
        var vespaType = toVespaTensorType(tritonType, shape);
        var sizes = DimensionSizes.of(vespaType);
        buffer.order(ByteOrder.LITTLE_ENDIAN);
        var size = sizes.totalSize();
        var builder = (IndexedTensor.BoundBuilder) Tensor.Builder.of(vespaType, sizes);

        switch (tritonType) {
            case "BF16" -> {
                var shortBuffer = buffer.asShortBuffer();
                for (int i = 0; i < size; i++) {
                    builder.cellByDirectIndex(i, Fp16Conversions.bf16ToFloat(shortBuffer.get(i)));
                }
            }
            case "FP16" -> {
                var shortBuffer = buffer.asShortBuffer();
                for (int i = 0; i < size; i++) {
                    builder.cellByDirectIndex(i, Fp16Conversions.fp16ToFloat(shortBuffer.get(i)));
                }
            }
            case "FP32" -> {
                var floatBuffer = buffer.asFloatBuffer();
                for (int i = 0; i < size; i++) {
                    builder.cellByDirectIndex(i, floatBuffer.get(i));
                }
            }
            case "FP64" -> {
                var doubleBuffer = buffer.asDoubleBuffer();
                for (int i = 0; i < size; i++) {
                    builder.cellByDirectIndex(i, doubleBuffer.get(i));
                }
            }
            case "INT8" -> {
                for (int i = 0; i < size; i++) {
                    builder.cellByDirectIndex(i, buffer.get(i));
                }
            }
            case "INT16" -> {
                var shortBuffer = buffer.asShortBuffer();
                for (int i = 0; i < size; i++) {
                    builder.cellByDirectIndex(i, shortBuffer.get(i));
                }
            }
            case "INT32" -> {
                var intBuffer = buffer.asIntBuffer();
                for (int i = 0; i < size; i++) {
                    builder.cellByDirectIndex(i, intBuffer.get(i));
                }
            }
            case "INT64" -> {
                var longBuffer = buffer.asLongBuffer();
                for (int i = 0; i < size; i++) {
                    builder.cellByDirectIndex(i, longBuffer.get(i));
                }
            }
            default -> throw new TritonException("Unsupported type from ONNX output: %s".formatted(tritonType));
        }
        return builder.build();
    }
Experimental model inference using Nvidia Triton as ONNX backend.

@author bjorncs
model-integration/src/main/java/ai/vespa/triton/TritonOnnxClient.java