Skip to content

Fix missing ParameterModule export in GPT-OSS compiler path#519

Open
danielhanchen wants to merge 7 commits intomainfrom
fix/gpt-oss-parametermodule-compiler-export
Open

Fix missing ParameterModule export in GPT-OSS compiler path#519
danielhanchen wants to merge 7 commits intomainfrom
fix/gpt-oss-parametermodule-compiler-export

Conversation

@danielhanchen
Copy link
Copy Markdown
Contributor

@danielhanchen danielhanchen commented Feb 25, 2026

Summary

Fixes GPT-OSS compiled-cache failures where generated modules can reference ParameterModule but the symbol is not available from transformers.models.gpt_oss.modeling_gpt_oss.

Root cause

ParameterModule is defined in unsloth_zoo.temporary_patches.gpt_oss, but compiler-generated code expects symbols to be resolvable from the GPT-OSS modeling namespace.

Changes

  • Added patch_gpt_oss_compiler_exports() in unsloth_zoo/temporary_patches/gpt_oss.py.
  • Exported compiler-required symbols into transformers.models.gpt_oss.modeling_gpt_oss:
    • ParameterModule
    • swiglu_torch_forward
    • dtype_from_config
    • transformers_version
    • Version
  • Registered the hook via TEMPORARY_PATCHES.append(patch_gpt_oss_compiler_exports).
  • Normalized GPT-OSS guard matching with UNSLOTH_MODEL_NAME.replace("-", "_") usage across key 4-bit/load guards.
  • Cleaned compiler export patch flow in exception path and removed redundant pass.
  • Updated compiler decorator stripping to handle:
    • @use_kernel_forward_from_hub(...)
    • @auto_docstring
      This removes noisy unknown-decorator warnings in GPT-OSS compile paths.

Validation

Run dirs:

  • logs/pr519_verify_20260226_031808/test_gpt_oss_compiler_export.log
  • logs/pr519_verify_20260226_031808/test_gpt_oss_compiler_export_after_autodoc_reinstall.log

Results:

  • GPT-OSS compiler export smoke test: PASS
  • @use_kernel_forward_from_hub unknown decorator warning: removed
  • @auto_docstring unknown decorator warning: removed

Notes

This change is scoped to symbol export and compile-time compatibility. It does not modify model math.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @danielhanchen, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses and resolves GPT-OSS compiled-cache failures by ensuring that critical symbols, such as ParameterModule, are properly exposed within the transformers.models.gpt_oss.modeling_gpt_oss namespace. This change prevents runtime errors that occur when compiled GPT-OSS modules attempt to resolve these previously missing symbols, thereby improving the stability and functionality of compiled GPT-OSS models.

Highlights

  • New Patch Function: Added patch_gpt_oss_compiler_exports() to unsloth_zoo/temporary_patches/gpt_oss.py.
  • Symbol Export: Exported ParameterModule, swiglu_torch_forward, dtype_from_config, transformers_version, and Version into transformers.models.gpt_oss.modeling_gpt_oss for compiler resolution.
  • Patch Registration: Registered the new patch function by appending it to TEMPORARY_PATCHES.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • unsloth_zoo/temporary_patches/gpt_oss.py
    • Added a new function patch_gpt_oss_compiler_exports to conditionally import transformers.models.gpt_oss.modeling_gpt_oss.
    • Implemented the export of ParameterModule, swiglu_torch_forward, dtype_from_config, transformers_version, and Version into the modeling_gpt_oss module.
    • Registered the patch_gpt_oss_compiler_exports function to the TEMPORARY_PATCHES list.
Activity
  • No human activity has been recorded on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly addresses a compiler failure for GPT-OSS models by exporting necessary symbols like ParameterModule into the transformers.models.gpt_oss.modeling_gpt_oss namespace. The implementation is straightforward and adds a new patch function patch_gpt_oss_compiler_exports to handle this. My only feedback is a minor code cleanup suggestion to improve readability.

m.dtype_from_config = dtype_from_config
m.transformers_version = transformers_version
m.Version = Version
pass
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

The pass statement here is redundant and can be removed. Python functions with a non-empty body do not require an explicit pass at the end.



def patch_gpt_oss_compiler_exports():
model_name = os.environ.get("UNSLOTH_MODEL_NAME", "").replace("-", "_")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Ideally, if our temporary_patches creates and references a class, compiler.py should automatically handle copying it over. But for now this is fine.


# Export helpers so compiler generated GPT-OSS modules can resolve symbols.
m = transformers.models.gpt_oss.modeling_gpt_oss
m.ParameterModule = ParameterModule
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

My only worry here is that this would leave from unsloth_zoo.temporary_patches.gpt_oss import ParameterModule in the unsloth_compiled_module_gpt_oss.py. Can you please verify where the import resolves to and it doesnot create a dependency cycle?

@danielhanchen
Copy link
Copy Markdown
Contributor Author

Addressed review comments on #519 and verified import resolution:

  • Added guard normalization for hyphenated GPT-OSS names across key 4-bit/load guards.
  • Cleaned patch_gpt_oss_compiler_exports exception path and removed redundant trailing pass.
  • Updated compiler rewrite to strip @use_kernel_forward_from_hub(...) and @auto_docstring decorators so these no longer emit unknown-decorator warnings in GPT-OSS compile path.

Datta concern check (dependency cycle):

  • Ran temp/test_gpt_oss_compiler_export.py after reinstalling from source on this branch.
  • Compiled module generated at unsloth_compiled_cache/unsloth_compiled_module_gpt_oss.py and import path resolved successfully.
  • No dependency cycle hit; test passes.

Latest verification logs:

  • logs/pr519_verify_20260226_031808/test_gpt_oss_compiler_export_after_autodoc_reinstall.log

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants