|
20 | 20 | "outputs": [], |
21 | 21 | "source": [ |
22 | 22 | "# replace by your profile path, it can be a single rank profile from a multi gpu run as well\n", |
| 23 | + "# If you are interested in replaying from perf report then skip down \n", |
23 | 24 | "path =\"/home/buffer/resnet_trace.json\"\n", |
24 | 25 | "perf_analyzer = TreePerfAnalyzer.from_file(path)" |
25 | 26 | ] |
|
32 | 33 | "outputs": [], |
33 | 34 | "source": [ |
34 | 35 | "# Replay works for any op, taking gemm as example \n", |
35 | | - "# gemm_events = [event for event in perf_analyzer.tree.events if event['name'] in ['aten::addmm', 'aten::mm', 'aten::_scaled_mm']]\n", |
36 | | - "gemm_events = [event for event in perf_analyzer.tree.events if event['name'] in ['aten::convolution']]\n", |
| 36 | + "gemm_events = [event for event in perf_analyzer.tree.events if event['name'] in ['aten::addmm', 'aten::mm', 'aten::_scaled_mm']]\n", |
37 | 37 | "df_gemm_ops = perf_analyzer.build_df_perf_metrics(gemm_events)\n", |
38 | 38 | "df_gemm_summary = perf_analyzer.summarize_df_perf_metrics(df_gemm_ops, ['mean'])\n", |
39 | 39 | "df_gemm_summary" |
|
218 | 218 | "print(f\"Created zip file: {zip_file_path}\")" |
219 | 219 | ] |
220 | 220 | }, |
| 221 | + { |
| 222 | + "cell_type": "markdown", |
| 223 | + "id": "1722250f", |
| 224 | + "metadata": {}, |
| 225 | + "source": [ |
| 226 | + "Replay ops from report" |
| 227 | + ] |
| 228 | + }, |
221 | 229 | { |
222 | 230 | "cell_type": "code", |
223 | 231 | "execution_count": null, |
224 | 232 | "id": "144ce15b-5f0a-4f8e-b7a2-f287154a5d18", |
225 | 233 | "metadata": {}, |
226 | 234 | "outputs": [], |
227 | 235 | "source": [ |
228 | | - "batched_replay.__file__" |
| 236 | + "# we can replay events from the perf reports as well - without the full profile too!\n", |
| 237 | + "# This is because we essentially require the args and the op name to replay\n", |
| 238 | + "# excel -> df -> for each row (row -> event -> replayer -> replayer IR -> append to replayer IR list) -> save replayer IR list as json\n", |
| 239 | + "import pandas as pd\n", |
| 240 | + "import ast\n", |
| 241 | + "# read sheet from excel\n", |
| 242 | + "\n", |
| 243 | + "df_unique_ops = pd.read_excel('/path/to/your/perf_report.xlsx', sheet_name='sheet_name')\n", |
| 244 | + "\n", |
| 245 | + "def row_to_evt(row):\n", |
| 246 | + " event = {\n", |
| 247 | + " 'name': row['name'],\n", |
| 248 | + " 'args': {\n", |
| 249 | + " 'Input Dims': ast.literal_eval(row['Input Dims']),\n", |
| 250 | + " 'Input Strides': ast.literal_eval(row['Input Strides']),\n", |
| 251 | + " 'Input type': ast.literal_eval(row['Input type']),\n", |
| 252 | + " 'Concrete Inputs': ast.literal_eval(row['Concrete Inputs']),\n", |
| 253 | + " }\n", |
| 254 | + " }\n", |
| 255 | + " return event\n" |
| 256 | + ] |
| 257 | + }, |
| 258 | + { |
| 259 | + "cell_type": "code", |
| 260 | + "execution_count": null, |
| 261 | + "id": "eb91e0c0", |
| 262 | + "metadata": {}, |
| 263 | + "outputs": [], |
| 264 | + "source": [ |
| 265 | + "repro_data_list = []\n", |
| 266 | + "processed_count = 0\n", |
| 267 | + "# lets say we are interested in the following ops\n", |
| 268 | + "ops_interest = ['aten::miopen_convolution',\n", |
| 269 | + " 'aten::convolution_backward', \n", |
| 270 | + " 'aten::miopen_batch_norm',\n", |
| 271 | + " 'aten::miopen_batch_norm_backward'] \n", |
| 272 | + "\n", |
| 273 | + "df_ops_interest = df_unique_ops[df_unique_ops['name'].isin(ops_interest)].copy()\n", |
| 274 | + "\n", |
| 275 | + "for index, row in df_ops_interest.iterrows():\n", |
| 276 | + " event = row_to_evt(row)\n", |
| 277 | + " # Initialize EventReplayer similar to above\n", |
| 278 | + " replayer = EventReplayer(event, lazy=True, verbose=False)\n", |
| 279 | + " # Extract the serializable info\n", |
| 280 | + " repro_info = replayer.get_repro_info()\n", |
| 281 | + " repro_data_list.append(repro_info)\n", |
| 282 | + " processed_count += 1\n", |
| 283 | + "print(f\"Processed {processed_count} events.\")\n", |
| 284 | + "# --- Save the Extracted Data ---\n", |
| 285 | + "OUTPUT_REPRO_FILE = '/path/to/your/output/replay_ir.json'\n", |
| 286 | + "if repro_data_list:\n", |
| 287 | + " print(f\"\\nSaving {len(repro_data_list)} extracted operator infos to '{OUTPUT_REPRO_FILE}'...\")\n", |
| 288 | + " with open(OUTPUT_REPRO_FILE, 'w') as f:\n", |
| 289 | + " json.dump(repro_data_list, f, indent=4)\n", |
| 290 | + " print(\"Save complete.\")" |
| 291 | + ] |
| 292 | + }, |
| 293 | + { |
| 294 | + "cell_type": "code", |
| 295 | + "execution_count": null, |
| 296 | + "id": "a0245187", |
| 297 | + "metadata": {}, |
| 298 | + "outputs": [], |
| 299 | + "source": [ |
| 300 | + "# STANDALONE ARTIFACTS FOR REPRO - independent of model code or tracelens code\n", |
| 301 | + "# artifacts include (a)replay_ir.json, (b) utils.py, (c) batched_replay.py\n", |
| 302 | + "files = [\n", |
| 303 | + " OUTPUT_REPRO_FILE,\n", |
| 304 | + " tl_utils.__file__, # Path to utils.py\n", |
| 305 | + " batched_replay.__file__, # Path to batched_replay.py\n", |
| 306 | + " batched_replay.__file__.replace('batched_replay.py', 'batched_replay_readme.md') # path to the readme\n", |
| 307 | + "]\n", |
| 308 | + "zip_file_path = '/path/to/your/directory/replay_code.zip' # Specify your desired zip file path\n", |
| 309 | + "with zipfile.ZipFile(zip_file_path, 'w') as zipf:\n", |
| 310 | + " for file in files:\n", |
| 311 | + " zipf.write(file, arcname=os.path.basename(file)) # ← use file.name\n", |
| 312 | + "print(f\"Created zip file: {zip_file_path}\")" |
229 | 313 | ] |
230 | 314 | } |
231 | 315 | ], |
|
0 commit comments