fishaudio/fish-speech · error · Exception

Metric value not found! <metric_name={metric_name}>\nMake su

Error message

Metric value not found! <metric_name={metric_name}>\nMake sure metric name logged in LightningModule is correct!\nMake sure `optimized_metric` name in `hparams_search` config is correct!

What it means

get_metric_value extracts the optimized metric from the hydra-swept result; if metric_name is not a key of metric_dict it raises a generic Exception with guidance to check the LightningModule logging and hparams_search.optimized_metric.

Source

Thrown at fish_speech/utils/utils.py:108

                if wandb.run:
                    log.info("Closing wandb!")
                    wandb.finish()

        return metric_dict, object_dict

    return wrap


def get_metric_value(metric_dict: dict, metric_name: str) -> float:
    """Safely retrieves value of the metric logged in LightningModule."""

    if not metric_name:
        log.info("Metric name is None! Skipping metric value retrieval...")
        return None

    if metric_name not in metric_dict:
        raise Exception(
            f"Metric value not found! <metric_name={metric_name}>\n"
            "Make sure metric name logged in LightningModule is correct!\n"
            "Make sure `optimized_metric` name in `hparams_search` config is correct!"
        )

    metric_value = metric_dict[metric_name].item()
    log.info(f"Retrieved metric value! <{metric_name}={metric_value}>")

    return metric_value


def set_seed(seed: int):
    if seed < 0:
        seed = -seed
    if seed > (1 << 31):
        seed = 1 << 31

    random.seed(seed)

View on GitHub (pinned to befe400174)

Solutions

  1. Inspect metric_dict keys (print the returned metrics dict) and match optimized_metric exactly
  2. Update hparams_search.optimized_metric to a metric that is actually logged
  3. Ensure the LightningModule calls self.log('<name>', ...) on the validated/tested stage used by the search

Example fix

# before
hparams_search:
  optimized_metric: val_loss
# after (module logs self.log("val/loss", ...))
hparams_search:
  optimized_metric: val/loss
Defensive patterns

Strategy: validation

Validate before calling

if optimized_metric and optimized_metric not in metric_dict:
    available = sorted(metric_dict)
    raise KeyError(f"{optimized_metric} not in {available}")

Try / catch

try:
    value = get_metric_value(metric_dict, name)
except Exception:
    value = None  # or pick a fallback metric

Prevention

When it happens

Trigger: Running hyperparameter search where optimized_metric (e.g. 'val/loss') does not match any metric the LightningModule logs to self.log(...).

Common situations: Renamed metrics in the module but not in hparams_search config; typo in optimized_metric; metric only logged under a different stage/name.

Related errors


AI-assisted analysis of fishaudio/fish-speech@befe400174 (2026-08-27). Data as JSON: /api/errors/ad57cd86b9a971a7. Report an issue: GitHub.