@@ -217,11 +217,12 @@ def write_to_csv(csv_path: str, calculate_metrics_results: List[Dict[str, Any]])
217217 if not isinstance (calculate_metrics_results [0 ], dict ):
218218 raise ValueError ("metrics result is not a dict." )
219219
220- def flatten_dict (current_dict : Dict , output_dict : Dict ) -> Dict :
220+ def flatten_dict (current_dict : Dict ) -> Dict :
221221 """Recursively flattens a nested dictionary."""
222+ output_dict = {}
222223 for key , val in current_dict .items ():
223224 if isinstance (val , Dict ):
224- output_dict = flatten_dict (val , output_dict )
225+ output_dict . update ( flatten_dict (val ) )
225226 else :
226227 # Try to evaluate string-formatted literals (e.g., "[1, 2, 3]")
227228 try :
@@ -233,10 +234,7 @@ def flatten_dict(current_dict: Dict, output_dict: Dict) -> Dict:
233234
234235 def convert_dict_to_df (target_dict : Dict ) -> pd .DataFrame :
235236 """Converts a single benchmark result dictionary to a pandas DataFrame."""
236- flattened_dict = flatten_dict (target_dict , {})
237-
238- # TODO(user): Generalize this hard-coded value if needed.
239- flattened_dict ["dtype" ] = "bfloat16"
237+ flattened_dict = flatten_dict (target_dict )
240238
241239 # This section is specific to collective benchmarks that produce
242240 # 'ici_average_time_ms_list'.
@@ -249,7 +247,6 @@ def convert_dict_to_df(target_dict: Dict) -> pd.DataFrame:
249247 for key , val in ici_average_time_ms_statistics .items ():
250248 flattened_dict ["ici_average_time_ms_" + key ] = val
251249
252-
253250 # Convert list to JSON string for CSV storage.
254251 flattened_dict ["ici_average_time_ms_list" ] = json .dumps (
255252 flattened_dict ["ici_average_time_ms_list" ]
@@ -258,7 +255,6 @@ def convert_dict_to_df(target_dict: Dict) -> pd.DataFrame:
258255 df = pd .DataFrame (flattened_dict , index = [0 ])
259256 return df
260257
261- # Create a list of DataFrames and concatenate them once for efficiency.
262258 # TODO(hylin2002@)
263259 # This is a temporary workaround to generate a properly formatted CSV file for the output metrics.
264260 # We should revert this PR and refactor the code such that metrics object is a flatten dict that can be easily exported as a CSV.
0 commit comments