Repository navigation
tests(version_compat): AST-based symbol checks and per-model drift coverage - #6740
Conversation
FastQwen3Model.pre_patch (unsloth/models/qwen3.py) rebinds Qwen3Attention/DecoderLayer/Model/ForCausalLM.forward and assigns Qwen3RotaryEmbedding on the transformers module. If any of those names disappear in a future transformers release the rebind silently no-ops and Unsloth's Qwen3 fast paths stop applying. Mirrors the existing gemma3/gpt_oss checks in the same file. CPU-only; 12 parametrized tags, ~6s wall.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 010b2b5e5f
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| if src is None: | ||
| pytest.skip(f"{tag}: modeling_qwen3.py missing") |
There was a problem hiding this comment.
Fail when pinned Qwen3 source is missing
When a pinned transformers tag moves or deletes src/transformers/models/qwen3/modeling_qwen3.py, fetch_text returns None on the 404 and this new guard skips instead of failing. unsloth/models/qwen3.py imports that exact module for supported transformers versions, so skipping makes the test pass in the file-moved/deleted case it is meant to catch; the Qwen3-supported pinned tags should fail here (or check an explicit alternate path), while transient network skips are already handled inside fetch_text.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Skipping is intended: gpt_oss and falcon_h1 do not exist on the older matrix tags, and a rename on a tag where the file exists still fails the class asserts.
|
Same gap exists in other files Happy to send a follow-up, either one test per model like this one, or a table-driven parametrize (one function + a row per model). Or skip it if you'd rather not expand the pattern. Let me know? |
|
@wasimysaid I'm willing to work on that. I'd like to learn more about Unsloth by contributing further. Could you assign the follow-up work to me? I'd also appreciate any guidance on the intended approach or your vision for these tests so I can implement them. |
oh yes no problem, thank you! il take a look in a bit and tell you if i found anything :) |
|
@danielhanchen , @wasimysaid The current |
…version compatibility tests
…nd adding all the models.
|
@danielhanchen this is ready for review. Coverage now spans 12 model files via a table-driven MODELING_CONTRACTS setup (llama, qwen2, qwen3, qwen3_moe, gemma, gemma2, gemma3, gpt_oss, mistral, cohere, granite, falcon_h1). 144/144 pass across the 12-tag matrix, full suite 239/1 skip. Let me know if any changes are needed, otherwise it's all yours. |
|
Review record for #6740, carried over from the mirror it was reviewed on: danielhanchen/unsloth-staging-review#408. Findings are quoted as posted and attributed to the account that posted them. The reactions shown are the triage recorded on the mirror; none were re-applied here. Commits are named as the mirror's, with this PR's equivalent where one was found. Round 1: reviewed mirror
|
Why
Every
Fast<Model>Model.pre_patchinunsloth/models/rebinds forward methods and assigns a rotary-embedding class ontransformers.models.<X>.modeling_<X>. If any of those names disappear upstream, the rebind silently no-ops (Python lets you assign arbitrary attrs on a module) and Unsloth's fast paths stop applying with no signal at import time.tests/version_compat/test_transformers_pinned_symbols.pypreviously guarded this failure class only forGemma3AttentionandGptOssModel; everything else was uncovered.While adding the coverage I also moved the regex/substring helpers in
tests/version_compat/_fetch.pyto AST. The oldhas_defand inline<sym> in srcchecks false-positive on docstrings, string literals, and commented-out code. The new helpers parse the source once and walk the tree, with a regex fallback for the case whereast.parsefails on syntax newer than the running Python.What
tests/version_compat/test_transformers_pinned_symbols.py: replaced the per-modeltest_<X>_*tests with a table-driventest_modeling_contractparametrized over aMODELING_CONTRACTStuple ofModelingContractrows. Each row pins the upstream module path, the classes that must remain, the rotary-embedding name (orNone), and optional extra bindings. Adding a new model is one tuple entry.Covered:
llama,qwen2,qwen3,qwen3_moe,gemma,gemma2,gemma3,gpt_oss,mistral,cohere,granite,falcon_h1.glm4_moeis omitted with an inline note: upstream renamedGlm4MoeLiteNaiveMoetoGlm4MoeLiteExpertson main, so the Unsloth side needs a fix before the test can pass againstmain.tests/version_compat/_fetch.py: AST-based helpers replacing the regex ones.has_def(src, name, kind="any"): walksClassDef/FunctionDef; with defaultkind="any"also matches module-level assignments andimport ... as name.is_bound(src, name): True iffnameis bound at module scope. Replaces ~30 ad-hoc<sym> in srcsubstring checks across the suite.function_params(src, name, *, cls=None): returns param names ofdef name(...), optionally scoped to a class. Replaces ad-hocre.search(r"^\s*def name\(([^)]*)\)", ...)patterns.ast.parsefails. AST is preferred; the fallback is best-effort and coarser.function_params(..., cls=X)returnsNonerather than guessing under regex (class scoping isn't reliable without an AST).Five files updated to use the new helpers:
test_transformers_pinned_symbols.py,test_bitsandbytes_pinned_symbols.py,test_sentence_transformers_pinned_symbols.py,test_peft_pinned_symbols.py,test_trl_grpo_pinned_symbols.py.No new runtime deps (
astandreare stdlib). No changes to non-test code.