From 36306e5b129e4415a06d29084389f6482483b060 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sat, 21 Sep 2024 16:45:48 -0700 Subject: [PATCH] feat(models): load models from JSON configuration - load models from JSON configuration - resolve security issue - update dependencies - optimize imports in graph.py and monitor.py --- models.json.example | 4 ++++ requirements.txt | 6 ++++-- setup.py | 16 ++++++++-------- src/graph.py | 34 ++++++++++++---------------------- src/monitor.py | 16 +++++----------- 5 files changed, 33 insertions(+), 43 deletions(-) create mode 100644 models.json.example diff --git a/models.json.example b/models.json.example new file mode 100644 index 0000000..296404a --- /dev/null +++ b/models.json.example @@ -0,0 +1,4 @@ +{ + "Example-Model-22B-FP8-dynamic": "http://112.83.15.44:8883", + "Mistral-7B-bf16": "http://57.214.142.199:8090" +} \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index a055162..859761d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,9 @@ -numpy~=2.1.1 +numpy~=1.26.4 uvicorn~=0.30.6 requests~=2.32.3 pandas~=2.2.3 plotly~=5.24.1 flask~=3.0.3 -zstd~=1.5.5.1 \ No newline at end of file +scipy~=1.13.1 +asgiref~=3.8.1 +setuptools~=74.1.3 diff --git a/setup.py b/setup.py index c285bf4..909803c 100644 --- a/setup.py +++ b/setup.py @@ -1,12 +1,12 @@ from setuptools import setup setup( - name='vAnalytics', - version='v1.0.0', - packages=[''], - url='https://github.com/leafspark/vAnalytics', - license='apache-2.0', - author='leafspark', - author_email='', - description='time series analytics for vLLM' + name="vAnalytics", + version="v1.0.0", + packages=[""], + url="https://github.com/leafspark/vAnalytics", + license="apache-2.0", + author="leafspark", + author_email="", + description="time series analytics for vLLM", ) diff --git a/src/graph.py b/src/graph.py index f115e5b..679dce6 100644 --- a/src/graph.py +++ b/src/graph.py @@ -1,22 +1,18 @@ import asyncio import json import logging -import numpy as np import os -import pandas as pd -import plotly.graph_objects as go -import plotly.offline as pyo import sqlite3 import subprocess import threading import time from concurrent.futures import ThreadPoolExecutor, as_completed from datetime import datetime, timedelta + +import plotly.graph_objects as go +import plotly.offline as pyo from flask import Flask, render_template, request, send_file -from functools import lru_cache from plotly.subplots import make_subplots -from plotly.subplots import make_subplots -from scipy.interpolate import make_interp_spline # Set up logging with a higher level logging.basicConfig( @@ -259,7 +255,7 @@ def index(): plot_div = None error_message = None - if selected_model: + if selected_model in valid_model_names: try: fig = create_plots(selected_model) if fig is not None: @@ -273,22 +269,16 @@ def index(): "An error occurred while creating the plot. Please try again later." ) - if selected_model in valid_model_names: - command = [ - "python", - "get_data.py", - "--hours", - "24", - f".\\data\\{selected_model}.sqlite", - ] - result = subprocess.run(command, capture_output=True, text=True) - else: - logging.error(f"Invalid model selected: {selected_model}") - error_message = "Invalid model selected. Please choose a valid model." - result = None - + command = [ + "python", + "get_data.py", + "--hours", + "24", + f".\\data\\{selected_model}.sqlite", + ] result = subprocess.run(command, capture_output=True, text=True) else: + logging.error(f"Invalid model selected: {selected_model}") result = None return render_template( diff --git a/src/monitor.py b/src/monitor.py index 196b3f7..d366809 100644 --- a/src/monitor.py +++ b/src/monitor.py @@ -4,11 +4,8 @@ import os import json from datetime import datetime import logging -import zstd import sqlite3 -print("Starting monitor.") - # Set up basic configuration for logging logging.basicConfig( level=logging.DEBUG, @@ -16,15 +13,12 @@ logging.basicConfig( filename="monitor.log", # Log to a file named monitor.log filemode="a", ) # Append to the log file -logging.basicConfig( - level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s" -) -# Model information -models = { - "Example-Model-22B-FP8-dynamic": "http://112.83.15.44:8883", - "Mistral-7B-bf16": "http://57.214.142.199:8090", -} +print("Starting monitor.") + +# Load model info +with open("models.json", "r") as file: + models = json.load(file) def call_metrics_endpoint(model_name, base_url):