File size: 2,200 Bytes
28b13fc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8356dae
 
 
 
 
c9b4129
 
 
 
 
 
28b13fc
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""
_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