-
Notifications
You must be signed in to change notification settings - Fork 26
/
hardware.py
63 lines (51 loc) · 1.41 KB
/
hardware.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import os
from typing import Dict
from app.utils.hardware import (
GPUComputeInfo,
GPUUtilizationInfo
)
from fastapi import APIRouter, Request
from pydantic import BaseModel
router = APIRouter()
class HardwareInformation(BaseModel):
"""Response model for GPU information."""
pipeline: str
model_id: str
gpu_info: Dict[int, GPUComputeInfo]
class HardwareStats(BaseModel):
"""Response model for real-time GPU statistics."""
pipeline: str
model_id: str
gpu_stats: Dict[int, GPUUtilizationInfo]
@router.get(
"/hardware/info",
operation_id="hardware_info",
response_model=HardwareInformation,
)
@router.get(
"/hardware/info/",
response_model=HardwareInformation,
include_in_schema=False,
)
async def hardware_info(request: Request):
return HardwareInformation(
pipeline=os.environ["PIPELINE"],
model_id=os.environ["MODEL_ID"],
gpu_info=request.app.hardware_info_service.get_gpu_compute_info(),
)
@router.get(
"/hardware/stats",
operation_id="hardware_stats",
response_model=HardwareStats,
)
@router.get(
"/hardware/stats/",
response_model=HardwareStats,
include_in_schema=False,
)
async def hardware_stats(request: Request):
return HardwareStats(
pipeline=os.environ["PIPELINE"],
model_id=os.environ["MODEL_ID"],
gpu_stats=request.app.hardware_info_service.get_gpu_utilization_stats(),
)