Skip to content

Commit 121c2b7

Browse files
authored
Add lambda to fetch data from api and add conifguration data model (#7092)
Stack from [ghstack](https://github.com/ezyang/ghstack) (oldest at bottom): * #7112 * #7096 * #7095 * #7094 * __->__ #7092 setup base for notification pipeline. add config to provide guidance for each pipepline how to process data and generate benchmark regression report
1 parent 43f94a7 commit 121c2b7

File tree

4 files changed

+868
-0
lines changed

4 files changed

+868
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
from dataclasses import dataclass, field
2+
from typing import Any, Dict, List
3+
4+
import requests
5+
6+
7+
# The data class to provide api response model from get_time_series api
8+
9+
10+
@dataclass
11+
class TimeRange:
12+
start: str
13+
end: str
14+
15+
16+
@dataclass
17+
class BenchmarkTimeSeriesItem:
18+
group_info: Dict[str, Any]
19+
num_of_dp: int
20+
data: List[Dict[str, Any]] = field(default_factory=list)
21+
22+
23+
@dataclass
24+
class BenchmarkTimeSeriesApiData:
25+
time_series: List[BenchmarkTimeSeriesItem]
26+
time_range: TimeRange
27+
28+
29+
@dataclass
30+
class BenchmarkTimeSeriesApiResponse:
31+
data: BenchmarkTimeSeriesApiData
32+
33+
@classmethod
34+
def from_request(
35+
cls, url: str, query: dict, timeout: int = 180
36+
) -> "BenchmarkTimeSeriesApiResponse":
37+
"""
38+
Send a POST request and parse into BenchmarkTimeSeriesApiResponse.
39+
40+
Args:
41+
url: API endpoint
42+
query: JSON payload must
43+
timeout: max seconds to wait for connect + response (default: 30)
44+
Returns:
45+
ApiResponse
46+
Raises:
47+
requests.exceptions.RequestException if network/timeout/HTTP error
48+
RuntimeError if the API returns an "error" field or malformed data
49+
"""
50+
resp = requests.post(url, json=query, timeout=timeout)
51+
resp.raise_for_status()
52+
payload = resp.json()
53+
54+
if "error" in payload:
55+
raise RuntimeError(f"API error: {payload['error']}")
56+
try:
57+
tr = TimeRange(**payload["data"]["time_range"])
58+
ts = [
59+
BenchmarkTimeSeriesItem(**item)
60+
for item in payload["data"]["time_series"]
61+
]
62+
except Exception as e:
63+
raise RuntimeError(f"Malformed API payload: {e}")
64+
return cls(data=BenchmarkTimeSeriesApiData(time_series=ts, time_range=tr))
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
from common.config_model import (
2+
BenchmarkApiSource,
3+
BenchmarkConfig,
4+
BenchmarkRegressionConfigBook,
5+
DayRangeWindow,
6+
Frequency,
7+
Policy,
8+
RangeConfig,
9+
RegressionPolicy,
10+
)
11+
12+
13+
# Compiler benchmark regression config
14+
# todo(elainewy): eventually each team should configure
15+
# their own benchmark regression config, currenlty place
16+
# here for lambda
17+
18+
19+
COMPILER_BENCHMARK_CONFIG = BenchmarkConfig(
20+
name="Compiler Benchmark Regression",
21+
id="compiler_regression",
22+
source=BenchmarkApiSource(
23+
api_query_url="https://hud.pytorch.org/api/benchmark/get_time_series",
24+
type="benchmark_time_series_api",
25+
# currently we only detect the regression for h100 with dtype bfloat16, and mode inference
26+
# we can extend this to other devices, dtypes and mode in the future
27+
api_endpoint_params_template="""
28+
{
29+
"name": "compiler_precompute",
30+
"query_params": {
31+
"commits": [],
32+
"compilers": [],
33+
"arch": "h100",
34+
"device": "cuda",
35+
"dtype": "bfloat16",
36+
"granularity": "hour",
37+
"mode": "inference",
38+
"startTime": "{{ startTime }}",
39+
"stopTime": "{{ stopTime }}",
40+
"suites": ["torchbench", "huggingface", "timm_models"],
41+
"workflowId": 0,
42+
"branches": ["main"]
43+
}
44+
}
45+
""",
46+
),
47+
# set baseline from past 7 days using avg, and compare with the last 1 day
48+
policy=Policy(
49+
frequency=Frequency(value=1, unit="days"),
50+
range=RangeConfig(
51+
baseline=DayRangeWindow(value=7),
52+
comparison=DayRangeWindow(value=2),
53+
),
54+
metrics={
55+
"passrate": RegressionPolicy(
56+
name="passrate",
57+
condition="greater_equal",
58+
threshold=0.9,
59+
baseline_aggregation="max",
60+
),
61+
"geomean": RegressionPolicy(
62+
name="geomean",
63+
condition="greater_equal",
64+
threshold=0.95,
65+
baseline_aggregation="max",
66+
),
67+
"compression_ratio": RegressionPolicy(
68+
name="compression_ratio",
69+
condition="greater_equal",
70+
threshold=0.9,
71+
baseline_aggregation="max",
72+
),
73+
},
74+
notification_config={
75+
"type": "github",
76+
"repo": "pytorch/test-infra",
77+
"issue": "7081",
78+
},
79+
),
80+
)
81+
82+
BENCHMARK_REGRESSION_CONFIG = BenchmarkRegressionConfigBook(
83+
configs={
84+
"compiler_regression": COMPILER_BENCHMARK_CONFIG,
85+
}
86+
)
87+
88+
89+
def get_benchmark_regression_config(config_id: str) -> BenchmarkConfig:
90+
"""Get benchmark regression config by config id"""
91+
try:
92+
return BENCHMARK_REGRESSION_CONFIG[config_id]
93+
except KeyError:
94+
raise ValueError(f"Invalid config id: {config_id}")

0 commit comments

Comments
 (0)