CoolFace
Modelpublic

hymenjj/llama-cpp-python-prebuilt

sourceHugging Faceupdated 7mo agoView on Hugging Face
0likes
_logger.py48 linesDownload Raw Back to llama_cpp
1import sys2import ctypes3import logging4 5import llama_cpp6 7# enum ggml_log_level {8#     GGML_LOG_LEVEL_NONE  = 0,9#     GGML_LOG_LEVEL_INFO  = 1,10#     GGML_LOG_LEVEL_WARN  = 2,11#     GGML_LOG_LEVEL_ERROR = 3,12#     GGML_LOG_LEVEL_DEBUG = 4,13#     GGML_LOG_LEVEL_CONT  = 5, // continue previous log14# };15GGML_LOG_LEVEL_TO_LOGGING_LEVEL = {16    0: logging.CRITICAL,17    1: logging.INFO,18    2: logging.WARNING,19    3: logging.ERROR,20    4: logging.DEBUG,21    5: logging.DEBUG,22}23 24logger = logging.getLogger("llama-cpp-python")25 26_last_log_level = GGML_LOG_LEVEL_TO_LOGGING_LEVEL[0]27 28# typedef void (*ggml_log_callback)(enum ggml_log_level level, const char * text, void * user_data);29@llama_cpp.llama_log_callback30def llama_log_callback(31    level: int,32    text: bytes,33    user_data: ctypes.c_void_p,34):35    # TODO: Correctly implement continue previous log36    global _last_log_level37    log_level = GGML_LOG_LEVEL_TO_LOGGING_LEVEL[level] if level != 5 else _last_log_level38    if logger.level <= GGML_LOG_LEVEL_TO_LOGGING_LEVEL[level]:39        print(text.decode("utf-8"), end="", flush=True, file=sys.stderr)40    _last_log_level = log_level41 42 43llama_cpp.llama_log_set(llama_log_callback, ctypes.c_void_p(0))44 45 46def set_verbose(verbose: bool):47    logger.setLevel(logging.DEBUG if verbose else logging.ERROR)48