{"record":{"id":"a66c25096f86b87a","repo":"microsoft/qlib","slug":"unknown-criterion-self-criterion","errorCode":null,"errorMessage":"Unknown criterion: {self.criterion}","messagePattern":"Unknown criterion: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"qlib/contrib/meta/data_selection/model.py","lineNumber":104,"sourceCode":"                meta_input[\"X\"],\n                meta_input[\"y\"],\n                meta_input[\"time_perf\"],\n                meta_input[\"time_belong\"],\n                meta_input[\"X_test\"],\n                ignore_weight=ignore_weight,\n            )\n            if self.criterion == \"mse\":\n                criterion = nn.MSELoss()\n                loss = criterion(pred, meta_input[\"y_test\"])\n            elif self.criterion == \"ic_loss\":\n                criterion = ICLoss(self.loss_skip_thresh)\n                try:\n                    loss = criterion(pred, meta_input[\"y_test\"], meta_input[\"test_idx\"])\n                except ValueError as e:\n                    get_module_logger(\"MetaModelDS\").warning(f\"Exception `{e}` when calculating IC loss\")\n                    continue\n            else:\n                raise ValueError(f\"Unknown criterion: {self.criterion}\")\n\n            assert not np.isnan(loss.detach().item()), \"NaN loss!\"\n\n            if phase == \"train\":\n                opt.zero_grad()\n                loss.backward()\n                opt.step()\n            elif phase == \"test\":\n                pass\n\n            pred_y_all.append(\n                pd.DataFrame(\n                    {\n                        \"pred\": pd.Series(pred.detach().cpu().numpy(), index=meta_input[\"test_idx\"]),\n                        \"label\": pd.Series(meta_input[\"y_test\"].detach().cpu().numpy(), index=meta_input[\"test_idx\"]),\n                    }\n                )\n            )","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/microsoft/qlib/blob/79633dd9506ea689e5400dea0197717b5b3d74b7/qlib/contrib/meta/data_selection/model.py#L86-L122","documentation":"MetaModelDS.train_only_logs/test loop computes its loss with either nn.MSELoss (criterion='mse') or the custom ICLoss (criterion='ic_loss'). Any other criterion string reaches the else and raises ValueError, because no other loss constructor is wired in.","triggerScenarios":"Constructing MetaModelDS(..., criterion='mae') or 'cross_entropy' etc.; the constructor accepts the string without validating it, so the error surfaces only when training starts.","commonSituations":"Trying standard PyTorch loss names on the meta model; typo like 'IC_loss' or 'ICLoss'; copy-pasting criterion configs from other qlib model classes.","solutions":["Use criterion=\"mse\" for plain regression loss on meta labels.","Use criterion=\"ic_loss\" to optimize the (negative) information-coefficient loss over daily cross-sections.","If you need another loss, subclass MetaModelDS and add a branch constructing your nn.Module criterion."],"exampleFix":"// before\nmodel = MetaModelDS(..., criterion=\"IC_loss\")  # trains then raises\n\n// after\nmodel = MetaModelDS(..., criterion=\"ic_loss\")","handlingStrategy":"validation","validationCode":"if criterion not in (\"mse\", \"ic_loss\"):\n    raise ValueError(f\"MetaModelDS criterion must be 'mse' or 'ic_loss', got {criterion!r}\")\nmodel = MetaModelDS(..., criterion=criterion)","typeGuard":"def is_meta_criterion(c) -> bool:\n    return c in (\"mse\", \"ic_loss\")","tryCatchPattern":"try:\n    model.fit(...)\nexcept ValueError as e:\n    if \"Unknown criterion\" in str(e):\n        raise ValueError(\"criterion must be 'mse' or 'ic_loss'\") from e\n    raise","preventionTips":["Validate criterion at construction time, since MetaModelDS defers the error to training.","Note 'ic_loss' additionally skips batches whose IC calc fails (logged warning).","Subclass to add losses rather than passing unsupported names."],"tags":["qlib","meta-learning","data-selection","criterion","pytorch"],"backgroundTag":null,"analyzedSha":"79633dd9506ea689e5400dea0197717b5b3d74b7","analyzedAt":"2026-08-15T07:01:27.511Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}