Skip to main content

No project description provided

Project description

FastQL Inference Server

Spin up a blazing fast Rust GraphQL API and query around your ML model in one line of python code.

We include an example which can deploy and serve stable diffusion / runwayml / midjourney or any of the diffusers models in seconds.

We've observed about a 2x speed up across the example schema vs a FastAPI/Ariadne python GraphQL server with identical schema. This is because although the model code is in python, the API is actually a Rust process running ActiX.

Please note

  • Does not include an auth mechanism, you can implement auth using an API Gateway or auth proxy.
  • Can only create flat / non nested schema.
  • Make sure you set RUST_ENV to production if you are using it on a remote machine.
  • This is currently a prototype and should not be used in production.

Why would I need FastQL?

  • FastQL encourages seperation of your API and model, allowing you to focus on your model code, making PRs with your model code completely detached from the API layer.
  • All the benefits of GraphQL... Fetch data with single API call, no overfetching, autogenerated API documentation, validation and type checking out-of-the-box, API evolution without versioning, subscriptions (websockets) as a first class citizen (to be implemented soon).
  • FastQL is really fast, much faster than a pure python implementation, the example schema has a latency of < 20ms when tested locally.
  • FastlQL is Apollo federation compliant, which means that you can aggregate many models into a single curated API using schema stitching. This means you can maintain both fixed and dynamic schema's for params to your models, so it is easy to test new features and benefit from federation versioning.
  • FastQL gives you GraphQL playground for testing and demonstrating your prototype models.
  • Because ML models are typically sequential in terms of request response pattern, requests to the model are always blocking,response time is the important bottleneck FastQL is focused on reducing.

Installation

pip install fastqlapi

Usage

Visit localhost:8000/graphiql for the graphql playground UI or make a request to localhost:8000.

example:

from fastqlapi import fastql_server
def infer(**kwargs):
    print (kwargs['input'])
    return {
        'output': "test response",
    }

fastql_server.start(callback=infer, query_name="Model", args={"input": { "type": "String", "description": "this is my input field"}}, fields={"output": { "type": "String"}})

or try with the example schema:

from fastqlapi import fastql_server, test_args, test_fields

def infer(**kwargs):
    print (kwargs['prompt'])
    return {
        "tokens": ["example", "tokens"],
    }

fastql_server.start(callback=infer, args=testargs, fields=testfields)

Spin up an example hugging face diffusers GraphQL API using Docker on AWS EC2

NB. these examples are not suitable for production

  • Launch an EC2 GPU powered instance (for example p3.2xlarge)
  • Search for NVIDIA GPU-Optimized PyTorch AMI in the Amazon Machine Image search bar.
  • Select this AMI and configure storage to 64GIB.
  • You will need to set a PEM key-pair, download and chmod the key on your local machine using chmod 400 {{key pair name}}.
  • Launch your instance.
  • In the security tab for your instance select the auto-created or chosen security group and add an inbound rule setting custom TCP and port 8000 (graphql api) to 0.0.0.0/0 (or more appropriate scoped access) and another setting port 8080 (image server) to 0.0.0.0/0.-
  • Sign up at https://huggingface.co/ to get your free ACCESS_TOKEN.
  • Setup aws configure with the command aws configure and enter access key details after creating an access key in the IAM panel.
  • Run the following commands to set your public IP:
EC2_INSTANCE_ID="`wget -q -O - http://169.254.169.254/latest/meta-data/instance-id || die \"wget instance-id has failed: $?\"`"
export PUBLIC_IP=$(aws ec2 describe-instances --instance-ids $EC2_INSTANCE_ID --query 'Reservations[*].Instances[*].PublicIpAddress' --output text)
  • Connect to your instance and use our example docker image on danfreshbc/fastqlapi-diffusers or run your published docker image similar to:
docker run -p 8000:8000 -p 8080:8080 \
    -e PUBLIC_IP=$PUBLIC_IP \
    -e MODEL_ID="stabilityai/stable-diffusion-2" \
    --gpus all danfreshbc/fastqlapi-diffusers:latest
  • You can echo $PUBLIC_IP to get your public IP or find it in your EC2 console instance details.
  • Connect to {{EC2_PUBLIC IP}}:8000/graphql to visit your new GraphQL API and make sure that the URL next to the history button contains {{EC2_PUBLIC IP}}:8000
  • An example query:
{
  Model1(prompt: "a handsome man holding a baby goat") {
    images
  }
}

You can change MODEL_ID to one of the following to try a different diffusers model for example:

"CompVis/stable-diffusion-v1-4"
"stabilityai/stable-diffusion-2"
"runwayml/stable-diffusion-v1-5"

The example API surfaces prompt, number_of_images, guidance_scale, number_inference_steps and seed and returns an array of images or a seed.

A further diffusers example implementing fine tuning

NB. This should use a mutation, mutation support coming soon!

This example allows you to download a folder of images from google drive or individual gdrive image ids. It will then fintune the model on these images so you can run inference against them. This example will overwrite the model each time you upload new files.

  • Setup your instance as above but with a machine with more than 16GB ram for example m5.2xlarge
  • Use the following docker command:
docker run -p 8000:8000 -p 8080:8080 \
    -e PUBLIC_IP=$PUBLIC_IP \
    -e MODEL_ID="stabilityai/stable-diffusion-2" \
    --gpus all danfreshbc/fastqlapi-diffusers:latest bash start_finetune.sh

To start finetuning use a query like below:

{
  Model(
    fine_tune_photo_description: "Photo of happymachine"
    gdrive_folder_of_images_link: "https://drive.google.com/drive/folders/17g_m3eaBA6SJQP-xppGkAHXYoKCLObZg"
  ) {
    images
  }
}

To infer:

{
  Model(prompt: "happymachine standing in front of an F1 McLaren") {
    images
  }
}

Further info

  • FastQL implements all the basic GraphQL types and array types, including required types but not currently required subtypes (an element of a list).

  • Using types URL, URL!, [URL] or [URL!] in python code will translate to GraphQL String equivalents, but will cause a valid URL that is sent under that type to be downloaded.

  • Under the hood FastQL uses the actix rust web server which is currently no.5 fastest web framework according to Tech Empower. By comparison, Python's FastAPI is at no.93. We've observed about a 2x speed up across the example schema here vs a FastAPI/Ariadne python GraphQL server with the same schema.


Environment variables

GRAPHQL_HOST Default localhost

GRAPHQL_PORT Default 8000

MODEL_ID The diffusers model ID for the huggingface diffusers model you want to launch

ACCESS_TOKEN Your huggingface diffusers access token

ENABLE_GRAPHIQL Will enable GraphiQL | default to true unless RUST_ENV is set to production (in which case setting ENABLE_GRAPHIQL=true will still overide)

ENABLE_CORS default false

CORS_PERMISSIVE Should be used in Development/Test only, allows all headers and origins, credentials supported, maximum age 1 hour does not send wildcard | default false

ALLOW_AUTHORIZATION_HEADER default false

ALLOW_ORIGIN_HEADER default false

ALLOW_CONTENT_TYPE_HEADER default false

MAX_AGE_HEADER default 3600

RUST_LOG Rust log level | default 'debug'

RUST_BACKTRACE Add rust backtrace to log | default 1

RUST_QUIET No rust logs | default false

TRACING Turn on Apollo tracing | default false


License

The code in this repo is released under the MIT license.

Thank you

The folks at Hugging Face
The team at Actix
Sunli @ Async-graphql.rs
The team at Maturin

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

fastqlapi-0.3.5-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.1 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

fastqlapi-0.3.5-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.1 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

fastqlapi-0.3.5-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.1 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

fastqlapi-0.3.5-cp311-none-win_amd64.whl (3.2 MB view details)

Uploaded CPython 3.11Windows x86-64

fastqlapi-0.3.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

fastqlapi-0.3.5-cp311-cp311-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (7.0 MB view details)

Uploaded CPython 3.11macOS 10.9+ universal2 (ARM64, x86-64)macOS 10.9+ x86-64macOS 11.0+ ARM64

fastqlapi-0.3.5-cp310-none-win_amd64.whl (3.2 MB view details)

Uploaded CPython 3.10Windows x86-64

fastqlapi-0.3.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

fastqlapi-0.3.5-cp310-cp310-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (7.0 MB view details)

Uploaded CPython 3.10macOS 10.9+ universal2 (ARM64, x86-64)macOS 10.9+ x86-64macOS 11.0+ ARM64

fastqlapi-0.3.5-cp39-none-win_amd64.whl (3.2 MB view details)

Uploaded CPython 3.9Windows x86-64

fastqlapi-0.3.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.1 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

fastqlapi-0.3.5-cp39-cp39-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (7.0 MB view details)

Uploaded CPython 3.9macOS 10.9+ universal2 (ARM64, x86-64)macOS 10.9+ x86-64macOS 11.0+ ARM64

fastqlapi-0.3.5-cp38-none-win_amd64.whl (3.2 MB view details)

Uploaded CPython 3.8Windows x86-64

fastqlapi-0.3.5-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.1 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

fastqlapi-0.3.5-cp38-cp38-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (7.0 MB view details)

Uploaded CPython 3.8macOS 10.9+ universal2 (ARM64, x86-64)macOS 10.9+ x86-64macOS 11.0+ ARM64

fastqlapi-0.3.5-cp37-none-win_amd64.whl (3.2 MB view details)

Uploaded CPython 3.7Windows x86-64

fastqlapi-0.3.5-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.1 MB view details)

Uploaded CPython 3.7mmanylinux: glibc 2.17+ x86-64

fastqlapi-0.3.5-cp37-cp37m-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (7.0 MB view details)

Uploaded CPython 3.7mmacOS 10.9+ universal2 (ARM64, x86-64)macOS 10.9+ x86-64macOS 11.0+ ARM64

File details

Details for the file fastqlapi-0.3.5-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for fastqlapi-0.3.5-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7b56805a1d8d8ea378bb45837b339ccd2de9db5df89c1a0c1cd71da1f43dfcd6
MD5 5a0ecc4b0c2b2e54029df287ca665d37
BLAKE2b-256 0671551e3f11420ffb26436bf038f6acbbc339e531ac830bbdec6a93bbc0dd56

See more details on using hashes here.

File details

Details for the file fastqlapi-0.3.5-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for fastqlapi-0.3.5-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7f9ab4eda61de1069faa071abfa1bea46d7d03e7b33496cfa2033bb840a4096e
MD5 bc100ee9e033787ab9182c575ad4f6f8
BLAKE2b-256 b96952b4ebfebf19e4267e3b50bed9cc7ba4b1591e83f574eab8d227aa9d3270

See more details on using hashes here.

File details

Details for the file fastqlapi-0.3.5-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for fastqlapi-0.3.5-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7b97680161400a8596e9cac04feeec4026ee60c0a910d87243db11cff7d1c0f3
MD5 b651cdd8965afc7d3b86a23ebcbbee8c
BLAKE2b-256 fc67cace9baa5f4476d6a0bd3aa9e53050954d1539b953988ffb08218ac1fc86

See more details on using hashes here.

File details

Details for the file fastqlapi-0.3.5-cp311-none-win_amd64.whl.

File metadata

File hashes

Hashes for fastqlapi-0.3.5-cp311-none-win_amd64.whl
Algorithm Hash digest
SHA256 eee82e1f98792a8680fb9eec65fe7d038cd46a1bbd7c89124eaf5ec67fb1f221
MD5 3af497aec79f5e2996e70e61ec6d5d5b
BLAKE2b-256 0521e76ea7ffb01181e01bc52664e245f3ba10500e53069133f59452cc26998d

See more details on using hashes here.

File details

Details for the file fastqlapi-0.3.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for fastqlapi-0.3.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b366b9a0ec7811f5d6bdadc5836bf1b5d213250494adb3204c0199962acd2694
MD5 bf95d6adad7c9559f86678943a10301e
BLAKE2b-256 8ed30756623b8faec167fbec05066495a359d87913c33da4427dfe8c95b2b622

See more details on using hashes here.

File details

Details for the file fastqlapi-0.3.5-cp311-cp311-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for fastqlapi-0.3.5-cp311-cp311-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 6e7b04e859fcba7c659bb1515b14c870171442e7ea21f89adef311df513d9c5f
MD5 3322a7432f20a37b7b62cb1af7de6f4c
BLAKE2b-256 00a9abb125ed16f88b944a9c67f8773c09e1168995af738dba7d8b14f4e96c22

See more details on using hashes here.

File details

Details for the file fastqlapi-0.3.5-cp310-none-win_amd64.whl.

File metadata

File hashes

Hashes for fastqlapi-0.3.5-cp310-none-win_amd64.whl
Algorithm Hash digest
SHA256 cffc020d8419a91b4403ce8ece3668c09993a342b86a78f4e5f12c47d3a25308
MD5 447d9d842dfdbbd19343341be6d3e009
BLAKE2b-256 d5023e194ac8c07d7e5475ae6e066982fffce1d858ccd48b3f22e1879ee5e598

See more details on using hashes here.

File details

Details for the file fastqlapi-0.3.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for fastqlapi-0.3.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 df3cc453b3140981c14cffeba979d87d3433b55bb526f93cac8ad7c9d5086452
MD5 99205f2ed2663499fb0323b9da229370
BLAKE2b-256 4162c9220e60ccd20b638c0b5b1507e0b0f20ccafd164e76043b7c2e24171eb3

See more details on using hashes here.

File details

Details for the file fastqlapi-0.3.5-cp310-cp310-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for fastqlapi-0.3.5-cp310-cp310-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 d64a4dd3284fd7e9575a0b4d3ab1b6ccc31475c6e48d0c1315449cc5e807ac37
MD5 963a4652172d0a772b8354fe9b012b99
BLAKE2b-256 2aa1018c8c9215cc11d573769bdfce050966246bf0ee09f29e079c6fd1749b23

See more details on using hashes here.

File details

Details for the file fastqlapi-0.3.5-cp39-none-win_amd64.whl.

File metadata

  • Download URL: fastqlapi-0.3.5-cp39-none-win_amd64.whl
  • Upload date:
  • Size: 3.2 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/0.14.7

File hashes

Hashes for fastqlapi-0.3.5-cp39-none-win_amd64.whl
Algorithm Hash digest
SHA256 ddce5722cac86deb103092abba21e54a204112dc8d5d04b51e2aaf47b34aeb91
MD5 846d0ffc9e9d96064e8b967346c83e47
BLAKE2b-256 292948a05a4d55498d07208cf3aa6fb7f010d0d4cc439c9eb58041b60c569863

See more details on using hashes here.

File details

Details for the file fastqlapi-0.3.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for fastqlapi-0.3.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 802300100d77abbcca84a005cf45a632110eb232f9a62a7c0337ae31d169a1af
MD5 4b59b4e8bc07bf578d6fff3c0120a906
BLAKE2b-256 0b5b66ad8d98d81505cbe9aba7c54ebca917a61e2c2df0d7874dd3ba99b0346c

See more details on using hashes here.

File details

Details for the file fastqlapi-0.3.5-cp39-cp39-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for fastqlapi-0.3.5-cp39-cp39-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 1d98cf2a9aad0110a78a8d21702eedb18cfdf3a2cd138d3b1a3c855e0ff2e06e
MD5 c1e7428569b5654eb39f617705e5db23
BLAKE2b-256 668364a3c98076bb3eb26e634e83f59b36d8e20124df35fa981cf28949deae55

See more details on using hashes here.

File details

Details for the file fastqlapi-0.3.5-cp38-none-win_amd64.whl.

File metadata

  • Download URL: fastqlapi-0.3.5-cp38-none-win_amd64.whl
  • Upload date:
  • Size: 3.2 MB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/0.14.7

File hashes

Hashes for fastqlapi-0.3.5-cp38-none-win_amd64.whl
Algorithm Hash digest
SHA256 6f7967e334c39c7ba12580298c9c6fda7a98448827cb54cce50af080bb7f03e5
MD5 355c176e2e1208bdec4a8ad53a70c0e2
BLAKE2b-256 4c2a2e8ac6f97745c6cad70975b339bb5979c79e5bf4c585bec0915652dd37c1

See more details on using hashes here.

File details

Details for the file fastqlapi-0.3.5-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for fastqlapi-0.3.5-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d7f33aa75e8eae2ec18cbffe0643574ed93aac2ba46e736b6689805e4385bb08
MD5 72d65c4cbec687de7726cdaf1cf9e678
BLAKE2b-256 bda1925b4d72ef9f1be71135f7bfa649ca6bcccb27c819c91c8fac17961a046a

See more details on using hashes here.

File details

Details for the file fastqlapi-0.3.5-cp38-cp38-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for fastqlapi-0.3.5-cp38-cp38-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 23766faf5c455155eedb59d8a1f144a476d5325c84dc804fe51228fce179c326
MD5 ca764a8d4a833bd6731a1f9f3abeb0d1
BLAKE2b-256 78a876792865af32a5e9663a8f548f535ae45e98324a95224e983aff39823fd0

See more details on using hashes here.

File details

Details for the file fastqlapi-0.3.5-cp37-none-win_amd64.whl.

File metadata

  • Download URL: fastqlapi-0.3.5-cp37-none-win_amd64.whl
  • Upload date:
  • Size: 3.2 MB
  • Tags: CPython 3.7, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/0.14.7

File hashes

Hashes for fastqlapi-0.3.5-cp37-none-win_amd64.whl
Algorithm Hash digest
SHA256 698c8cc63f8957837bbdb0390eabba86a56bb24d87532d023995ac9de5890f0f
MD5 8b773363922061f8cc7af27974647c46
BLAKE2b-256 fbd7ae898b432b9b17bafed3bcff5226e9b9622d9abf13f224bf94eccf340ee1

See more details on using hashes here.

File details

Details for the file fastqlapi-0.3.5-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for fastqlapi-0.3.5-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 924a030da18fa0a46d6e90f60dd864945b2adb37faebd1ce1498d8dce7239d15
MD5 ededc391bf3b02f665fb388d01046f34
BLAKE2b-256 590ebdcde45367993cf3c490ca4845abbd6d3eb038677a0ffadf72cb613d6bdd

See more details on using hashes here.

File details

Details for the file fastqlapi-0.3.5-cp37-cp37m-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for fastqlapi-0.3.5-cp37-cp37m-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 0b9dd01c9e2b13e2562a29e781edc4fb3091fd6655be2e5a5be4b98a52a55502
MD5 c6deeda86515fcad18532a49bed59e2a
BLAKE2b-256 20d9df8b5922b388df1755bbed43f2182f5b31fb69eca97c2f042ce17a4ba956

See more details on using hashes here.

Supported by

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