[docs]classBaseError(Exception):"""Base class for all project-specific errors."""exit_code=1message="An error occurred."def__init__(self,*args):self.args=argsifargs:self.message=self.message.format(*args)self.handle()
[docs]defhandle(self):"""Prints the error message and exits with the specified code."""sys.stderr.write(f"Error: {self.message}\n")sys.exit(self.exit_code)
[docs]classCheckpointNotFoundError(BaseError):"""Raised when no checkpoint files are found."""exit_code=2message="No checkpoint files found in directory: {}."
[docs]classCheckpointDirectoryError(BaseError):"""Raised when the checkpoint directory is invalid or missing."""exit_code=3message="Checkpoint directory not found or invalid: {}."
[docs]classMultipleCheckpointsError(BaseError):"""Raised when multiple checkpoint files are found."""exit_code=4message="Multiple checkpoint files found in directory: {}. Expected exactly one."
[docs]classConfigId2LabelError(BaseError):"""Raised when the 'id2label' mapping is missing from the configuration or dataset."""exit_code=5message="'id2label' mapping is missing in config. Please provide it to ensure correct label mapping."
[docs]classNormalizeError(BaseError):"""Exception raised if normalize is not from valid options."""exit_code=6message="'normalize' must be 'max' | 'balance' | 'sum' got {}"
[docs]classLossWeightsTypeError(BaseError):"""Exception raised if 'weights' got wrong type."""exit_code=7message="'weights' need to be type tuple|np.ndarray|list|tensor got {}."
[docs]classLossWeightsSizeError(BaseError):"""Exception raised if weights size is not equal to num class."""exit_code=8message="'weights' size {}. != num_classes {}."
[docs]classLossIgnoreIndexError(BaseError):"""Exception raised if weights size is not equal to num class."""exit_code=9message="'ignore_index' {} is out of bounds for 'num_classes' {}."