-
Notifications
You must be signed in to change notification settings - Fork 608
Improve python client cross python version compatibility #1640
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7f657c8
Improve python client cross python version compatibility
vishalbollu 7aee866
Update deploy_test.py
vishalbollu ad53d69
Update bootloader.sh
vishalbollu 13fc755
Respond to PR comments
vishalbollu 2add6df
Update client.py
vishalbollu f5e8817
Merge branch 'master' into python-client-cross-compatibility
deliahu 5c8184a
Merge branch 'master' into python-client-cross-compatibility
vishalbollu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Copyright 2020 Cortex Labs, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# USAGE: python ./dev/deploy_test.py <env_name> | ||
# e.g.: python ./dev/deploy_test.py aws | ||
|
||
import os | ||
import cortex | ||
import sys | ||
import requests | ||
|
||
cx = cortex.client(sys.argv[1]) | ||
api_config = { | ||
"name": "text-generator", | ||
"kind": "RealtimeAPI", | ||
} | ||
|
||
|
||
class PythonPredictor: | ||
def __init__(self, config): | ||
from transformers import pipeline | ||
|
||
self.model = pipeline(task="text-generation") | ||
|
||
def predict(self, payload): | ||
return self.model(payload["text"])[0] | ||
|
||
|
||
api = cx.deploy( | ||
api_config, | ||
predictor=PythonPredictor, | ||
requirements=["torch", "transformers"], | ||
wait=True, | ||
) | ||
|
||
response = requests.post( | ||
api["endpoint"], | ||
json={"text": "machine learning is great because"}, | ||
) | ||
|
||
print(response.status_code) | ||
print(response.text) | ||
|
||
cx.delete_api(api_config["name"]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#!/bin/bash | ||
|
||
# Copyright 2020 Cortex Labs, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
|
||
# USAGE: ./dev/python_version_test.sh <python version> <env_name> | ||
# e.g.: ./dev/python_version_test.sh 3.6.9 aws | ||
|
||
set -e | ||
|
||
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")"/.. >/dev/null && pwd)" | ||
|
||
# create a new conda environment based on the supplied python version | ||
conda create -n env -y | ||
CONDA_BASE=$(conda info --base) | ||
source $CONDA_BASE/etc/profile.d/conda.sh | ||
conda activate env | ||
conda config --append channels conda-forge | ||
conda install python=$1 -y | ||
|
||
pip install requests | ||
|
||
export CORTEX_CLI_PATH=$ROOT/bin/cortex | ||
|
||
# install cortex | ||
cd $ROOT/pkg/workloads/cortex/client | ||
pip install -e . | ||
|
||
# run script.py | ||
python $ROOT/dev/deploy_test.py $2 | ||
|
||
# clean up conda | ||
conda deactivate | ||
conda env remove -n env | ||
rm -rf $ROOT/pkg/workloads/cortex/client/cortex.egg-info | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.