Skip to main content

A Pyodide python http client library and utilities for communicating with Triton Inference Server (based on tritonclient from NVIDIA)

Project description

Triton HTTP Client for Pyodide

A Pyodide python http client library and utilities for communicating with Triton Inference Server (based on tritonclient from NVIDIA).

This is a simplified implemetation of the triton client from NVIDIA, it works both in the browser with Pyodide Python or the native Python. It only implement the http client, and most of the API remains the similar but changed into async and with additional utility functions.

Usage

To use it in native CPython, you can install the package by running:

pip install pyotritonclient[native]

For Pyodide-based Python environment, for example: JupyterLite or Pyodide console, you can install the client by running the following python code:

import micropip
micropip.install("pyotritonclient")

To execute the model, we provide utility functions to make it much easier:

import numpy as np
from pyotritonclient import execute

# create fake input tensors
input0 = np.zeros([2, 349, 467], dtype='float32')
input1 = np.array([30], dtype='float32')
# run inference
results = await execute(inputs=[input0, input1], server_url='https://ai.imjoy.io/triton', model_name='cellpose-python')

You can access the lower level api, see the test example.

You can also find the official client examples demonstrate how to use the package to issue request to triton inference server. However, please notice that you will need to change the http client code into async style. For example, instead of doing client.infer(...), you need to do await client.infer(...).

The http client code is forked from triton client git repo since commit b3005f9db154247a4c792633e54f25f35ccadff0.

To simplify the manipulation on stateful models with sequence, we also provide the SequenceExecutor to make it easier to run models in a sequence.

from pyotritonclient import SequenceExcutor
(image, labels, info) = train_samples[0]

model_id = 100
async with SequenceExcutor(
    server_url='https://ai.imjoy.io/triton',
    model_name='cellpose-train',
    auto_end=True,
    sequence_id=model_id) as se:

    for i in range(2):
      print(await se.execute([
                  image.astype('float32'),
                  labels.astype('float32'),
                  {"steps": 1, "pretrained_model": None}
                ]))

Note that above example used auto_end=True, this means when exiting the block, the last inputs will be sent again to end the sequence. If you don't want that, you can set auto_end=False and run se.execute(..., sequence_end=True) before exiting the block.

Server setup

Since we access the server from the browser environment which typically has more security restrictions, it is important that the server is configured to enable browser access.

Please make sure you configured following aspects:

  • The server must provide HTTPS endpoints instead of HTTP
  • The server should send the following headers:
    • Access-Control-Allow-Headers: Inference-Header-Content-Length,Accept-Encoding,Content-Encoding,Access-Control-Allow-Headers
    • Access-Control-Expose-Headers: Inference-Header-Content-Length,Range,Origin,Content-Type
    • Access-Control-Allow-Methods: GET,HEAD,OPTIONS,PUT,POST
    • Access-Control-Allow-Origin: * (This is optional depending on whether you want to support CORS)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyotritonclient-0.1.16.tar.gz (20.0 kB view details)

Uploaded Source

Built Distribution

pyotritonclient-0.1.16-py3-none-any.whl (22.1 kB view details)

Uploaded Python 3

File details

Details for the file pyotritonclient-0.1.16.tar.gz.

File metadata

  • Download URL: pyotritonclient-0.1.16.tar.gz
  • Upload date:
  • Size: 20.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.0.1 pkginfo/1.5.0.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.7.8

File hashes

Hashes for pyotritonclient-0.1.16.tar.gz
Algorithm Hash digest
SHA256 afc310f0a525e286494ce571ff596a001eefe0a0cc14c913679d12f2b9f173a9
MD5 0f00210dc435d0b494aab38afbdf1909
BLAKE2b-256 bbb20f8fcc87f2702420b7675035692e0429b071b301c820f2f52c8f3adf1487

See more details on using hashes here.

File details

Details for the file pyotritonclient-0.1.16-py3-none-any.whl.

File metadata

  • Download URL: pyotritonclient-0.1.16-py3-none-any.whl
  • Upload date:
  • Size: 22.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.0.1 pkginfo/1.5.0.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.7.8

File hashes

Hashes for pyotritonclient-0.1.16-py3-none-any.whl
Algorithm Hash digest
SHA256 21904e080534031f34a3e92507b8fcc2e1bc2105e28ef7cc7a708fd89dea6c7c
MD5 e416f481c7db34aa3b30787bf4250c1f
BLAKE2b-256 e09fbe2c7dc86473a4bc40def30af16c731ba8f1aa3b366356a5b4db4723d067

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page