{"record":{"id":"37749ab05b302fac","repo":"docling-project/docling","slug":"model-not-loaded-ensure-enginemodelconfig-was-pro-37749a","errorCode":null,"errorMessage":"Model not loaded. Ensure EngineModelConfig was provided during initialization.","messagePattern":"Model not loaded\\. Ensure EngineModelConfig was provided during initialization\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"docling/models/inference_engines/vlm/transformers_engine.py","lineNumber":319,"sourceCode":"\n        This method processes multiple images in a single forward pass,\n        which is much more efficient than processing them sequentially.\n\n        Args:\n            input_batch: List of inputs to process\n\n        Returns:\n            List of outputs, one per input\n        \"\"\"\n        if not self._initialized:\n            self.initialize()\n\n        if not input_batch:\n            return []\n\n        # Model should already be loaded via initialize()\n        if self.vlm_model is None or self.processor is None:\n            raise RuntimeError(\n                \"Model not loaded. Ensure EngineModelConfig was provided during initialization.\"\n            )\n\n        # Get prompt style from first input's extra config\n        first_input = input_batch[0]\n        prompt_style = first_input.extra_generation_config.get(\n            \"transformers_prompt_style\",\n            TransformersPromptStyle.CHAT,\n        )\n\n        # Prepare images using shared utility\n        images = preprocess_image_batch([inp.image for inp in input_batch])\n\n        # Prepare prompts\n        prompts = []\n        for input_data in input_batch:\n            # Format prompt\n            if prompt_style == TransformersPromptStyle.CHAT:","sourceCodeStart":301,"sourceCodeEnd":337,"githubUrl":"https://github.com/docling-project/docling/blob/61d76f1ff3f8428065465889f7b4577da7df704c/docling/models/inference_engines/vlm/transformers_engine.py#L301-L337","documentation":"TransformersVlmEngine.predict_batch() verifies that initialize() loaded a vlm_model and processor. Those are only set when a model_config with a repo_id was provided at construction; without one, initialize() completes but no weights are in memory and this RuntimeError is raised on the first non-empty batch.","triggerScenarios":"Building TransformersVlmEngine without model_config (or with repo_id None) via create_vlm_engine(model_spec=None), then calling predict_batch with at least one VlmEngineInput.","commonSituations":"Options-only pipelines where the model spec was never wired in; assuming a default model is auto-selected; passing model_spec=None to try to 'configure later'.","solutions":["Pass an EngineModelConfig with repo_id (or a VlmModelSpec through create_vlm_engine) so initialize() downloads and loads weights","Assert model_config and model_config.repo_id are set right after engine construction, before the first batch","Do not rely on a default: the Transformers engine has no bundled model"],"exampleFix":"# before\nengine = TransformersVlmEngine(options=TransformersVlmEngineOptions())\noutputs = engine.predict_batch(inputs)  # RuntimeError\n\n# after\nengine = TransformersVlmEngine(\n    options=TransformersVlmEngineOptions(),\n    model_config=EngineModelConfig(repo_id='ds4sd/SmolDocling-256M-preview'),\n)\noutputs = engine.predict_batch(inputs)","handlingStrategy":"validation","validationCode":"engine = TransformersVlmEngine(options=opts, model_config=model_config, artifacts_path=None, accelerator_options=acc)\nassert model_config is not None and model_config.repo_id, 'Transformers engine requires EngineModelConfig.repo_id'\nengine.initialize()\nassert engine.vlm_model is not None and engine.processor is not None","typeGuard":null,"tryCatchPattern":"try:\n    outputs = engine.predict_batch(inputs)\nexcept RuntimeError as e:\n    if 'Model not loaded' in str(e):\n        raise SystemExit('Attach an EngineModelConfig(repo_id=...) to the Transformers engine before inference') from e\n    raise","preventionTips":["Never construct TransformersVlmEngine without a model_config containing repo_id","Call initialize() eagerly and assert the model/processor attributes are populated","Wire model specs through create_vlm_engine so the factory attaches model_config for you"],"tags":["vlm","transformers","configuration","model-not-loaded","runtime-error"],"backgroundTag":null,"analyzedSha":"61d76f1ff3f8428065465889f7b4577da7df704c","analyzedAt":"2026-08-14T23:53:18.727Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}