fix: bare except → except Exception in evaluate.py#109
Conversation
JiwaniZakir
left a comment
There was a problem hiding this comment.
The fix in evaluate.py is a meaningful improvement over a bare except:, since that would silently swallow KeyboardInterrupt, SystemExit, and other BaseException subclasses. That said, except Exception is still broader than necessary here — the expected failure when loading a torch.compiled checkpoint is almost a RuntimeError or KeyError from load_state_dict mismatched keys, so narrowing to except (RuntimeError, KeyError) would make the intent explicit and prevent unrelated exceptions from being quietly routed to the fallback path.
There's also no logging inside the except block, so if something unexpected causes the first load_state_dict to fail (e.g., a corrupted checkpoint, a CUDA OOM), the code silently retries with the prefix-stripped variant, likely producing a confusing error from the second call rather than a clear message about the root cause. Adding even a logging.warning or print noting that the key-stripping fallback was triggered would help with debugging. The second load_state_dict call itself is also unguarded, so a failure there will surface as an unhandled exception regardless.
Replace bare
except:withexcept Exception:in evaluation metric parsing.