microsoft/qlib · error · ValueError

unknown base model name `%s`

Error message

unknown base model name `%s`

What it means

In fit(), GATsTSModel instantiates a pretrained base RNN for warm-starting and accepts only exact-case 'LSTM' and 'GRU' for self.base_model; anything else raises ValueError before loading pretrained weights. The comparison is case-sensitive, matching the non-ts GATs behavior.

Source

Thrown at qlib/contrib/model/pytorch_gats_ts.py:268

        train_loader = DataLoader(dl_train, sampler=sampler_train, num_workers=self.n_jobs, drop_last=True)
        valid_loader = DataLoader(dl_valid, sampler=sampler_valid, num_workers=self.n_jobs, drop_last=True)

        save_path = get_or_create_path(save_path)

        stop_steps = 0
        train_loss = 0
        best_score = -np.inf
        best_epoch = 0
        evals_result["train"] = []
        evals_result["valid"] = []

        # load pretrained base_model
        if self.base_model == "LSTM":
            pretrained_model = LSTMModel(d_feat=self.d_feat, hidden_size=self.hidden_size, num_layers=self.num_layers)
        elif self.base_model == "GRU":
            pretrained_model = GRUModel(d_feat=self.d_feat, hidden_size=self.hidden_size, num_layers=self.num_layers)
        else:
            raise ValueError("unknown base model name `%s`" % self.base_model)

        if self.model_path is not None:
            self.logger.info("Loading pretrained model...")
            pretrained_model.load_state_dict(torch.load(self.model_path, map_location=self.device))

        model_dict = self.GAT_model.state_dict()
        pretrained_dict = {
            k: v for k, v in pretrained_model.state_dict().items() if k in model_dict  # pylint: disable=E1135
        }
        model_dict.update(pretrained_dict)
        self.GAT_model.load_state_dict(model_dict)
        self.logger.info("Loading pretrained model Done...")

        # train
        self.logger.info("training...")
        self.fitted = True

        for step in range(self.n_epochs):

View on GitHub (pinned to 79633dd950)

Solutions

  1. Use exact 'LSTM' or 'GRU'.
  2. Fix case and typos in the base_model config value.
  3. Subclass GATsTSModel.fit to construct a custom pretrained base model.

Example fix

# before
model = GATsTSModel(base_model='gru')

# after
model = GATsTSModel(base_model='GRU')
Defensive patterns

Strategy: validation

Validate before calling

assert model.base_model in ('LSTM', 'GRU'), f"base_model must be exactly 'LSTM' or 'GRU', got {model.base_model!r}"

Type guard

def is_valid_base_model(name: str) -> bool:
    return name in ('LSTM', 'GRU')

Try / catch

try:
    model.fit(dataset)
except ValueError as e:
    if 'unknown base model name' in str(e):
        model.base_model = model.base_model.upper()
        model.fit(dataset)
    else:
        raise

Prevention

When it happens

Trigger: GATsTSModel(base_model='gru') or any non-exact string followed by fit().

Common situations: Lowercase values in YAML configs; porting base_model settings between models; using names of custom base networks not registered here.

Related errors


AI-assisted analysis of microsoft/qlib@79633dd950 (2026-08-15). Data as JSON: /api/errors/c29a207772046473. Report an issue: GitHub.