{"record":{"id":"6b14a8092530925e","repo":"microsoft/qlib","slug":"optimizer-is-not-supported-6b14a8","errorCode":null,"errorMessage":"optimizer {} is not supported!","messagePattern":"optimizer (.+?) is not supported!","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"qlib/contrib/model/pytorch_gats_ts.py","lineNumber":155,"sourceCode":"            np.random.seed(self.seed)\n            torch.manual_seed(self.seed)\n\n        self.GAT_model = GATModel(\n            d_feat=self.d_feat,\n            hidden_size=self.hidden_size,\n            num_layers=self.num_layers,\n            dropout=self.dropout,\n            base_model=self.base_model,\n        )\n        self.logger.info(\"model:\\n{:}\".format(self.GAT_model))\n        self.logger.info(\"model size: {:.4f} MB\".format(count_parameters(self.GAT_model)))\n\n        if optimizer.lower() == \"adam\":\n            self.train_optimizer = optim.Adam(self.GAT_model.parameters(), lr=self.lr)\n        elif optimizer.lower() == \"gd\":\n            self.train_optimizer = optim.SGD(self.GAT_model.parameters(), lr=self.lr)\n        else:\n            raise NotImplementedError(\"optimizer {} is not supported!\".format(optimizer))\n\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","sourceCodeStart":137,"sourceCodeEnd":173,"githubUrl":"https://github.com/microsoft/qlib/blob/79633dd9506ea689e5400dea0197717b5b3d74b7/qlib/contrib/model/pytorch_gats_ts.py#L137-L173","documentation":"GATsTSModel.fit() builds its training optimizer from the optimizer hyperparameter with exactly two branches: 'adam' -> torch.optim.Adam and 'gd' -> torch.optim.SGD (both case-insensitive). Any other string raises NotImplementedError before training starts. The time-series GATs variant shares the same constrained optimizer switch as the non-ts version.","triggerScenarios":"GATsTSModel(...).fit(dataset) with optimizer='sgd', 'adamw', 'rmsprop', or any string besides 'adam'/'gd'.","commonSituations":"Writing 'sgd' instead of the expected 'gd'; migrating configs from models with wider optimizer support; attempting to use decoupled weight-decay optimizers like AdamW which are not wired in.","solutions":["Use 'adam' or 'gd' as the optimizer value.","Replace 'sgd' with 'gd'.","Subclass GATsTSModel and add a branch for the torch.optim optimizer you need."],"exampleFix":"# before\nmodel = GATsTSModel(optimizer='adamw')\n\n# after\nmodel = GATsTSModel(optimizer='adam')","handlingStrategy":"validation","validationCode":"assert optimizer.lower() in ('adam', 'gd'), f\"optimizer must be 'adam' or 'gd', got {optimizer!r}\"","typeGuard":"def is_supported_optimizer(name: str) -> bool:\n    return name.lower() in ('adam', 'gd')","tryCatchPattern":"try:\n    model.fit(dataset)\nexcept NotImplementedError as e:\n    if 'optimizer' in str(e):\n        model = GATsTSModel(optimizer='adam')\n        model.fit(dataset)\n    else:\n        raise","preventionTips":["Use 'gd', never 'sgd', across the qlib PyTorch contrib models.","Validate optimizer strings before long training jobs.","Maintain a shared allowlist constant for optimizer names in your experiment framework."],"tags":["pytorch","qlib","optimizer","config-validation","gats-ts"],"backgroundTag":null,"analyzedSha":"79633dd9506ea689e5400dea0197717b5b3d74b7","analyzedAt":"2026-08-15T07:01:27.511Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}