""" _quiet.py --------- Silences the noisy tqdm / verbose logging that floods notebook output when `!python -m ...` is run in a non-TTY subprocess (Kaggle / Colab). Import this module at the **very top** of train.py / evaluate.py, *before* any `transformers` / `huggingface_hub` / `bitsandbytes` import, because those libraries read these env vars once at import time. We do not suppress tqdm globally — HF Trainer's training-loop progress is useful. We only kill: • HF Hub per-shard download bars (the `pytorch_model-00001-of-00002.bin` spam you see during first model load). • transformers' info-level logging. • bitsandbytes welcome banner. • HF tokenizers' multiprocessing fork warning. """ import os # ── env vars read at import time by downstream libs ────────────────────── os.environ.setdefault("HF_HUB_DISABLE_PROGRESS_BARS", "1") os.environ.setdefault("TRANSFORMERS_VERBOSITY", "warning") os.environ.setdefault("TOKENIZERS_PARALLELISM", "false") os.environ.setdefault("BITSANDBYTES_NOWELCOME", "1") os.environ.setdefault("PYTHONUNBUFFERED", "1") # ── httpx 0.28+ compat patch (must apply BEFORE transformers imports) ──── # transformers ≤4.50 calls httpx.Client.head(allow_redirects=...) which # httpx 0.28 removed. The shim translates kwarg → follow_redirects. from . import _httpx_compat # noqa: F401 # ── torch 2.6+ compat patch (must apply BEFORE Trainer.train() resumes) ── # torch 2.6 made `torch.load(..., weights_only=True)` the default; the # rng_state.pth that transformers ≤4.50 loads during resume contains numpy # objects and trips the safe unpickler. Restore the legacy default. from . import _torch_load_compat # noqa: F401 # ── programmatic disable (belt-and-braces) ─────────────────────────────── try: from huggingface_hub.utils import disable_progress_bars disable_progress_bars() except Exception: pass try: import transformers transformers.logging.set_verbosity_warning() transformers.logging.disable_progress_bar() except Exception: pass