{"record":{"id":"7d7f3e9c7c0e0578","repo":"microsoft/qlib","slug":"please-give-the-search-space-of-model","errorCode":null,"errorMessage":"Please give the search space of model.","messagePattern":"Please give the search space of model\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"qlib/contrib/tuner/tuner.py","lineNumber":173,"sourceCode":"        estimator_config[\"strategy\"].update({\"args\": params[\"strategy_space\"]})\n        if params.get(\"data_label_space\", None) is not None:\n            estimator_config[\"data\"][\"args\"].update(params[\"data_label_space\"])\n\n        estimator_path = os.path.join(\n            self.tuner_config[\"experiment\"].get(\"dir\", \"../\"),\n            QLibTuner.ESTIMATOR_CONFIG_NAME,\n        )\n\n        with open(estimator_path, \"w\") as fp:\n            yaml.dump(estimator_config, fp)\n\n        return estimator_path\n\n    def setup_space(self):\n        # 1. Setup model space\n        model_space_name = self.tuner_config[\"model\"].get(\"space\", None)\n        if model_space_name is None:\n            raise ValueError(\"Please give the search space of model.\")\n        model_space = getattr(\n            importlib.import_module(\".space\", package=\"qlib.contrib.tuner\"),\n            model_space_name,\n        )\n\n        # 2. Setup strategy space\n        strategy_space_name = self.tuner_config[\"strategy\"].get(\"space\", None)\n        if strategy_space_name is None:\n            raise ValueError(\"Please give the search space of strategy.\")\n        strategy_space = getattr(\n            importlib.import_module(\".space\", package=\"qlib.contrib.tuner\"),\n            strategy_space_name,\n        )\n\n        # 3. Setup data label space if given\n        if self.tuner_config.get(\"data_label\", None) is not None:\n            data_label_space_name = self.tuner_config[\"data_label\"].get(\"space\", None)\n            if data_label_space_name is not None:","sourceCodeStart":155,"sourceCodeEnd":191,"githubUrl":"https://github.com/microsoft/qlib/blob/79633dd9506ea689e5400dea0197717b5b3d74b7/qlib/contrib/tuner/tuner.py#L155-L191","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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)"],"exampleFix":"# before (tuner_config.yaml)\nmodel:\n  class: LGBModel\n  module_path: qlib.contrib.model.gbdt\n\n# after\nmodel:\n  space: LGBModelSpace\n  class: LGBModel\n  module_path: qlib.contrib.model.gbdt","handlingStrategy":"validation","validationCode":"model_space = cfg.get('model', {}).get('space')\nassert model_space, 'tuner config model section needs a space: entry'\nfrom qlib.contrib.tuner import space as tuner_space\nassert hasattr(tuner_space, model_space), f'{model_space} not found in qlib.contrib.tuner.space'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["qlib","tuner","configuration","search-space"],"backgroundTag":null,"analyzedSha":"79633dd9506ea689e5400dea0197717b5b3d74b7","analyzedAt":"2026-08-15T07:01:27.511Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}