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_IPto 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!
- 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
UPLOAD_PATH Path to download files given as a value for URL types | default ./
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fastqlapi-0.3.4-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: fastqlapi-0.3.4-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 5.1 MB
- Tags: PyPy, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.14.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
678f9f06e2e7c7b90ce5d61389b01b33649c3490d97a1e92a6e2e65b66cf6e3e
|
|
| MD5 |
c275ac14d984f5bad92089d7d7c995b3
|
|
| BLAKE2b-256 |
3712c1e19eae23f10fc9bb0afe468a606720fa89532c12af418ac1e3ee421581
|
File details
Details for the file fastqlapi-0.3.4-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: fastqlapi-0.3.4-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 5.1 MB
- Tags: PyPy, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.14.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7f14e56480eaa7dfdb353b810090d4481cd60ce2749778e9d92d93a0f8fc6a78
|
|
| MD5 |
c64fb16b3e393181cb6314fa6b1b0a8a
|
|
| BLAKE2b-256 |
37d6f3ea85c3f4f777eacbbae1d56a9c652dca1d749d4575aa21d71cea8e69a3
|
File details
Details for the file fastqlapi-0.3.4-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: fastqlapi-0.3.4-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 5.1 MB
- Tags: PyPy, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.14.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
76eaa286b261e6281d33def79db74bbd5eddc6c3378f1876b5572b42f9d7b319
|
|
| MD5 |
8e62b3d6176c55534e1265b50e7b18da
|
|
| BLAKE2b-256 |
222aa727c8a45fbec33a52869a27c567e83f5f1f85a4fa30c173da83d8ff8523
|
File details
Details for the file fastqlapi-0.3.4-cp311-none-win_amd64.whl.
File metadata
- Download URL: fastqlapi-0.3.4-cp311-none-win_amd64.whl
- Upload date:
- Size: 3.2 MB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.14.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2d82a4ed91a1843c0fa57b211c521d2ea6c79051b72556b89cb95f007cf988a6
|
|
| MD5 |
45d1e58a4ea2a24bbc4d71e531a13e13
|
|
| BLAKE2b-256 |
59fccfbfd29d99d77b85e43714c1ea57dcd16fbaccd2a520af8b6f1c7b3cc39b
|
File details
Details for the file fastqlapi-0.3.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: fastqlapi-0.3.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 5.1 MB
- Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.14.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7afebcfed786ebb3aae3682bf65bcd7c085626394dc3ed7303ce82e962d14cf6
|
|
| MD5 |
9a38a0dfc93ebb3f6412d6aa7b310efe
|
|
| BLAKE2b-256 |
f784067dd6529c3e4f3587e0f08f35f40375f66ea234d8ae8e4b2ea1cd926f63
|
File details
Details for the file fastqlapi-0.3.4-cp311-cp311-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl.
File metadata
- Download URL: fastqlapi-0.3.4-cp311-cp311-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
- Upload date:
- Size: 7.0 MB
- Tags: CPython 3.11, macOS 10.9+ universal2 (ARM64, x86-64), macOS 10.9+ x86-64, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.14.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fca5decf797abae89225d7007b6ee7cc2976058ff6b104160c94ac938c2cd1bd
|
|
| MD5 |
b00a090ee4ae57a6c8b2fa6e85db7902
|
|
| BLAKE2b-256 |
cda819533683c91d5fb4f81ae885150599c18a85c4a30ad33958eb54b550adde
|
File details
Details for the file fastqlapi-0.3.4-cp310-none-win_amd64.whl.
File metadata
- Download URL: fastqlapi-0.3.4-cp310-none-win_amd64.whl
- Upload date:
- Size: 3.2 MB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.14.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ef75c36170a4127fb496484a8520c796576fff17f3ba19f51988ac8ae53d0897
|
|
| MD5 |
17deceaa62e9bc37e77948ef3cf6c8f3
|
|
| BLAKE2b-256 |
8ff88a99edb7e660f4d07bc742aa1132ef0a4dbbc4f89bd6236cd18b297d70d9
|
File details
Details for the file fastqlapi-0.3.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: fastqlapi-0.3.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 5.1 MB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.14.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
56ccce32cc98a8cfd413d1046359373401ab2efd48eae1b5f842727d759fd662
|
|
| MD5 |
bff40e5aa02f3ab726d20b1d18733052
|
|
| BLAKE2b-256 |
7d7ffbd8880eeb5b8aabef5ced33f474477d93cffee9414846aca9b08ee477e9
|
File details
Details for the file fastqlapi-0.3.4-cp310-cp310-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl.
File metadata
- Download URL: fastqlapi-0.3.4-cp310-cp310-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
- Upload date:
- Size: 7.0 MB
- Tags: CPython 3.10, macOS 10.9+ universal2 (ARM64, x86-64), macOS 10.9+ x86-64, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.14.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b3f358ffea8958b98be5fcf1631255a7d94c641798a5f4d70655e0e6c5bbe691
|
|
| MD5 |
e28786c5768e74aa34cde39ba14e95b4
|
|
| BLAKE2b-256 |
0fad44be3441e861a0225f45cac609f062a143e13a4f3a3636ae72dd1acdb121
|
File details
Details for the file fastqlapi-0.3.4-cp39-none-win_amd64.whl.
File metadata
- Download URL: fastqlapi-0.3.4-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7a8156b387e95dc85ac6c46c43021b99411e39aa23ab3f6ba45e9953e233789f
|
|
| MD5 |
7b1412e5ada370e7204e21e5978371d9
|
|
| BLAKE2b-256 |
b17500b543589d1c62a4679c8f075f7236b7af63d9b460b02b6c3c37c8ea9d0c
|
File details
Details for the file fastqlapi-0.3.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: fastqlapi-0.3.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 5.1 MB
- Tags: CPython 3.9, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.14.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9c85f5898e56bf928ea8b24b4754d58b9b726b646dc0e233bb5fa4fd3fe6f144
|
|
| MD5 |
9b63299910d37d9d1582034bbbd6ff01
|
|
| BLAKE2b-256 |
06a57fd4bbc11f99fbb3fd63641a15889416960dfa3cb3ee918660838a744ef9
|
File details
Details for the file fastqlapi-0.3.4-cp39-cp39-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl.
File metadata
- Download URL: fastqlapi-0.3.4-cp39-cp39-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
- Upload date:
- Size: 7.0 MB
- Tags: CPython 3.9, macOS 10.9+ universal2 (ARM64, x86-64), macOS 10.9+ x86-64, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.14.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
928da8713850bb0f1cd466feceff2fca314f090971f293c4bf309eec0919ab0c
|
|
| MD5 |
2db3bc176d5ef859e5304eec83d39edd
|
|
| BLAKE2b-256 |
f5770e2072631bfb9626043f74bf09ba608d20e690131283284cbca2c7ab604d
|
File details
Details for the file fastqlapi-0.3.4-cp38-none-win_amd64.whl.
File metadata
- Download URL: fastqlapi-0.3.4-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
03c95bac43c0743b5964bb31a06e69fa3e01c82c9c4e27c0ea7306c5385f87eb
|
|
| MD5 |
fd374bdee9ec2a29378741426cfa7669
|
|
| BLAKE2b-256 |
70f6428977e107fef91db330130c55dba14441f49b561266e8ab3c44c184544c
|
File details
Details for the file fastqlapi-0.3.4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: fastqlapi-0.3.4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 5.1 MB
- Tags: CPython 3.8, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.14.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
83c88e3042ba021ec30bbf2eb2e37857243ac1b58258cb312c49aebcadb72320
|
|
| MD5 |
4474b0848a85e8347b9f86d4925b5144
|
|
| BLAKE2b-256 |
606c341977fd1a68b71350cfa493bc1f3f53dfb29a718433c5494420cd597040
|
File details
Details for the file fastqlapi-0.3.4-cp38-cp38-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl.
File metadata
- Download URL: fastqlapi-0.3.4-cp38-cp38-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
- Upload date:
- Size: 7.0 MB
- Tags: CPython 3.8, macOS 10.9+ universal2 (ARM64, x86-64), macOS 10.9+ x86-64, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.14.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
85795f90fa216b68699399655fdb49dfd3ec12e9bae68005e6db9e5c473ac4dd
|
|
| MD5 |
81f1186b46a599d89ba4d6fa6a63a619
|
|
| BLAKE2b-256 |
e046d0728555b63edae0f0710de57b3ce95588d4f0edcfbf1f1442eaa9fe04c5
|
File details
Details for the file fastqlapi-0.3.4-cp37-none-win_amd64.whl.
File metadata
- Download URL: fastqlapi-0.3.4-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f0f0102e43bd5ab03c139b087f8a01a4c353616d863e47592744da885e5a5624
|
|
| MD5 |
91a01fd355ecfe3f83f2791cd4076db4
|
|
| BLAKE2b-256 |
34c21d0421332885893f20b6c401cb17dae8f7ac3f6f829c06089f3431e266fa
|
File details
Details for the file fastqlapi-0.3.4-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: fastqlapi-0.3.4-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 5.1 MB
- Tags: CPython 3.7m, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.14.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
059a966f597c4d1666bf6b37a02c83547f591a33efeddabb716e23c9aa343f05
|
|
| MD5 |
a7b6207cc95aa08b624d832835e95e06
|
|
| BLAKE2b-256 |
a10636d754248efdf4aa5fa4346bed43fa2ef6b476e19be0f50b3335ea8fbd70
|
File details
Details for the file fastqlapi-0.3.4-cp37-cp37m-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl.
File metadata
- Download URL: fastqlapi-0.3.4-cp37-cp37m-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
- Upload date:
- Size: 7.0 MB
- Tags: CPython 3.7m, macOS 10.9+ universal2 (ARM64, x86-64), macOS 10.9+ x86-64, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.14.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4278aafc706177c9c7d9da65b5b0f3734b43736fa67c94b3838be100a05f5f94
|
|
| MD5 |
0f1a6682b70c146a6ff4eb9f6e7ec87d
|
|
| BLAKE2b-256 |
2c85f707c5063b9262016bfec383470d420054a3ed91cd83f8355873ec450c55
|