unsloth/unsloth
Daniel Han 52e0358569 Fix broken wandb import crashing unsloth startup (#4147)
* Fix broken wandb import crashing unsloth startup

When wandb is installed but broken (e.g., wandb < 0.19.11 with
protobuf >= 6.0), the import chain unsloth -> trl -> transformers ->
is_wandb_available() -> import wandb crashes with:

  ImportError: cannot import name 'Imports' from
  'wandb.proto.wandb_telemetry_pb2'

This happens because transformers' is_wandb_available() has no
try/except around `import wandb`. The error propagates up and kills
`from unsloth import FastLanguageModel` even though wandb is optional.

Add disable_broken_wandb() following the same pattern as
disable_torchcodec_if_broken(). It proactively tries importing wandb
during early init, and if the import fails, patches
is_wandb_available() to return False and sets WANDB_DISABLED=true.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2026-03-03 07:08:12 -08:00
..
dataprep Guard optional vLLM imports when extension is broken (#4068) 2026-02-15 22:09:29 -08:00
kernels fix(ROCm): restrict is_rdna() to ROCm-officially-supported RDNA GPUs (#4136) 2026-03-03 03:05:38 -08:00
models Fixup mapper issues and resolve properly (#4124) 2026-03-03 06:57:25 -08:00
registry Revert "[pre-commit.ci] auto fixes from pre-commit.com hooks" 2025-12-01 07:24:58 -08:00
utils Fix/pr 3699 leftpad prefill main (#4100) 2026-02-25 07:21:04 -08:00
__init__.py Fix broken wandb import crashing unsloth startup (#4147) 2026-03-03 07:08:12 -08:00
_auto_install.py Add PyTorch 2.10 and xformers 0.0.34 support (#3985) 2026-02-05 05:56:26 -08:00
chat_templates.py Fix regressions from security PRs #4042, #4044, and #4045 (#4062) 2026-02-15 23:16:17 -08:00
device_type.py Add missing import of inspect (#3778) 2025-12-25 18:43:59 -08:00
import_fixes.py Fix broken wandb import crashing unsloth startup (#4147) 2026-03-03 07:08:12 -08:00
ollama_template_mappers.py Refactor Ollama template wiring and harden packing helpers (#3890) 2026-02-09 04:04:48 -08:00
save.py fix: update GGUF save paths to use ~/.unsloth/llama.cpp with Windows support (#4138) 2026-03-03 06:34:09 -08:00
tokenizer_utils.py Add resilience to TRL internal API reclassification (#4111) 2026-02-25 06:34:21 -08:00
trainer.py Fix auto padding free logic to respect user passed False (#4128) 2026-03-01 19:30:47 -08:00