forked from mudler/LocalAI
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into rf-config-directory
- Loading branch information
Showing
24 changed files
with
192 additions
and
269 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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,10 @@ | ||
CONDA_ENV_PATH = "transformers.yml" | ||
|
||
ifeq ($(BUILD_TYPE), cublas) | ||
CONDA_ENV_PATH = "transformers-nvidia.yml" | ||
endif | ||
|
||
.PHONY: transformers | ||
transformers: | ||
@echo "Installing $(CONDA_ENV_PATH)..." | ||
bash install.sh $(CONDA_ENV_PATH) |
This file contains 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,15 @@ | ||
#!/bin/bash | ||
set -ex | ||
|
||
# Check if environment exist | ||
conda_env_exists(){ | ||
! conda list --name "${@}" >/dev/null 2>/dev/null | ||
} | ||
|
||
if conda_env_exists "transformers" ; then | ||
echo "Creating virtual environment..." | ||
conda env create --name transformers --file $1 | ||
echo "Virtual environment created." | ||
else | ||
echo "Virtual environment already exists." | ||
fi |
This file contains 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 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 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 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 |
---|---|---|
@@ -1,11 +1,15 @@ | ||
.PHONY: petals | ||
petals: | ||
@echo "Creating virtual environment..." | ||
@conda env create --name petals --file petals.yml | ||
@echo "Virtual environment created." | ||
$(MAKE) -C ../common-env/transformers | ||
|
||
.PHONY: run | ||
run: | ||
@echo "Running petals..." | ||
bash run.sh | ||
@echo "petals run." | ||
|
||
.PHONY: test | ||
test: | ||
@echo "Testing petals..." | ||
bash test.sh | ||
@echo "petals tested." |
This file contains 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 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,11 @@ | ||
#!/bin/bash | ||
## | ||
## A bash script wrapper that runs the transformers server with conda | ||
|
||
# Activate conda environment | ||
source activate transformers | ||
|
||
# get the directory where the bash script is located | ||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" | ||
|
||
python -m unittest $DIR/test_petals.py |
This file contains 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,58 @@ | ||
import unittest | ||
import subprocess | ||
import time | ||
import backend_pb2 | ||
import backend_pb2_grpc | ||
|
||
import grpc | ||
|
||
import unittest | ||
import subprocess | ||
import time | ||
import grpc | ||
import backend_pb2_grpc | ||
import backend_pb2 | ||
|
||
class TestBackendServicer(unittest.TestCase): | ||
""" | ||
TestBackendServicer is the class that tests the gRPC service. | ||
This class contains methods to test the startup and shutdown of the gRPC service. | ||
""" | ||
def setUp(self): | ||
self.service = subprocess.Popen(["python", "backend_petals.py", "--addr", "localhost:50051"]) | ||
time.sleep(10) | ||
|
||
def tearDown(self) -> None: | ||
self.service.terminate() | ||
self.service.wait() | ||
|
||
def test_server_startup(self): | ||
try: | ||
self.setUp() | ||
with grpc.insecure_channel("localhost:50051") as channel: | ||
stub = backend_pb2_grpc.BackendStub(channel) | ||
response = stub.Health(backend_pb2.HealthMessage()) | ||
self.assertEqual(response.message, b'OK') | ||
except Exception as err: | ||
print(err) | ||
self.fail("Server failed to start") | ||
finally: | ||
self.tearDown() | ||
def test_load_model(self): | ||
""" | ||
This method tests if the model is loaded successfully | ||
""" | ||
try: | ||
self.setUp() | ||
with grpc.insecure_channel("localhost:50051") as channel: | ||
stub = backend_pb2_grpc.BackendStub(channel) | ||
response = stub.LoadModel(backend_pb2.ModelOptions(Model="bigscience/bloom-560m")) | ||
print(response) | ||
self.assertTrue(response.success) | ||
self.assertEqual(response.message, "Model loaded successfully") | ||
except Exception as err: | ||
print(err) | ||
self.fail("LoadModel service failed") | ||
finally: | ||
self.tearDown() |
This file contains 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 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
Oops, something went wrong.