Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions unsloth/models/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -1046,6 +1046,14 @@ def from_pretrained(
# Set norms to float32 since anyways they get upcasted to float32
# common in both gemma-3 and gemma-3n
os.environ["UNSLOTH_HIGH_PRECISION_LAYERNORM"] = "1"
# ROCm: Gemma3 compiled forward produces NaN on RDNA GPUs (gfx11xx).
# Disable compilation; eager path is numerically correct.
# See https://github.com/unslothai/unsloth/issues/3385
if DEVICE_TYPE == "hip":
os.environ["UNSLOTH_COMPILE_DISABLE"] = "1"
import unsloth_zoo.compiler
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To improve code style and adhere to PEP 8, it's better to have imports at the top of the file. Please move this import to the top of unsloth/models/loader.py and remove it from here.


unsloth_zoo.compiler.UNSLOTH_COMPILE_DISABLE = True
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid persisting compile-disable globally after Gemma3 load

This assignment mutates a process-wide compiler flag and there is no corresponding reset path in FastLanguageModel.from_pretrained, so once a HIP Gemma3 load runs, later loads of other model families in the same Python process can inherit compile-disabled behavior unintentionally. That creates a silent cross-model regression (not just Gemma3) where subsequent calls into unsloth_compile_transformers may stay on eager paths and lose expected optimizations.

Useful? React with 👍 / 👎.

# Cohere
elif "cohere2" in model_types_all and transformers_version < Version(
"4.50.0.dev0"
Expand Down