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
This commit is contained in:
BuildTools 2024-09-21 16:45:48 -07:00
parent ba2a610ac5
commit 36306e5b12
No known key found for this signature in database
GPG Key ID: 3270C066C15D530B
5 changed files with 33 additions and 43 deletions

4
models.json.example Normal file
View File

@ -0,0 +1,4 @@
{
"Example-Model-22B-FP8-dynamic": "http://112.83.15.44:8883",
"Mistral-7B-bf16": "http://57.214.142.199:8090"
}

View File

@ -1,7 +1,9 @@
numpy~=2.1.1 numpy~=1.26.4
uvicorn~=0.30.6 uvicorn~=0.30.6
requests~=2.32.3 requests~=2.32.3
pandas~=2.2.3 pandas~=2.2.3
plotly~=5.24.1 plotly~=5.24.1
flask~=3.0.3 flask~=3.0.3
zstd~=1.5.5.1 scipy~=1.13.1
asgiref~=3.8.1
setuptools~=74.1.3

View File

@ -1,12 +1,12 @@
from setuptools import setup from setuptools import setup
setup( setup(
name='vAnalytics', name="vAnalytics",
version='v1.0.0', version="v1.0.0",
packages=[''], packages=[""],
url='https://github.com/leafspark/vAnalytics', url="https://github.com/leafspark/vAnalytics",
license='apache-2.0', license="apache-2.0",
author='leafspark', author="leafspark",
author_email='', author_email="",
description='time series analytics for vLLM' description="time series analytics for vLLM",
) )

View File

@ -1,22 +1,18 @@
import asyncio import asyncio
import json import json
import logging import logging
import numpy as np
import os import os
import pandas as pd
import plotly.graph_objects as go
import plotly.offline as pyo
import sqlite3 import sqlite3
import subprocess import subprocess
import threading import threading
import time import time
from concurrent.futures import ThreadPoolExecutor, as_completed from concurrent.futures import ThreadPoolExecutor, as_completed
from datetime import datetime, timedelta 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 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 plotly.subplots import make_subplots
from scipy.interpolate import make_interp_spline
# Set up logging with a higher level # Set up logging with a higher level
logging.basicConfig( logging.basicConfig(
@ -259,7 +255,7 @@ def index():
plot_div = None plot_div = None
error_message = None error_message = None
if selected_model: if selected_model in valid_model_names:
try: try:
fig = create_plots(selected_model) fig = create_plots(selected_model)
if fig is not None: if fig is not None:
@ -273,22 +269,16 @@ def index():
"An error occurred while creating the plot. Please try again later." "An error occurred while creating the plot. Please try again later."
) )
if selected_model in valid_model_names: command = [
command = [ "python",
"python", "get_data.py",
"get_data.py", "--hours",
"--hours", "24",
"24", f".\\data\\{selected_model}.sqlite",
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
result = subprocess.run(command, capture_output=True, text=True) result = subprocess.run(command, capture_output=True, text=True)
else: else:
logging.error(f"Invalid model selected: {selected_model}")
result = None result = None
return render_template( return render_template(

View File

@ -4,11 +4,8 @@ import os
import json import json
from datetime import datetime from datetime import datetime
import logging import logging
import zstd
import sqlite3 import sqlite3
print("Starting monitor.")
# Set up basic configuration for logging # Set up basic configuration for logging
logging.basicConfig( logging.basicConfig(
level=logging.DEBUG, level=logging.DEBUG,
@ -16,15 +13,12 @@ logging.basicConfig(
filename="monitor.log", # Log to a file named monitor.log filename="monitor.log", # Log to a file named monitor.log
filemode="a", filemode="a",
) # Append to the log file ) # Append to the log file
logging.basicConfig(
level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s"
)
# Model information print("Starting monitor.")
models = {
"Example-Model-22B-FP8-dynamic": "http://112.83.15.44:8883", # Load model info
"Mistral-7B-bf16": "http://57.214.142.199:8090", with open("models.json", "r") as file:
} models = json.load(file)
def call_metrics_endpoint(model_name, base_url): def call_metrics_endpoint(model_name, base_url):