Skip to content

Fix the FSDP2 QLoRA non-float parameter guard on Python 3.9 - #14774

Merged
danielhanchen merged 3 commits into
mainfrom
fix-fsdp2-qlora-py39-staticmethod
Oct 28, 2026
Merged

danielhanchen merged 3 commits into
mainfrom
fix-fsdp2-qlora-py39-staticmethod

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

nonfloat_param_guard temporarily replaces torch.nn.Parameter.new while FSDP2
shards a QLoRA model, so that nn.Parameter(x) defaults to requires_grad=False for
non-float data (torch < 2.12 builds the sharded parameter with requires_grad=True
first, which raises on uint8). The replacement called the original through
Parameter.dict["new"], which is a staticmethod object. staticmethod objects
only became callable in Python 3.10, so on Python 3.9 every nn.Parameter created
inside the guard raised "TypeError: 'staticmethod' object is not callable".

Reach: FSDP2 QLoRA preparation on Python 3.9, which the package still supports.
Python 3.10 and newer are unaffected.

Fix: call the function looked up through the class (Parameter.new), which
unwraps the staticmethod on every Python version. The raw object from dict is
still kept and put back on exit, so the class is restored exactly as before.

Tests: tests/test_fsdp2_qlora.py gains a test that swaps Parameter.new for a
staticmethod whose direct call raises, as on Python 3.9, and checks the guard still
turns off requires_grad for a uint8 Parameter, leaves float Parameters alone and
restores the class attribute. It fails on main and passes with this change on any
Python version. A pure Python mirror of the guard was also run on Python 3.9.25:
the old call fails, the new one works.

nonfloat_param_guard called the staticmethod object taken from Parameter.__dict__, which is
not callable on Python 3.9, so every nn.Parameter built while FSDP2 shards raised TypeError
there. Call the function looked up through the class and keep the raw object only to restore
the class on exit.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-27T12:18:37.612231Z bce4d01 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: 6109aa259b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

danielhanchen added a commit that referenced this pull request Oct 22, 2026
pre-commit.ci fails `ruff-format-with-kwargs` on every open PR (#14806,
#14805, #14803, #14790, #14785, #14781, #14780, #14777, #14776, #14775,
#14774, #14773, #14772, #14770, #14769, #14768, and others): "files were
modified by this hook". pre-commit.ci runs the hooks on all files, and
20 files on main (26 by the time this lands) are not in the formatter's
output, so every PR is reformatted outside its own diff. Where
pre-commit.ci can push, its autofix commit drags those unrelated files
into the PR (for example #14790's touches `tests/test_block_compile.py`,
`tests/test_bnb_integration_compile.py` and `unsloth/models/_utils.py`).

The drift came in with PRs merged today, among them #14702, #14751,
#14759, #14784, #14786, #14787, #14788, #14791 and the FP8 block decode,
GRPO routing replay, 4-bit decode, compiled blocks and MoE LoRA target
changes.

### Change

`python scripts/run_ruff_format.py` (the hook's own entry point,
`ruff==0.6.9` as pinned in `.pre-commit-config.yaml`) applied to those
20 files, plus 6 more from #14739, #14779 and #14806, which merged while
this was open. Formatting only.

### Verification

- Every changed file parses to an identical AST before and after.
- A second run of the hook over the same files changes nothing (fixed
point), and over all tracked Python files on this branch it changes
nothing.
- `ruff check` passes on the changed files;
`tests/test_formatter_fixed_point.py` passes (16).

Open PRs pick this up on their next pre-commit.ci run after merging
main.
@danielhanchen danielhanchen self-assigned this Oct 27, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: bce4d01471

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

[skip ci]
@danielhanchen
danielhanchen merged commit f0c879a into main Oct 28, 2026
@danielhanchen
danielhanchen deleted the fix-fsdp2-qlora-py39-staticmethod branch October 28, 2026 05:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant