-
-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Fix broken wandb import crashing unsloth startup #4147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -1290,6 +1290,38 @@ def disable_torchcodec_if_broken(): | |||||
| pass | ||||||
|
|
||||||
|
|
||||||
| def disable_broken_wandb(): | ||||||
| """Disable wandb if it's installed but cannot actually import. | ||||||
|
|
||||||
| wandb can fail to import when there's a protobuf version mismatch | ||||||
| (e.g., wandb < 0.19.11 with protobuf >= 6.0). This causes a cascading | ||||||
| import failure through trl -> transformers -> wandb that crashes | ||||||
| unsloth's import chain. | ||||||
|
|
||||||
| This function tests if wandb can actually import and if not, patches | ||||||
| transformers' is_wandb_available() to return False. | ||||||
| """ | ||||||
| if importlib.util.find_spec("wandb") is None: | ||||||
| return # wandb not installed, nothing to do | ||||||
|
|
||||||
| try: | ||||||
| import wandb | ||||||
| except Exception: | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using a broad
Suggested change
|
||||||
| # wandb is installed but broken - patch transformers to skip it | ||||||
| logger.info( | ||||||
| "Unsloth: wandb is installed but broken (likely a protobuf version mismatch). " | ||||||
| "Disabling wandb to prevent import errors. To fix, run: pip install --upgrade wandb" | ||||||
| ) | ||||||
| try: | ||||||
| import transformers.integrations.integration_utils as tf_integration | ||||||
|
|
||||||
| tf_integration.is_wandb_available = lambda: False | ||||||
| except (ImportError, AttributeError): | ||||||
| pass | ||||||
| # Also set env var as fallback for any other code path | ||||||
| os.environ["WANDB_DISABLED"] = "true" | ||||||
|
|
||||||
|
|
||||||
| CAUSAL_CONV1D_BROKEN = False | ||||||
| _CAUSAL_CONV1D_PREFIX = "causal_conv1d" | ||||||
| _CAUSAL_CONV1D_BLOCKER_SENTINEL = "_unsloth_causal_conv1d_blocker" | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
disable_broken_wandb()is executed afterpatch_enable_input_require_grads(), but that earlier patch unconditionally doesfrom transformers import PreTrainedModel(unsloth/import_fixes.py), so on environments where importing transformers already touches wandb (the failure mode this commit targets), startup can still crash before the new guard runs. Moving the guard earlier in the init sequence is necessary to make the workaround effective for those installs.Useful? React with 👍 / 👎.