-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update: add class Config and move env into it
- Loading branch information
Showing
6 changed files
with
87 additions
and
88 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,16 +1,71 @@ | ||
import os | ||
|
||
REDIS_PREFIX = os.environ.get("REDIS_PREFIX", "llm-api") | ||
REDIS_HOST = os.environ.get("REDIS_HOST", "localhost") | ||
REDIS_PORT = os.environ.get("REDIS_PORT", "6379") | ||
|
||
RABBIT_MQ_HOST = os.environ.get("RABBIT_MQ_HOST", "localhost") | ||
RABBIT_MQ_PORT = os.environ.get("RABBIT_MQ_PORT", "5672") | ||
RABBIT_MQ_LOGIN = os.environ.get("RABBIT_MQ_LOGIN", "admin") | ||
RABBIT_MQ_PASSWORD = os.environ.get("RABBIT_MQ_PASSWORD", "admin") | ||
class Config: | ||
def __init__( | ||
self, | ||
redis_host: str = "localhost", | ||
redis_port: int = 6379, | ||
redis_prefix: str = "llm-api", | ||
rabbit_host: str = "localhost", | ||
rabbit_port: int = 5672, | ||
rabbit_login: str = "admin", | ||
rabbit_password: str = "admin", | ||
queue_name: str = "llm-api-queue", | ||
model_path: str = None, | ||
token_len: int = None, | ||
tensor_parallel_size: int = None, | ||
gpu_memory_utilisation: float = None, | ||
): | ||
self.redis_host = redis_host | ||
self.redis_port = redis_port | ||
self.redis_prefix = redis_prefix | ||
self.rabbit_host = rabbit_host | ||
self.rabbit_port = rabbit_port | ||
self.rabbit_login = rabbit_login | ||
self.rabbit_password = rabbit_password | ||
self.queue_name = queue_name | ||
self.model_path = model_path, | ||
self.token_len = token_len, | ||
self.tensor_parallel_size = tensor_parallel_size, | ||
self.gpu_memory_utilisation = gpu_memory_utilisation, | ||
|
||
QUEUE_NAME = os.environ.get("QUEUE_NAME", "llm-api-queue") | ||
MODEL_PATH = os.environ.get("MODEL_PATH") | ||
TOKENS_LEN = int(os.environ.get("TOKENS_LEN")) | ||
TENSOR_PARALLEL_SIZE = int(os.environ.get("TENSOR_PARALLEL_SIZE")) | ||
GPU_MEMORY_UTILISATION = float(os.environ.get("GPU_MEMORY_UTILISATION")) | ||
@classmethod | ||
def read_from_env(cls) -> 'Config': | ||
return Config( | ||
os.environ.get("REDIS_HOST", "localhost"), | ||
os.environ.get("REDIS_PORT", "6379"), | ||
os.environ.get("REDIS_PREFIX", "llm-api"), | ||
os.environ.get("RABBIT_MQ_HOST", "localhost"), | ||
os.environ.get("RABBIT_MQ_PORT", "5672"), | ||
os.environ.get("RABBIT_MQ_LOGIN", "admin"), | ||
os.environ.get("RABBIT_MQ_PASSWORD", "admin"), | ||
os.environ.get("QUEUE_NAME", "llm-api-queue"), | ||
os.environ.get("MODEL_PATH"), | ||
int(os.environ.get("TOKENS_LEN")), | ||
int(os.environ.get("TENSOR_PARALLEL_SIZE")), | ||
float(os.environ.get("GPU_MEMORY_UTILISATION")), | ||
) | ||
|
||
@classmethod | ||
def read_from_env_file(cls, path: str) -> 'Config': | ||
with open(path) as file: | ||
lines = file.readlines() | ||
env_vars = {} | ||
for line in lines: | ||
key, value = line.split("=") | ||
env_vars[key] = value | ||
return Config( | ||
env_vars.get("REDIS_HOST", "localhost"), | ||
int(env_vars.get("REDIS_PORT", "6379")), | ||
env_vars.get("REDIS_PREFIX", "llm-api"), | ||
env_vars.get("RABBIT_MQ_HOST", "localhost"), | ||
int(env_vars.get("RABBIT_MQ_PORT", "5672")), | ||
env_vars.get("RABBIT_MQ_LOGIN", "admin"), | ||
env_vars.get("RABBIT_MQ_PASSWORD", "admin"), | ||
env_vars.get("QUEUE_NAME", "llm-api-queue"), | ||
env_vars.get("MODEL_PATH"), | ||
int(env_vars.get("TOKENS_LEN")), | ||
int(env_vars.get("TENSOR_PARALLEL_SIZE")), | ||
float(env_vars.get("GPU_MEMORY_UTILISATION")), | ||
) |
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,21 +1,11 @@ | ||
from protollm_worker.config import MODEL_PATH, REDIS_HOST, REDIS_PORT, QUEUE_NAME | ||
from protollm_worker.models.vllm_models import VllMModel | ||
from protollm_worker.services.broker import LLMWrap | ||
from protollm_worker.config import ( | ||
RABBIT_MQ_HOST, RABBIT_MQ_PORT, | ||
RABBIT_MQ_PASSWORD, RABBIT_MQ_LOGIN, | ||
REDIS_PREFIX | ||
) | ||
from protollm_worker.config import Config | ||
|
||
if __name__ == "__main__": | ||
config = Config.read_from_env() | ||
llm_model = VllMModel(model_path=MODEL_PATH) | ||
llm_wrap = LLMWrap(llm_model=llm_model, | ||
redis_host= REDIS_HOST, | ||
redis_port= REDIS_PORT, | ||
queue_name= QUEUE_NAME, | ||
rabbit_host= RABBIT_MQ_HOST, | ||
rabbit_port= RABBIT_MQ_PORT, | ||
rabbit_login= RABBIT_MQ_LOGIN, | ||
rabbit_password= RABBIT_MQ_PASSWORD, | ||
redis_prefix= REDIS_PREFIX) | ||
config= config) | ||
llm_wrap.start_connection() |
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