{"record":{"id":"98d177a27c915a8e","repo":"unslothai/unsloth","slug":"error-msg-dynamic-from-format-error-message-e","errorCode":null,"errorMessage":"{error_msg} (dynamic, from format_error_message: e.g. \"Model '{model_short}' not found. Check the model name.\", \"Not enough {device_label} memory to load '{model_short}'. Try a smaller model or free memory.\", or str(error))","messagePattern":"(.+?) \\(dynamic, from format_error_message: e\\.g\\. \"Model '(.+?)' not found\\. Check the model name\\.\", \"Not enough (.+?) memory to load '(.+?)'\\. Try a smaller model or free memory\\.\", or str\\(error\\)\\)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"studio/backend/core/inference/inference.py","lineNumber":698,"sourceCode":"            self._load_chat_template_info(model_name)\n\n            self.active_model_name = model_name\n            self.loading_models.discard(model_name)\n\n            logger.info(f\"Successfully loaded model: {model_name}\")\n            log_gpu_memory(f\"After loading {model_name}\")\n            return True\n\n        except Exception as e:\n            logger.error(f\"Failed to load model: {e}\")\n            error_msg = format_error_message(e, config.identifier)\n\n            # Cleanup on failure\n            if model_name in self.models:\n                del self.models[model_name]\n            self.loading_models.discard(model_name)\n\n            raise Exception(error_msg)\n\n    def unload_model(self, model_name: str) -> bool:\n        \"\"\"Remove a model from the registry and clear GPU memory.\"\"\"\n        if model_name in self.models:\n            try:\n                # Clean up codecs for audio models\n                if self.models[model_name].get(\"is_audio\"):\n                    self._audio_codec_manager.unload()\n\n                logger.info(f\"Unloading model '{model_name}' from memory.\")\n                del self.models[model_name]\n\n                # Clear the active model if it was the one unloaded\n                if self.active_model_name == model_name:\n                    self.active_model_name = None\n\n                clear_gpu_cache()\n","sourceCodeStart":680,"sourceCodeEnd":716,"githubUrl":"https://github.com/unslothai/unsloth/blob/203007d19051dcd2ae33876786d117c99f6b0368/studio/backend/core/inference/inference.py#L680-L716","documentation":"The inference engine's model-load path wraps any exception during load_model and re-raises it as a generic Exception whose message comes from format_error_message(e, config.identifier). That helper maps common failures to friendly text — 'Model X not found. Check the model name.', 'Not enough {device} memory to load X...' — and falls back to str(error) otherwise. Because it raises bare Exception (not a specific type), callers cannot catch selectively by type.","triggerScenarios":"load_model failing on: a nonexistent or mistyped model id, insufficient GPU/VRAM (or unified memory) for the weights, missing files on disk, architecture incompatibility, or dependency errors — anything in the load path including transformers/from_pretrained failures.","commonSituations":"Model id typos; picking a model too large for the GPU; interrupted downloads leaving corrupt snapshots; mismatched transformers version for the model architecture; GGUF/diffusers dependency missing.","solutions":["Match the message: 'not found' → fix the model id; 'Not enough memory' → pick a smaller model/quantization or free VRAM","For other messages, the raw str(error) is included — act on that underlying text","Free GPU memory (unload other models) or upgrade hardware/quantization","Verify the model snapshot is complete (re-download if the cache is corrupt)"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"# Validate before loading\nfrom huggingface_hub import model_info\n\ndef model_exists(model_id: str) -> bool:\n    try:\n        model_info(model_id)\n        return True\n    except Exception:\n        return False","typeGuard":null,"tryCatchPattern":"try:\n    engine.load_model(name)\nexcept Exception as e:\n    msg = str(e)\n    if \"not found\" in msg:\n        surface(\"unknown model\", 404)\n    elif \"Not enough\" in msg and \"memory\" in msg:\n        surface(\"insufficient memory — try a smaller model\", 507)\n    else:\n        surface(msg, 500)","preventionTips":["Because it raises bare Exception, catch broadly and branch on message text","Free VRAM (unload unused models) before loading new ones","Pre-verify model ids exist and the cache snapshot is complete"],"tags":["model-loading","memory","huggingface","generic-wrapper"],"backgroundTag":null,"analyzedSha":"203007d19051dcd2ae33876786d117c99f6b0368","analyzedAt":"2026-08-15T02:48:39.846Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}