microsoft/qlib · error · ValueError
Please give the search space of model.
Error message
Please give the search space of model.
What it means
QLibTuner.setup_space (qlib/contrib/tuner/tuner.py) requires the tuner config's 'model' section to name a search space class (key 'space'). That name is resolved via getattr on qlib.contrib.tuner.space, so a missing space key raises ValueError('Please give the search space of model.') before any tuning starts.
Source
Thrown at qlib/contrib/tuner/tuner.py:173
estimator_config["strategy"].update({"args": params["strategy_space"]})
if params.get("data_label_space", None) is not None:
estimator_config["data"]["args"].update(params["data_label_space"])
estimator_path = os.path.join(
self.tuner_config["experiment"].get("dir", "../"),
QLibTuner.ESTIMATOR_CONFIG_NAME,
)
with open(estimator_path, "w") as fp:
yaml.dump(estimator_config, fp)
return estimator_path
def setup_space(self):
# 1. Setup model space
model_space_name = self.tuner_config["model"].get("space", None)
if model_space_name is None:
raise ValueError("Please give the search space of model.")
model_space = getattr(
importlib.import_module(".space", package="qlib.contrib.tuner"),
model_space_name,
)
# 2. Setup strategy space
strategy_space_name = self.tuner_config["strategy"].get("space", None)
if strategy_space_name is None:
raise ValueError("Please give the search space of strategy.")
strategy_space = getattr(
importlib.import_module(".space", package="qlib.contrib.tuner"),
strategy_space_name,
)
# 3. Setup data label space if given
if self.tuner_config.get("data_label", None) is not None:
data_label_space_name = self.tuner_config["data_label"].get("space", None)
if data_label_space_name is not None:View on GitHub (pinned to 79633dd950)
Solutions
- Add a space key under model in the tuner YAML pointing to a class in qlib.contrib.tuner.space, e.g. model: {space: LGBModelSpace}
- Verify the named class exists in qlib/contrib/tuner/space.py (import errors surface as AttributeError next)
- Base your config on the shipped tuner examples (examples/tuner or benchmarks workflow tuner yaml)
Example fix
# before (tuner_config.yaml) model: class: LGBModel module_path: qlib.contrib.model.gbdt # after model: space: LGBModelSpace class: LGBModel module_path: qlib.contrib.model.gbdt
Defensive patterns
Strategy: validation
Validate before calling
model_space = cfg.get('model', {}).get('space')
assert model_space, 'tuner config model section needs a space: entry'
from qlib.contrib.tuner import space as tuner_space
assert hasattr(tuner_space, model_space), f'{model_space} not found in qlib.contrib.tuner.space' Prevention
- Base tuner configs on the shipped examples so model/strategy sections keep their space keys
- Pre-resolve every space name against qlib.contrib.tuner.space before constructing QLibTuner
When it happens
Trigger: A tuner YAML whose model section lacks the space key (model: {class: ..., module: ...} with no space:) triggers the error when QLibTuner.setup_space() runs at tuner initialization.
Common situations: Reusing a plain workflow/model config (which has no search space) as a tuner config; trimming the example tuner YAML too aggressively; the space class name given also needs to exist in qlib/contrib/tuner/space.py or AttributeError follows.
Related errors
- Please give the search space of strategy.
- Config path is invalid.
- report_type should be one of pred_long, pred_long_short, pre
- report_factor should be one of annualized_return, informatio
- optim_type should be min, max or correlation
AI-assisted analysis of microsoft/qlib@79633dd950 (2026-08-15).
Data as JSON: /api/errors/7d7f3e9c7c0e0578.
Report an issue: GitHub.