-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wrap each metric update in try/except. #3562
Conversation
try: | ||
if prediction_key == RESPONSE: | ||
if tokenizer is not None: | ||
# RESPONSE metrics cannot be computed if decoded texts are not provided. | ||
# Decoded texts are only provided using the LLM model type. | ||
if decoded_targets is not None and decoded_predictions is not None: | ||
if metric_name == "bleu": | ||
# BLEU takes in targets as a list. | ||
metric_fn.update(decoded_predictions, [decoded_targets]) | ||
else: | ||
metric_fn.update(decoded_predictions, decoded_targets) | ||
else: | ||
metric_fn = metric_fn.to(predictions[prediction_key].device) | ||
metric_fn.update(predictions[prediction_key].detach(), targets) | ||
except Exception as e: | ||
logger.info(f"Ran into error when calculating metric {metric_name}. Skipping. The error is: {e}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, so will the metric function have no value then that we can collect later? Will that cause an error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should be ok. get_metrics()
is already wrapped in a try/except:
def get_metrics(self):
metric_vals = {}
for metric_name, metric_fn in self._metric_functions.items():
try:
computed_metric = metric_fn.compute()
except Exception as e:
logger.exception(f"Caught exception computing metric: {metric_name} with error: {e}.")
continue
And it also looks like there's default values for torchmetrics, even if no update() was called.
from torchmetrics.text import BLEUScore
bleu = BLEUScore()
bleu.compute()
/Users/justinzhao/ludwig/env/lib/python3.8/site-packages/torchmetrics/utilities/prints.py:36: UserWarning: The ``compute`` method of metric BLEUScore was called before the ``update`` method which may lead to errors, as metric states have not yet been updated.
warnings.warn(*args, **kwargs)
tensor(0.)
No description provided.