From 0bb90775539a5fc8b45c8e665f4ac213760c023d Mon Sep 17 00:00:00 2001 From: NanoCode012 Date: Thu, 19 Jun 2025 02:46:27 +0700 Subject: [PATCH] Fix: logging on py310 (#2802) * feat: encourage py311 * fix: logging import on py310 * fix: do upper and simplify handling --- docs/installation.qmd | 4 ++-- src/axolotl/logging_config.py | 20 ++++++++++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/docs/installation.qmd b/docs/installation.qmd index 15f2db57b..c905e93cd 100644 --- a/docs/installation.qmd +++ b/docs/installation.qmd @@ -14,7 +14,7 @@ This guide covers all the ways you can install and set up Axolotl for your envir ## Requirements {#sec-requirements} - NVIDIA GPU (Ampere architecture or newer for `bf16` and Flash Attention) or AMD GPU -- Python ≥3.10 +- Python ≥3.11 - PyTorch ≥2.5.1 ## Installation Methods {#sec-installation-methods} @@ -153,7 +153,7 @@ We recommend using WSL2 (Windows Subsystem for Linux) or Docker. ### Conda/Pip venv {#sec-conda} -1. Install Python ≥3.10 +1. Install Python ≥3.11 2. Install PyTorch: https://pytorch.org/get-started/locally/ 3. Install Axolotl: ```{.bash} diff --git a/src/axolotl/logging_config.py b/src/axolotl/logging_config.py index b8dc6479d..f570e013c 100644 --- a/src/axolotl/logging_config.py +++ b/src/axolotl/logging_config.py @@ -25,12 +25,20 @@ class AxolotlOrWarnErrorFilter(logging.Filter): def __init__(self, **kwargs): super().__init__(**kwargs) - self.axolotl_level = logging.getLevelNamesMapping()[ - os.getenv("AXOLOTL_LOG_LEVEL", DEFAULT_AXOLOTL_LOG_LEVEL) - ] - self.other_level = logging.getLevelNamesMapping()[ - os.getenv("LOG_LEVEL", DEFAULT_LOG_LEVEL) - ] + axolotl_log_level = os.getenv( + "AXOLOTL_LOG_LEVEL", DEFAULT_AXOLOTL_LOG_LEVEL + ).upper() + other_log_level = os.getenv("LOG_LEVEL", DEFAULT_LOG_LEVEL).upper() + + try: + # py311+ only + level_mapping = logging.getLevelNamesMapping() + self.axolotl_level = level_mapping[axolotl_log_level] + self.other_level = level_mapping[other_log_level] + except AttributeError: + # For py310, use getLevelName directly + self.axolotl_level = logging.getLevelName(axolotl_log_level) + self.other_level = logging.getLevelName(other_log_level) def filter(self, record: LogRecord) -> bool: # General filter