Skip to content

NameError: '_should_use_gpt_oss_bnb4bit' is not defined due to function definition ordering in gpt_oss.py #581

@HwangHanJae

Description

@HwangHanJae

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:
    ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions