Repository navigation
Commit 9b5758f
authored
Fix Inspector plot crash on non-finite metrics (pytorch#23400)
### Summary
Follow-up to pytorch#23276. While testing that one I noticed
`compare_results(plot=True)` (and so `inspector_cli --compare_results`)
still crashes when a metric isn't finite. SNR is inf when the run output
matches the reference exactly, and -inf when the reference is all zeros.
`plot_metric` then passes that into `plt.ylim` and matplotlib raises
`ValueError: Axis limits cannot be NaN or Inf`. So the plot fails in the
best case, when outputs match perfectly.
This plots non-finite values as 0 (same as we do for None), while the
bar label still shows the real value (`inf`, `-inf`, `nan`). Also fixed
the `plot_metric` type hint to `List[Optional[float]]` to match what
compare_results passes in.
### Test plan
Added test_compare_results_plot_non_finite_metrics in
devtools/inspector/tests/inspector_utils_test.py. It covers identical
tensors (SNR inf) and an all-zero reference (SNR -inf) with plot=True.
It fails on main with the ValueError above and passes with the fix, and
the rest of inspector_utils_test.py passes (91 tests). ufmt and flake8
are clean with the versions from requirements-lintrunner.txt.
cc @Gasoonjia @nil-is-all1 parent ad40fa9 commit 9b5758f
2 files changed
Lines changed: 43 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
394 | 394 | | |
395 | 395 | | |
396 | 396 | | |
397 | | - | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
398 | 402 | | |
399 | 403 | | |
400 | 404 | | |
401 | 405 | | |
402 | 406 | | |
403 | 407 | | |
404 | 408 | | |
405 | | - | |
406 | | - | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
407 | 414 | | |
408 | 415 | | |
409 | 416 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
| 10 | + | |
9 | 11 | | |
10 | 12 | | |
11 | 13 | | |
| |||
42 | 44 | | |
43 | 45 | | |
44 | 46 | | |
| 47 | + | |
45 | 48 | | |
46 | 49 | | |
47 | 50 | | |
| |||
246 | 249 | | |
247 | 250 | | |
248 | 251 | | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
249 | 282 | | |
250 | 283 | | |
251 | 284 | | |
| |||
0 commit comments