{"record":{"id":"c0effc8035a4f1b1","repo":"microsoft/qlib","slug":"unknown-metric-s-c0effc","errorCode":null,"errorMessage":"unknown metric `%s`","messagePattern":"unknown metric `(.+?)`","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"qlib/contrib/model/pytorch_gats_ts.py","lineNumber":182,"sourceCode":"    def mse(self, pred, label):\n        loss = (pred - label) ** 2\n        return torch.mean(loss)\n\n    def loss_fn(self, pred, label):\n        mask = ~torch.isnan(label)\n\n        if self.loss == \"mse\":\n            return self.mse(pred[mask], label[mask])\n\n        raise ValueError(\"unknown loss `%s`\" % self.loss)\n\n    def metric_fn(self, pred, label):\n        mask = torch.isfinite(label)\n\n        if self.metric in (\"\", \"loss\"):\n            return -self.loss_fn(pred[mask], label[mask])\n\n        raise ValueError(\"unknown metric `%s`\" % self.metric)\n\n    def get_daily_inter(self, df, shuffle=False):\n        # organize the train data into daily batches\n        daily_count = df.groupby(level=0, group_keys=False).size().values\n        daily_index = np.roll(np.cumsum(daily_count), 1)\n        daily_index[0] = 0\n        if shuffle:\n            # shuffle data\n            daily_shuffle = list(zip(daily_index, daily_count))\n            np.random.shuffle(daily_shuffle)\n            daily_index, daily_count = zip(*daily_shuffle)\n        return daily_index, daily_count\n\n    def train_epoch(self, data_loader):\n        self.GAT_model.train()\n\n        for data in data_loader:\n            data = data.squeeze()","sourceCodeStart":164,"sourceCodeEnd":200,"githubUrl":"https://github.com/microsoft/qlib/blob/79633dd9506ea689e5400dea0197717b5b3d74b7/qlib/contrib/model/pytorch_gats_ts.py#L164-L200","documentation":"GATsTSModel.metric_fn validates self.metric against only '' or 'loss'; there is no 'mse' branch, so even metric='mse' raises ValueError during the first validation pass in fit(). Early stopping depends on this metric, so training aborts before any epoch completes.","triggerScenarios":"GATsTSModel(metric='mse') or metric='ic' followed by fit(); first validation epoch calls metric_fn and raises.","commonSituations":"Reusing metric settings from ALSTM (which supports 'mse'); assuming a shared metric vocabulary across qlib contrib models; config templates with non-empty defaults.","solutions":["Set metric='' or 'loss'.","Strip metric='mse' from configs ported from ALSTM-based workflows.","Subclass GATsTSModel to extend metric_fn if a custom metric is required."],"exampleFix":"# before\nmodel = GATsTSModel(metric='mse')\n\n# after\nmodel = GATsTSModel(metric='loss')","handlingStrategy":"validation","validationCode":"assert model.metric in ('', 'loss'), f\"GATsTSModel metric must be '' or 'loss', got {model.metric!r}\"","typeGuard":"def is_supported_gats_metric(metric: str) -> bool:\n    return metric in ('', 'loss')","tryCatchPattern":"try:\n    model.fit(dataset)\nexcept ValueError as e:\n    if 'unknown metric' in str(e):\n        model.metric = 'loss'\n        model.fit(dataset)\n    else:\n        raise","preventionTips":["Do not assume 'mse' is a valid metric everywhere; GATs variants only accept ''/'loss'.","Validate metric per model class before fit.","Store supported hyperparameter values next to model choice in experiment configs."],"tags":["pytorch","qlib","metrics","config-validation","gats-ts"],"backgroundTag":null,"analyzedSha":"79633dd9506ea689e5400dea0197717b5b3d74b7","analyzedAt":"2026-08-15T07:01:27.511Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}