class ModelNotFoundError(Exception): """Error raised when a model cannot be found or accessed""" def __init__(self, model_name: str, original_error: Exception = None): self.model_name = model_name self.original_error = original_error message = ( f"Could not find or access model: '{model_name}'\n\n" f"This could be because:\n" f"1. The model name is misspelled - double check the name\n" f"2. The model requires authentication - you need to:\n" f" - Log in to Hugging Face (huggingface.co)\n" f" - Accept the model's terms of use on its page\n" f" - Create an access token in your HF account settings\n" f" - Set the token as an environment variable: export HUGGING_FACE_HUB_TOKEN=your_token\n\n" f"Original error: {str(original_error)}" ) super().__init__(message) class ModelLoadError(Exception): """Error raised when a model fails to load""" def __init__(self, model_name: str, load_type: str, original_error: Exception = None): self.model_name = model_name self.load_type = load_type self.original_error = original_error message = ( f"Failed to load model: '{model_name}' using {load_type} precision\n\n" f"Common reasons:\n" f"1. Not enough GPU memory - This model requires more VRAM than available\n" f" - Try using 8-bit quantization (load_in_8bit=True)\n" f" - Try using 4-bit quantization (load_in_4bit=True)\n" f" - Or use a smaller model\n" f"2. Incorrect model parameters - Check the model card for correct loading parameters\n" f"3. Corrupted model files - Try removing the model folder and downloading again\n\n" f"Original error: {str(original_error)}" ) super().__init__(message) class InvalidConfigurationError(Exception): """Error raised when configuration is invalid""" def __init__(self, param_name: str, current_value: any, expected_value: str, original_error: Exception = None): self.param_name = param_name self.current_value = current_value self.expected_value = expected_value self.original_error = original_error message = ( f"Invalid configuration parameter: '{param_name}'\n\n" f"Current value: {current_value}\n" f"Expected value: {expected_value}\n\n" f"Please update your config.yaml file with the correct value\n" f"Original error: {str(original_error)}" ) super().__init__(message) class GenerationError(Exception): """Error raised when text generation fails""" def __init__(self, stage: str, original_error: Exception = None): self.stage = stage self.original_error = original_error message = ( f"Text generation failed during {stage}\n\n" f"This could be because:\n" f"1. The model ran out of memory during generation\n" f" - Try reducing max_new_tokens\n" f" - Try reducing the input text length\n" f"2. The input prompt might be too complex or long\n" f"3. The model might be in an inconsistent state\n" f" - Try reinitializing the model\n\n" f"Original error: {str(original_error)}" ) super().__init__(message) # Usage examples: """ # When model not found: raise ModelNotFoundError("mistralai/Mistral-7B-v0.1", original_error=e) # When model fails to load: raise ModelLoadError("mistralai/Mistral-7B-v0.1", "8-bit quantization", original_error=e) # When config is invalid: raise InvalidConfigurationError( "temperature", 2.5, "a value between 0.0 and 2.0", original_error=e ) # When generation fails: raise GenerationError("token generation", original_error=e) """