Skip to main content

PyFunc Server

PyFunc Server is Kserve extension for deploying user-defined python function model. It leverages mlflow.pyfunc model for model loading.

Usage

HTTP Server

Run following command to load sample echo-model model and start HTTP server:

PROMETHEUS_MULTIPROC_DIR=prometheus \
python -m pyfuncserver --model_dir echo-model/model

This will start http server at port 8080 which you can test using curl command

curl localhost:8080/v1/models/model-1:predict -H "Content-Type: application/json" -d '{}'

UPI V1 Server

Run following command to load sample echo-model model and start UPI v1 server:

PROMETHEUS_MULTIPROC_DIR=prometheus \
CARAML_PROTOCOL=UPI_V1 \
WORKERS=2 python -m pyfuncserver --model_dir echo-model/model

Since UPI v1 interface is gRPC then you can use grpcurl to send request

grpcurl -plaintext -d '{}'  localhost:9000 caraml.upi.v1.UniversalPredictionService/PredictValues

Development

Requirements:

  • pipenv

To install locally (including test dependency):

pipenv shell
make setup

To run all test

make test

To run benchmark

make benchmark

Configuration

Pyfunc server can be configured via following environment variables

Environment Variable Description
CARAML_PROTOCOL Protocol to be used, the valid values are HTTP_JSON and UPI_V1
CARAML_HTTP_PORT Pyfunc server will start http server listening to this port when CARAML_PROTOCOL = HTTP_JSON
CARAML_GRPC_PORT Pyfunc server will start grpc server listening to this port when CARAML_PROTOCOL = UPI_V1
CARAML_MODEL_NAME Model name
CARAML_MODEL_VERSION Model version
CARAML_MODEL_FULL_NAME Model full name in the format of ${CARAML_MODEL_NAME}-${CARAML_MODEL_FULL_NAME}
WORKERS Number of Python processes that will be created to allow multi processing (default = 1)
LOG_LEVEL Log level, valid values are INFO, ERROR, DEBUG, WARN, CRITICAL (default='INFO')
GRPC_OPTIONS GRPC options to configure UPI server as json string. The possible options can be found in grpc_types.h. Example: '{"grpc.max_concurrent_streams":100}'
GRPC_CONCURRENCY Size of grpc handler threadpool per worker (default = 10)
PUSHGATEWAY_ENABLED Enable pushing metrics to prometheus push gateway, only available when CARAML_PROTOCOL is set to UPI_V1 (default = false)
PUSHGATEWAY_URL Url of the prometheus push gateway (default = localhost:9091)
PUSHGATEWAY_PUSH_INTERVAL_SEC Interval in seconds for pushing metrics to prometheus push gateway (default = 30)

Directory Structure

├── benchmark              <- Benchmarking artifacts
├── docker                 <- Dockerfiles and environment files
    ├── Dockerfile         <- Dockerfile that will be used by kaniko to build user image in the cluster
    ├── base.Dockerfile    <- Base docker image that will be used by `Dockerfile`
├── examples               <- Examples of PyFunc models implementation
├── test                   <- Test package
├── pyfuncserver           <- Source code of this workflow
│   ├── __main__.py        <- Entry point of pyfuncserver
│   ├── config.py          <- Pyfuncserver configurations
│   ├── server.py          <- Main server that orchestrate the initialization of all server within pyfuncserver
│   ├── metrics            <- Module related to pubishing prometheus metrics
│   ├── utils              <- Utility package
│   ├── model              <- Model package
│   └── protocol           <- Protocol implementations
│       └── rest           <- Server implementation for HTTP_JSON protocol
│       └── upi            <- Server implementation for UPI_V1 protocol
├── .gitignore
├── Makefile               <- Makefile
├── README.md              <- The top-level README for developers using this project.
├── requirements.txt       <- pyfuncserver dependencies
├── setup.py               <- setup.py
├── run.sh                 <- Script to activate `merlin-model` environment and run pyfuncserver when `docker run` is invoked

Metadata

Release files for merlin-pyfunc-server 0.50.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for merlin-pyfunc-server 0.50.0
File Size Uploaded Provenance Actions
merlin_pyfunc_server-0.50.0.tar.gz 50.5 kB Without provenance Details for merlin_pyfunc_server-0.50.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for merlin-pyfunc-server 0.50.0
File Interpreter ABI Platform Actions
merlin_pyfunc_server-0.50.0-py3-none-any.whl Python 3 none any Details for merlin_pyfunc_server-0.50.0-py3-none-any.whl

Total release size: 77.1 kB

Release files / merlin_pyfunc_server-0.50.0.tar.gz

Download URL merlin_pyfunc_server-0.50.0.tar.gz
Size 50.5 kB
Tags Source
SHA-256 checksum
How to use checksums
cb9bfdb03539bfff7f18e2c4ba0c67d28c6d44da78de5314eb3d6b4f6275535a
BLAKE2b-256 checksum
How to use checksums
f220d3d3480b79f4a693d04f16df2bce1d8cc11a8b09ba0e412c9a6e6dbaad2f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release files / merlin_pyfunc_server-0.50.0-py3-none-any.whl

Download URL merlin_pyfunc_server-0.50.0-py3-none-any.whl
Size 26.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cd425f9bb574d64e22f0595d743c5f4d730b5ddda95a0371efabc3885a046f20
BLAKE2b-256 checksum
How to use checksums
f3813122c17003a92963e1d4946883824e3c0701ac3476fff52ccfaf28c61eaa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Security for merlin-pyfunc-server 0.50.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.50.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page