{"record":{"id":"ad57cd86b9a971a7","repo":"fishaudio/fish-speech","slug":"metric-value-not-found-metric-name-metric-name","errorCode":null,"errorMessage":"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!","messagePattern":"Metric value not found! <metric_name=(.+?)>\\\\nMake sure metric name logged in LightningModule is correct!\\\\nMake sure `optimized_metric` name in `hparams_search` config is correct!","errorType":"validation","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"fish_speech/utils/utils.py","lineNumber":108,"sourceCode":"\n                if wandb.run:\n                    log.info(\"Closing wandb!\")\n                    wandb.finish()\n\n        return metric_dict, object_dict\n\n    return wrap\n\n\ndef get_metric_value(metric_dict: dict, metric_name: str) -> float:\n    \"\"\"Safely retrieves value of the metric logged in LightningModule.\"\"\"\n\n    if not metric_name:\n        log.info(\"Metric name is None! Skipping metric value retrieval...\")\n        return None\n\n    if metric_name not in metric_dict:\n        raise Exception(\n            f\"Metric value not found! <metric_name={metric_name}>\\n\"\n            \"Make sure metric name logged in LightningModule is correct!\\n\"\n            \"Make sure `optimized_metric` name in `hparams_search` config is correct!\"\n        )\n\n    metric_value = metric_dict[metric_name].item()\n    log.info(f\"Retrieved metric value! <{metric_name}={metric_value}>\")\n\n    return metric_value\n\n\ndef set_seed(seed: int):\n    if seed < 0:\n        seed = -seed\n    if seed > (1 << 31):\n        seed = 1 << 31\n\n    random.seed(seed)","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/fishaudio/fish-speech/blob/befe4001745417f8c42131739d862b8a6fdbd15a/fish_speech/utils/utils.py#L90-L126","documentation":"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.","triggerScenarios":"Running hyperparameter search where optimized_metric (e.g. 'val/loss') does not match any metric the LightningModule logs to self.log(...).","commonSituations":"Renamed metrics in the module but not in hparams_search config; typo in optimized_metric; metric only logged under a different stage/name.","solutions":["Inspect metric_dict keys (print the returned metrics dict) and match optimized_metric exactly","Update hparams_search.optimized_metric to a metric that is actually logged","Ensure the LightningModule calls self.log('<name>', ...) on the validated/tested stage used by the search"],"exampleFix":"# before\nhparams_search:\n  optimized_metric: val_loss\n# after (module logs self.log(\"val/loss\", ...))\nhparams_search:\n  optimized_metric: val/loss","handlingStrategy":"validation","validationCode":"if optimized_metric and optimized_metric not in metric_dict:\n    available = sorted(metric_dict)\n    raise KeyError(f\"{optimized_metric} not in {available}\")","typeGuard":null,"tryCatchPattern":"try:\n    value = get_metric_value(metric_dict, name)\nexcept Exception:\n    value = None  # or pick a fallback metric","preventionTips":["Log a fixed canonical metric name in the module","Add a test asserting optimized_metric appears in logged metrics"],"tags":["hydra","hyperparameter-search","metrics"],"backgroundTag":"metric-not-found","analyzedSha":"befe4001745417f8c42131739d862b8a6fdbd15a","analyzedAt":"2026-08-27T21:31:45.703Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}