NameError: '_should_use_gpt_oss_bnb4bit' is not defined due to function definition ordering in gpt_oss.py
Environment
unsloth==2026.3.11
unsloth_zoo==2026.3.5
- Python 3.12
- PyTorch with CUDA
Bug Description
In unsloth_zoo/temporary_patches/gpt_oss.py, patch_gpt_oss_bnb4bit_auto is registered to TEMPORARY_PATCHES at line 1132, but the function _should_use_gpt_oss_bnb4bit() that it calls internally is defined much later at line 1351.
Between these two lines (~220 lines of module-level code), there are runtime statements that can fail:
# line 1132 - function reference registered
TEMPORARY_PATCHES.append(patch_gpt_oss_bnb4bit_auto)
# line 1141 - module-level CUDA call (can fail: OOM, no GPU context, etc.)
device_memory = torch.cuda.memory.mem_get_info(0)[-1]
# ... ~200 lines of module-level code ...
# line 1336 - module-level import
from .moe_utils import (...)
# line 1351 - never reached if anything above fails
def _should_use_gpt_oss_bnb4bit() -> bool:
...
NameError: '_should_use_gpt_oss_bnb4bit' is not defineddue to function definition ordering ingpt_oss.pyEnvironment
unsloth==2026.3.11unsloth_zoo==2026.3.5Bug Description
In
unsloth_zoo/temporary_patches/gpt_oss.py,patch_gpt_oss_bnb4bit_autois registered toTEMPORARY_PATCHESat line 1132, but the function_should_use_gpt_oss_bnb4bit()that it calls internally is defined much later at line 1351.Between these two lines (~220 lines of module-level code), there are runtime statements that can fail: