{"record":{"id":"520c3c69a084a55a","repo":"microsoft/qlib","slug":"unknown-loss-s-520c3c","errorCode":null,"errorMessage":"unknown loss `%s`","messagePattern":"unknown loss `(.+?)`","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"qlib/contrib/model/pytorch_igmtf.py","lineNumber":153,"sourceCode":"\n        self.fitted = False\n        self.igmtf_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 == \"ic\":\n            x = pred[mask]\n            y = label[mask]\n\n            vx = x - torch.mean(x)\n            vy = y - torch.mean(y)\n            return torch.sum(vx * vy) / (torch.sqrt(torch.sum(vx**2)) * torch.sqrt(torch.sum(vy**2)))\n\n        if self.metric == (\"\", \"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):","sourceCodeStart":135,"sourceCodeEnd":171,"githubUrl":"https://github.com/microsoft/qlib/blob/79633dd9506ea689e5400dea0197717b5b3d74b7/qlib/contrib/model/pytorch_igmtf.py#L135-L171","documentation":"IGMTFModel.loss_fn implements exactly one loss: 'mse', computed over non-NaN labels via a mask. If self.loss is any other string, loss_fn raises this ValueError the first time the training loop tries to compute loss.","triggerScenarios":"Constructing IGMTFModel(loss='mse') variants misspelled, or loss='cross_entropy'/'huber'/None, then calling fit(): the error surfaces on the first train epoch batch.","commonSituations":"Copying a loss name supported by a different qlib model (some support more losses); typo 'msee'; leaving a placeholder value in a shared hyperparameter search grid that includes unsupported losses.","solutions":["Set loss='mse' (this is the only supported value)","For custom losses, subclass IGMTFModel and extend loss_fn"],"exampleFix":"# before\nIGMTFModel(loss=\"mean_squared_error\")\n\n# after\nIGMTFModel(loss=\"mse\")","handlingStrategy":"validation","validationCode":"assert loss == \"mse\", f\"IGMTFModel supports only loss='mse', got {loss!r}\"","typeGuard":"def is_supported_igmtf_loss(name: str) -> bool:\n    return name == \"mse\"","tryCatchPattern":null,"preventionTips":["Restrict hyperparameter search grids for loss to values the target model implements","Read each model's loss_fn/metric_fn once before configuring it"],"tags":["qlib","igmtf","loss-function","invalid-argument"],"backgroundTag":null,"analyzedSha":"79633dd9506ea689e5400dea0197717b5b3d74b7","analyzedAt":"2026-08-15T07:01:27.511Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}