Utilities
Controlling the logging of huggingface_hub
The huggingface_hub
package exposes a logging
utility to control the logging level of the package itself.
You can import it as such:
from huggingface_hub import logging
Then, you may define the verbosity in order to update the amount of logs you’ll see:
from huggingface_hub import logging
logging.set_verbosity_error()
logging.set_verbosity_warning()
logging.set_verbosity_info()
logging.set_verbosity_debug()
logging.set_verbosity(...)
The levels should be understood as follows:
error
: only show critical logs about usage which may result in an error or unexpected behavior.warning
: show logs that aren’t critical but usage may result in unintended behavior. Additionally, important informative logs may be shown.info
: show most logs, including some verbose logging regarding what is happening under the hood. If something is behaving in an unexpected manner, we recommend switching the verbosity level to this in order to get more information.debug
: show all logs, including some internal logs which may be used to track exactly what’s happening under the hood.
Return the current level for the HuggingFace Hub’s root logger.
HuggingFace Hub has following logging levels:
huggingface_hub.logging.CRITICAL
,huggingface_hub.logging.FATAL
huggingface_hub.logging.ERROR
huggingface_hub.logging.WARNING
,huggingface_hub.logging.WARN
huggingface_hub.logging.INFO
huggingface_hub.logging.DEBUG
huggingface_hub.utils.logging.set_verbosity
< source >( verbosity: int )
Sets the level for the HuggingFace Hub’s root logger.
Sets the verbosity to logging.INFO
.
Sets the verbosity to logging.DEBUG
.
Sets the verbosity to logging.WARNING
.
Sets the verbosity to logging.ERROR
.
Disable propagation of the library log outputs. Note that log propagation is disabled by default.
Enable propagation of the library log outputs. Please disable the HuggingFace Hub’s default handler to prevent double logging if the root logger has been configured.
Repo-specific helper methods
The methods exposed below are relevant when modifying modules from the huggingface_hub
library itself.
Using these shouldn’t be necessary if you use huggingface_hub
and you don’t modify them.
huggingface_hub.utils.logging.get_logger
< source >( name: typing.Optional[str] = None )
Returns a logger with the specified name. This function is not supposed to be directly accessed by library users.
Custom errors
See below for all custom errors thrown by different methods across the package.
Raised when trying to access a hf.co URL with an invalid repository name, or with a private repo name the user does not have access to.
Raised when trying to access a hf.co URL with a valid repository but an invalid revision.
Raised when trying to access a hf.co URL with a valid repository and revision but an invalid filename.
Raised when trying to access a file that is not on the disk when network is disabled or unavailable (connection issue). The entry may exist on the Hub.
Note: ValueError
type is to ensure backward compatibility.
Note: LocalEntryNotFoundError
derives from HTTPError
because of EntryNotFoundError
even when it is not a network issue.
Example:
>>> from huggingface_hub import hf_hub_download
>>> hf_hub_download('bert-base-cased', '<non-cached-file>', local_files_only=True)
huggingface_hub.utils._errors.LocalEntryNotFoundError: Cannot find the requested files in the disk cache and outgoing traffic has been disabled. To enable hf.co look-ups and downloads online, set 'local_files_only' to False.