ror HF Staff commited on
Commit
be77c90
·
1 Parent(s): 2165257

Actual latest data refresh and clickable link

Browse files
Files changed (2) hide show
  1. app.py +3 -3
  2. data.py +55 -12
app.py CHANGED
@@ -60,10 +60,10 @@ def get_description_text():
60
  "NVIDIA runs on A10",
61
  ]
62
  msg = ["**" + x + "**" for x in msg] + [""]
63
- if Ci_results.last_update_time:
64
- msg.append(f"*Result overview by model and hardware (last updated: {Ci_results.last_update_time})*")
65
  else:
66
- msg.append("*Result overview by model and hardware (loading...)*")
67
  return "<br>".join(msg)
68
 
69
  # Load CSS from external file
 
60
  "NVIDIA runs on A10",
61
  ]
62
  msg = ["**" + x + "**" for x in msg] + [""]
63
+ if Ci_results.latest_update_msg:
64
+ msg.append(f"*Result overview by hardware for important models ({Ci_results.latest_update_msg})*")
65
  else:
66
+ msg.append("*Result overview by hardware for important models (loading...)*")
67
  return "<br>".join(msg)
68
 
69
  # Load CSS from external file
data.py CHANGED
@@ -5,6 +5,7 @@ from datetime import datetime
5
  import threading
6
  import traceback
7
  import json
 
8
 
9
  # NOTE: if caching is an issue, try adding `use_listings_cache=False`
10
  fs = HfFileSystem()
@@ -49,27 +50,69 @@ KEYS_TO_KEEP = [
49
  "job_link_nvidia",
50
  ]
51
 
52
- def read_one_dataframe(json_path: str, device_label: str) -> pd.DataFrame:
53
- logger.info(f"Reading df located at {json_path}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
  df = pd.read_json(json_path, orient="index")
55
  df.index.name = "model_name"
56
  df[f"failed_multi_no_{device_label}"] = df["failures"].apply(lambda x: len(x["multi"]) if "multi" in x else 0)
57
  df[f"failed_single_no_{device_label}"] = df["failures"].apply(lambda x: len(x["single"]) if "single" in x else 0)
58
- return df
59
 
60
- def get_distant_data() -> pd.DataFrame:
61
  # Retrieve AMD dataframe
62
  amd_src = "hf://datasets/optimum-amd/transformers_daily_ci/**/runs/**/ci_results_run_models_gpu/model_results.json"
63
  files_amd = sorted(fs.glob(amd_src, refresh=True), reverse=True)
64
- df_amd = read_one_dataframe(f"hf://{files_amd[0]}", "amd")
65
  # Retrieve NVIDIA dataframe, which pattern should be:
66
- # hf://datasets/hf-internal-testing/transformers_daily_ci/raw/main/YYYY-MM-DD/ci_results_run_models_gpu/model_results.json
67
  nvidia_src = "hf://datasets/hf-internal-testing/transformers_daily_ci/*/ci_results_run_models_gpu/model_results.json"
68
  files_nvidia = sorted(fs.glob(nvidia_src, refresh=True), reverse=True)
69
  # NOTE: should this be removeprefix instead of lstrip?
70
  nvidia_path = files_nvidia[0].lstrip('datasets/hf-internal-testing/transformers_daily_ci/')
71
  nvidia_path = "https://huggingface.co/datasets/hf-internal-testing/transformers_daily_ci/raw/main/" + nvidia_path
72
- df_nvidia = read_one_dataframe(nvidia_path, "nvidia")
 
 
73
  # Join both dataframes
74
  joined = df_amd.join(df_nvidia, rsuffix="_nvidia", lsuffix="_amd", how="outer")
75
  joined = joined[KEYS_TO_KEEP]
@@ -81,7 +124,7 @@ def get_distant_data() -> pd.DataFrame:
81
  for model in IMPORTANT_MODELS:
82
  if model not in filtered_joined.index:
83
  print(f"[WARNING] Model {model} was missing from index.")
84
- return filtered_joined
85
 
86
 
87
  def get_sample_data() -> pd.DataFrame:
@@ -140,14 +183,15 @@ class CIResults:
140
  def __init__(self):
141
  self.df = pd.DataFrame()
142
  self.available_models = []
143
- self.last_update_time = ""
144
 
145
  def load_data(self) -> None:
146
  """Load data from the data source."""
147
  # Try loading the distant data, and fall back on sample data for local tinkering
148
  try:
149
  logger.info("Loading distant data...")
150
- new_df = get_distant_data()
 
151
  except Exception as e:
152
  error_msg = [
153
  "Loading data failed:",
@@ -161,11 +205,10 @@ class CIResults:
161
  # Update attributes
162
  self.df = new_df
163
  self.available_models = new_df.index.tolist()
164
- self.last_update_time = datetime.now().strftime('%H:%M')
165
  # Log and return distant load status
166
  logger.info(f"Data loaded successfully: {len(self.available_models)} models")
167
  logger.info(f"Models: {self.available_models[:5]}{'...' if len(self.available_models) > 5 else ''}")
168
- logger.info(f"Last update: {self.last_update_time}")
169
  # Log a preview of the df
170
  msg = {}
171
  for model in self.available_models[:3]:
 
5
  import threading
6
  import traceback
7
  import json
8
+ import re
9
 
10
  # NOTE: if caching is an issue, try adding `use_listings_cache=False`
11
  fs = HfFileSystem()
 
50
  "job_link_nvidia",
51
  ]
52
 
53
+
54
+ def log_dataframe_link(link: str) -> str:
55
+ """
56
+ Adds the link to the dataset in the logs, modifies it to get a clockable link and then returns the date of the
57
+ report.
58
+ """
59
+ logger.info(f"Reading df located at {link}")
60
+ # Make sure the links starts with an http adress
61
+ if link.startswith("hf://"):
62
+ link = "https://huggingface.co/" + link.removeprefix("hf://")
63
+ # Pattern to match transformers_daily_ci followed by any path, then a date (YYYY-MM-DD format)
64
+ pattern = r'transformers_daily_ci(.*?)/(\d{4}-\d{2}-\d{2})'
65
+ match = re.search(pattern, link)
66
+ # Failure case:
67
+ if not match:
68
+ logger.error("Could not find transformers_daily_ci and.or date in the link")
69
+ return "9999-99-99"
70
+ # Replace the path between with blob/main
71
+ path_between = match.group(1)
72
+ link = link.replace("transformers_daily_ci" + path_between, "transformers_daily_ci/blob/main")
73
+ logger.info(f"Link to data source: {link}")
74
+ # Return the date
75
+ return match.group(2)
76
+
77
+ def infer_latest_update_msg(date_df_amd: str, date_df_nvidia: str) -> str:
78
+ # Early return if one of the dates is invalid
79
+ if date_df_amd.startswith("9999") and date_df_nvidia.startswith("9999"):
80
+ return "could not find last update time"
81
+ # Warn if dates are not the same
82
+ if date_df_amd != date_df_nvidia:
83
+ logger.warning(f"Different dates found: {date_df_amd} (AMD) vs {date_df_nvidia} (NVIDIA)")
84
+ # Take the latest date and format it
85
+ try:
86
+ latest_date = max(date_df_amd, date_df_nvidia)
87
+ yyyy, mm, dd = latest_date.split("-")
88
+ return f"last updated {mm}/{dd}/{yyyy}"
89
+ except Exception as e:
90
+ logger.error(f"When trying to infer latest date, got error {e}")
91
+ return "could not find last update time"
92
+
93
+ def read_one_dataframe(json_path: str, device_label: str) -> tuple[pd.DataFrame, str]:
94
+ df_upload_date = log_dataframe_link(json_path)
95
  df = pd.read_json(json_path, orient="index")
96
  df.index.name = "model_name"
97
  df[f"failed_multi_no_{device_label}"] = df["failures"].apply(lambda x: len(x["multi"]) if "multi" in x else 0)
98
  df[f"failed_single_no_{device_label}"] = df["failures"].apply(lambda x: len(x["single"]) if "single" in x else 0)
99
+ return df, df_upload_date
100
 
101
+ def get_distant_data() -> tuple[pd.DataFrame, str]:
102
  # Retrieve AMD dataframe
103
  amd_src = "hf://datasets/optimum-amd/transformers_daily_ci/**/runs/**/ci_results_run_models_gpu/model_results.json"
104
  files_amd = sorted(fs.glob(amd_src, refresh=True), reverse=True)
105
+ df_amd, date_df_amd = read_one_dataframe(f"hf://{files_amd[0]}", "amd")
106
  # Retrieve NVIDIA dataframe, which pattern should be:
107
+ # hf://datasets/hf-internal-testing`/transformers_daily_ci/raw/main/YYYY-MM-DD/ci_results_run_models_gpu/model_results.json
108
  nvidia_src = "hf://datasets/hf-internal-testing/transformers_daily_ci/*/ci_results_run_models_gpu/model_results.json"
109
  files_nvidia = sorted(fs.glob(nvidia_src, refresh=True), reverse=True)
110
  # NOTE: should this be removeprefix instead of lstrip?
111
  nvidia_path = files_nvidia[0].lstrip('datasets/hf-internal-testing/transformers_daily_ci/')
112
  nvidia_path = "https://huggingface.co/datasets/hf-internal-testing/transformers_daily_ci/raw/main/" + nvidia_path
113
+ df_nvidia, date_df_nvidia = read_one_dataframe(nvidia_path, "nvidia")
114
+ # Infer and format the latest df date
115
+ latest_update_msg = infer_latest_update_msg(date_df_amd, date_df_nvidia)
116
  # Join both dataframes
117
  joined = df_amd.join(df_nvidia, rsuffix="_nvidia", lsuffix="_amd", how="outer")
118
  joined = joined[KEYS_TO_KEEP]
 
124
  for model in IMPORTANT_MODELS:
125
  if model not in filtered_joined.index:
126
  print(f"[WARNING] Model {model} was missing from index.")
127
+ return filtered_joined, latest_update_msg
128
 
129
 
130
  def get_sample_data() -> pd.DataFrame:
 
183
  def __init__(self):
184
  self.df = pd.DataFrame()
185
  self.available_models = []
186
+ self.latest_update_msg = ""
187
 
188
  def load_data(self) -> None:
189
  """Load data from the data source."""
190
  # Try loading the distant data, and fall back on sample data for local tinkering
191
  try:
192
  logger.info("Loading distant data...")
193
+ new_df, latest_update_msg = get_distant_data()
194
+ self.latest_update_msg = latest_update_msg
195
  except Exception as e:
196
  error_msg = [
197
  "Loading data failed:",
 
205
  # Update attributes
206
  self.df = new_df
207
  self.available_models = new_df.index.tolist()
 
208
  # Log and return distant load status
209
  logger.info(f"Data loaded successfully: {len(self.available_models)} models")
210
  logger.info(f"Models: {self.available_models[:5]}{'...' if len(self.available_models) > 5 else ''}")
211
+ logger.info(f"Latest update message: {self.latest_update_msg}")
212
  # Log a preview of the df
213
  msg = {}
214
  for model in self.available_models[:3]: