{"record":{"id":"9e0d4d8eb99f3ec4","repo":"unslothai/unsloth","slug":"no-active-model","errorCode":null,"errorMessage":"No active model","messagePattern":"No active model","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"studio/backend/core/inference/inference.py","lineNumber":1112,"sourceCode":"        max_new_tokens: int = 256,\n        repetition_penalty: float = 1.0,\n        cancel_event = None,\n        _adapter_state = None,\n        tools: Optional[list] = None,\n        enable_thinking: Optional[bool] = None,\n        reasoning_effort: Optional[str] = None,\n        preserve_thinking: Optional[bool] = None,\n        continue_final_message: bool = False,\n        presence_penalty: float = 0.0,\n    ) -> Generator[str, None, None]:\n        \"\"\"Inner generation logic, called by generate_chat_response and\n        generate_with_adapter_control.\n\n        _adapter_state is passed to generate_stream/vision so the background\n        thread can toggle adapters under the generation lock.\n        \"\"\"\n        if not self.active_model_name:\n            raise RuntimeError(\"No active model\")\n\n        model_info = self.models[self.active_model_name]\n        is_vision = model_info.get(\"is_vision\", False)\n        tokenizer = model_info.get(\"tokenizer\") or model_info.get(\"processor\")\n        # Unwrap processor -> raw tokenizer for VLMs on the text path.\n        tokenizer = getattr(tokenizer, \"tokenizer\", tokenizer)\n        top_k = self._normalize_top_k(top_k)\n\n        if is_vision and image:\n            # Verify the stored processor can handle images; FastVisionModel may\n            # return a raw tokenizer instead of a ProcessorMixin (e.g. Gemma-3).\n            from transformers import ProcessorMixin\n\n            processor = model_info.get(\"processor\")\n            has_image_processing = processor is not None and (\n                isinstance(processor, ProcessorMixin) or hasattr(processor, \"image_processor\")\n            )\n            if has_image_processing:","sourceCodeStart":1094,"sourceCodeEnd":1130,"githubUrl":"https://github.com/unslothai/unsloth/blob/203007d19051dcd2ae33876786d117c99f6b0368/studio/backend/core/inference/inference.py#L1094-L1130","documentation":"The inner chat-generation routine raises RuntimeError('No active model') when self.active_model_name is falsy — i.e. no model has been loaded/activated on the engine before generation is attempted. Every generation path dereferences self.models[self.active_model_name], so the guard prevents a KeyError and gives a clear message.","triggerScenarios":"Calling generate_chat_response / generate_stream before any load_model succeeded, after unload_model cleared the active model, or after a failed load left active_model_name unset.","commonSituations":"Service restart losing loaded state while a queued request arrives; frontend allows sending chat before load completes; a previous load failed and the client ignored the error and sent a generation anyway.","solutions":["Load and activate a model first (await the load endpoint) before sending generation requests","If a load failed, address that failure (see load error) and retry the load","On the client, gate the send button on the engine's 'model loaded' state"],"exampleFix":"// before\nfor tok in engine._generate(...): ...  # no model loaded\n// after\nengine.load_model(\"qwen2.5-7b-instruct\")\nfor tok in engine._generate(...): ...","handlingStrategy":"type-guard","validationCode":"if not getattr(engine, \"active_model_name\", None):\n    raise HTTPException(409, \"No model is loaded — load one before generating\")","typeGuard":"def has_active_model(engine) -> bool:\n    return bool(getattr(engine, \"active_model_name\", None)) and engine.active_model_name in engine.models","tryCatchPattern":"try:\n    yield from engine._generate(...)\nexcept RuntimeError as e:\n    if str(e) == \"No active model\":\n        return JSONResponse(status_code=409, content={\"detail\": \"Load a model first\"})\n    raise","preventionTips":["Gate every generation call on active_model_name being set","Wait for the load endpoint to report success before allowing send","After unload, clear client-side 'ready' state"],"tags":["state","model-loading","chat","guard"],"backgroundTag":null,"analyzedSha":"203007d19051dcd2ae33876786d117c99f6b0368","analyzedAt":"2026-08-15T02:48:39.846Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}