{"record":{"id":"a0268a8c821a4edc","repo":"microsoft/qlib","slug":"unknown-loss-s-a0268a","errorCode":null,"errorMessage":"unknown loss `%s`","messagePattern":"unknown loss `(.+?)`","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"qlib/contrib/model/pytorch_gats_ts.py","lineNumber":174,"sourceCode":"\n        self.fitted = False\n        self.GAT_model.to(self.device)\n\n    @property\n    def use_gpu(self):\n        return self.device != torch.device(\"cpu\")\n\n    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)","sourceCodeStart":156,"sourceCodeEnd":192,"githubUrl":"https://github.com/microsoft/qlib/blob/79633dd9506ea689e5400dea0197717b5b3d74b7/qlib/contrib/model/pytorch_gats_ts.py#L156-L192","documentation":"GATsTSModel.loss_fn implements a single branch, self.loss == 'mse'; any other value raises ValueError the first time the training loop computes the loss in fit(). This mirrors the non-ts GATs model: MSE is the only supported objective.","triggerScenarios":"GATsTSModel(loss='mae') or any non-'mse' string followed by fit(); the first batch triggers loss_fn and raises.","commonSituations":"Hyperparameter sweeps that vary loss across models; configs copied from other contrib models; blank or default-mismatched loss values in workflow YAML.","solutions":["Keep loss='mse' (the default).","Audit the loss hyperparameter for typos and cross-model copy-paste.","Subclass GATsTSModel and add loss branches in loss_fn for custom objectives."],"exampleFix":"# before\nmodel = GATsTSModel(loss='mae')\n\n# after\nmodel = GATsTSModel(loss='mse')","handlingStrategy":"validation","validationCode":"assert model.loss == 'mse', f\"GATsTSModel only supports loss='mse', got {model.loss!r}\"","typeGuard":"def is_supported_gats_loss(loss: str) -> bool:\n    return loss == 'mse'","tryCatchPattern":"try:\n    model.fit(dataset)\nexcept ValueError as e:\n    if 'unknown loss' in str(e):\n        model.loss = 'mse'\n        model.fit(dataset)\n    else:\n        raise","preventionTips":["Fix loss='mse' in GATs-ts configs.","Reject non-'mse' loss values in config validation.","Subclass up front if your research needs another loss, rather than discovering at runtime."],"tags":["pytorch","qlib","loss-function","config-validation","gats-ts"],"backgroundTag":null,"analyzedSha":"79633dd9506ea689e5400dea0197717b5b3d74b7","analyzedAt":"2026-08-15T07:01:27.511Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}