Repository navigation
Recognise a partially initialised torchvision and fix the studiobench ab_plan row - #11015
Conversation
…n payload section The broken torchvision probe only matched loader failures and the torchvision:: operator wording, so the common transformers lazy import shape, partially initialized module 'torchvision' has no attribute 'extension', fell through and the user got the raw traceback instead of the reinstall guidance. Require the partially initialized wording, which CPython only produces while the module is still executing its own import, so a typo'd attribute on a healthy torchvision is no longer answered with reinstall advice. Add the negative controls and an end to end probe assertion. ab_plan was mapped to header in the studiobench payload, and header is collapsed to its first row when the payload is assembled, so the A/B order was dropped silently while record_counts still reported two header rows. Keep it as its own section and exempt it from the bare zero walker, the same way comparability is handled. The new selftest inserts tests/studio on sys.path before importing studiobench, as every other selftest beside it does, so the file collects when it is run on its own.
peft.utils.transformers_weight_conversion arrived in PEFT 0.19.0, and both pyprojects declare peft>=0.18.0, so on the floor the patch it guards returns early by design and there is nothing to drift from. The detector stays a hard failure from 0.19.0 up.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
…ually raises Both from the Codex review, plus one the check for the second turned up. ab_plan: --resume appends its own plan for the work that session was asked to do, so collapsing the section to [0] named only the first session's cells while record_counts reported both. Concatenate order, AND balanced. torchvision: a stray torchvision.py raises the same words a half-loaded extension does, and the metadata still reports the installed distribution, so the binary branch answered a shadowing bug with reinstall advice that cannot fix it. Resolve the file with find_spec and name it instead. While testing that with a real shadow: CPython 3.13 words the message "partially initialized module 'X' from '<file>' has no attribute", 3.12 omits the from clause. The marker required the 3.12 wording, so the detection this PR adds was dead on 3.13. Allow the clause, and pin the marker to what the running interpreter raises so it cannot drift again.
|
@codex security review |
…e balance claim A torchvision/ directory shadows as well as a torchvision.py and is a package like the real one, so the spec's shape cannot separate them. Compare the resolved file against what the distribution's metadata installed instead, and decline to answer when that layout is not on disk. An A/B with work left re-runs every pair, so a plan whose every cell id a later plan names is superseded and no longer speaks for balance. order stays the union.
…ows does An ab_plan row is emitted before its session runs anything, so its order is a request. A resume that dies before retrying the old pair leaves that pair owned by the session that did run it, and reading liveness off plan membership reported a balance nothing measured. Ownership now keys on session_id over ATTEMPT_ROW_TYPES, imported from scoring/from_payload rather than restated: that module moved off cell rows because an attempt hard-killed mid-cell never writes its terminal row, and a second copy of the rule that disagreed would be worse than none.
The marker now allows the 3.13 `from '<file>'` clause, but still requires
"has no attribute" after the module name, and CPython words the same fault two
further ways that carry no such clause:
cannot import name 'extension' from partially initialized module 'torchvision'
cannot access submodule 'ops' of module 'torchvision'
The first is what `from torchvision import X` raises while torchvision is still
executing, the second what a repeat import raises once a submodule has failed to
initialise. Both reach the probe from transformers' lazy import, and both were
read as a healthy box.
Anchor on "partially initialized module 'torchvision'" and nothing after it,
which covers all three of those wordings at once, plus one alternative for the
submodule form, which names torchvision as the parent instead. The shadow guard
and the negative cases are unchanged, and a typo on a healthy torchvision still
cannot produce any of them.
Also skip the shadow case when torchvision is not installed. A shadow exists only
relative to an installed torchvision, so _shadowing_torchvision_path returns None
by design there and the case failed, rather than skipped, on every environment
without it.
The ab_plan row's balanced is order_is_balanced over the whole plan, computed
before any of it runs. A --reps 2 interrupted after rep 0 planned base,
treatment, treatment, base and ran base, treatment, so base led every pair that
happened and drift lands on treatment rather than cancelling. The completed pair
is scored either way, so the plan's True described an order nothing ran.
executed_balance applies the same rule to the cells a session owns, reading the
arm and pair out of make_cell_id's r{rung}.{arm}.rep{rep}, and returns None on
ids of another shape so the plan's own word stands. order remains the requested
ladder; balanced now describes the run.
order spans every session and balanced comes from the ones owning the latest attempts, so carrying plans[0]'s session_id labelled the result s1 while s2 supplied the verdict. Drop the per-row stamps and name the contributors.
|
Codex Review: Didn't find any major issues. 👍 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Breezy! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
… ab_plan row (unslothai#11015) ## torchvision A torchvision whose compiled extension failed to load does not always surface as a loader error. Reached through a lazy import it arrives as a circular-import message, and CPython words that one fault four ways: ``` 3.9 - 3.12 partially initialized module 'torchvision' has no attribute 'extension' 3.13, 3.14 partially initialized module 'torchvision' from '<file>' has no attribute from-import cannot import name 'extension' from partially initialized module 'torchvision' submodule cannot access submodule 'ops' of module 'torchvision' ``` Measured on this box (3.12.3 omits the `from` clause, 3.13.12 carries it) and confirmed against the interpreter's own strings for the fourth. The marker anchors on `partially initialized module 'torchvision'` and stops there, with one alternative for the submodule wording. A typo on a healthy torchvision still cannot match, because none of these occur without "partially initialized". A local `torchvision` earlier on sys.path raises the same words while the metadata still describes the installed distribution, so the check would have answered a shadowing bug with "reinstall", which cannot change which sys.path entry is searched first. `_shadowing_torchvision_path` asks identity rather than shape, since a `torchvision/` directory is a package exactly like the real one: it compares what `find_spec` resolves against what the distribution's metadata installed, and declines to answer when that layout is not on disk. `find_spec` rather than `sys.modules`, because CPython has already removed the half-built module by the time the `except` runs. `test_the_marker_matches_what_this_interpreter_actually_says` provokes the error on whatever interpreter runs the suite and checks the marker against it, so the pattern cannot drift from CPython again without a red test. ## studiobench ab_plan `--resume` emits a fresh `ab_plan` for the work that session was asked to do, so collapsing the section to `[0]` dropped the cells a later session added while `record_counts` still reported both plans. That is the same silent loss that moved this row out of `header`, one layer down. - `order` is the union across sessions. - `balanced` is ANDed over the sessions that still own a cell, taking ownership from `latest_attempt_rows`: `ATTEMPT_ROW_TYPES` rather than `cell` rows alone, keyed on `session_id`. Keying on cell rows would have reintroduced the bug that module already fixed, since an attempt hard-killed mid-cell never writes its terminal row. - Each verdict is recomputed over what that session attempted, because the row's own was computed over the whole plan before it ran. A `--reps 2` interrupted after rep 0 planned base, treatment, treatment, base and ran base, treatment, so base led every pair that happened. - The merged object no longer carries `plans[0]`'s `session_id`, which labelled the result with a session that supplied none of the verdict. It names every contributor instead. Every fix is mutation-tested: restoring the old marker fails 4 tests, shape-based shadow detection fails 1, `cell`-only ownership fails 1, plan-membership liveness fails 2, reading `balanced` off the plan fails 1, dropping the single-arm rule fails 1, `[0]` for `ab_plan` fails 2.
Summary
Two diagnostic and test-harness fixes, neither on a training, inference or saving path.
The broken-torchvision probe now recognises the shape the reporter of #1793 actually hit,
a
partially initialized module 'torchvision' has no attribute 'extension', withoutfiring on the message a typo against a perfectly healthy torchvision produces.
The studiobench
ab_planrow now has its own report section and payload key instead ofbeing filed under
header, which is collapsed to its first row, so the A and B order wasbeing dropped silently while
record_countsstill claimed two header rows.Root cause
#1793.
_probe_torchvision_binaryimportstorchvisionandtorchvision.opsearlyso an ABI mismatch is named at
import unslothand not six frames deep in transformers._is_broken_torchvision_errordecides whether a failure is that pathology. It knew theloader shapes and
operator torchvision::nms does not exist, but not this one:nor the transformers
_LazyModuleRuntimeErrorthat wraps it when something importstorchvision lazily. Users with that break got the raw traceback instead of the reinstall
guidance the probe exists to produce.
#9580.
ROW_TYPE_SECTIONSintests/studio/studiobench/report/payload.pymappedab_planto theheadersection.assemble_rowscollapsesheaderto its first row, sothe
ab_planrow was discarded whilerecord_countsreported two header rows, and thescorer could no longer say whether the A and B order had been balanced.
Changes
unsloth/import_fixes.py_TORCHVISION_ATTRIBUTE_RE, requiring both halves:The module name must be
torchvisionor one of its submodules, so an unrelated circularimport elsewhere does not match. The
partially initializedwording is what separatesthe break from a typo: CPython only words an attribute failure that way while the module
is still executing its own
__init__, which is precisely the window the probe's ownimport torchvisionruns in. A fully imported torchvision cannot produce it, so nothingthe probe can see is lost, and
module 'torchvision' has no attribute 'nms'no longergets answered with
pip install --force-reinstall.tests so the narrowing cannot have eaten them.
tests/studio/studiobench/report/payload.pyandscoring/schema.pyab_plangets its own section and its own payload key, the same shapecomparabilityalready uses, and joins
comparabilityinEXEMPT_SUBTREE_KEYSfor the same reason: anunbalanced order recorded as
Falseis a true statement about how the run was executed,not a missing measurement.
tests/test_import_fixes_drift.py(separate commit)test_peft_transformers_weight_conversion_importable_and_signaturefails at thedeclared PEFT floor on
main, becausepeft.utils.transformers_weight_conversionarrived in PEFT 0.19.0 while both pyprojects declare
peft>=0.18.0. Below 0.19.0 thefunction it guards,
patch_peft_weight_converter_compatibility, returns early by design,so there is nothing to drift from and the detector now skips with that reason. From
0.19.0 up it is unchanged and still a hard failure. A bare
pytest.importorskipon thesubmodule would have been wrong: that would also swallow a real upstream removal, which
is the thing this detector exists to catch. The gate uses the file's own
_safe_versionand
_PkgVersionhelpers, the same way itsdatasets4.4.x range check does.studio/install_llama_prebuilt.pyis deliberately untouched. Its_MACOS_LOADER_FAILURE_MARKERSlist is about macOS dyld failures when selecting allama.cpp prebuilt, not about torchvision, and is not a copy of anything here.
Compatibility
CPU lane, 26 environments, every step of both fixes.
Every executed cell passes. The only non-pass value is
studiobench-full, the wholestudiobench suite, which is run once rather than in every corner and is recorded as
skipwith the reason "optional group 'heavy' not requested" everywhere exceptmStudio, where it ran and passed: 1403 passed, 156 skipped.mAis python 3.10.19, the syntax floor.mA,mX1,mV1andmStudioare thePEFT 0.18.x corners where
import-fixes-driftfailed onmain; they pass here because ofthe version gate described above, and
mB,mC,mD,mX2and the eighteentransformers-sweep corners confirm the detector still runs, not skips, from PEFT 0.19 up.
Tests
tests/test_broken_torchvision_probe.py, 39 tests, 15 of them on this change:torchvision.transforms, and a deepersubmodule
_LazyModuleRuntimeErrorwrapper, with theAttributeErroras__cause__import, a dotted parent (
mypackage.torchvision), three near-miss names(
torchvisionfoo,not_torchvision,mytorchvision), andmodule 'os' has no attribute 'extension'_probe_torchvision_binaryitself, rather than the predicate:the partially initialised error must raise an
ImportErrorthat namesUNSLOTH_SKIP_TORCHVISION_CHECK=1and carries the original as__cause__, and the typomust leave
import unslothaloneThe three typo negatives and the end to end silence are the cases that fail on the naive
form of this marker; the three positives, the wrapper and the end to end raise are the
cases that fail on
main.tests/studio/studiobench/report/selftest/test_studiobench_payload_ab_plan.py, 4 tests:ab_planhas its own section, the row survives assembly with itstreatment_ref,orderand
balancedfields,headeris still therun_metarow andrecord_countsagrees, andan absent
ab_planassembles to an empty mapping. The file now insertstests/studioonsys.paththe way all five sibling selftests in that directory do, so it collects when runon its own instead of only when another test in the same session had already done it.
Also green on the branch: every unsloth test file that imports
import_fixes, 29 files,1778 passed; the collection-drift gate from
consolidated-tests-ci.yml, 275 testscollected; and all four studiobench CI steps,
pytest tests/studio/studiobench(1413 passed, 146 skipped),
ruff check tests/studio/studiobench,--doctor, and thezipapp build plus its own
--doctor.Commits
Two commits, deliberately kept apart.
ab_plansection, which are the two issuesthis PR closes.
tests/test_import_fixes_drift.py. That is a pre-existing testfailure at the declared PEFT floor rather than part of either issue, so it is separated
to keep it easy to review or revert on its own. The version boundary was verified
against the upstream tags:
src/peft/utils/transformers_weight_conversion.pyis absentat
v0.18.1and present atv0.19.0.Evidence
Log paths below are relative to the report directory that accompanies this work.
mainfixpass_laneC_pr8_torchvision_before.logtests/test_import_fixes_drift.pyon this branchfixpass_laneC_pr8_after_torchvision.logfixpass_laneC_pr8_torchvision_repro.logimport_fixes, 29 filesfixpass_laneC_pr8_import_fixes_suite.logconsolidated-tests-ci.ymlfixpass_laneC_pr8_import_fixes_suite.logpytest tests/studio/studiobench,ruff check tests/studio/studiobench,--doctor, the zipapp build and its--doctorfixpass_laneC_pr8_studiobench.logsys.pathinsertfixpass_laneC_pr8_studiobench_recheck.logfixpass_laneC_matrix_peft018_recheck.logfixpass_laneC_final_verify.logKnown limitations
partially initializedwording. If a report ever arriveswhere a broken torchvision surfaces as a plain
module 'torchvision' has no attribute ...raised from insideimport torchvision, that message is the thing to add, with thetraceback attached. CPython's wording rules say it cannot happen in that window, but
that is an argument rather than a user report.
studio/install_llama_prebuilt.pyis untouched. Its macOS loader failure markers areabout selecting a llama.cpp prebuilt, not about torchvision.
comparabilityis in, and it is what the issue asks for: the plan is no longerdiscarded. Rendering it in the report is a separate change.
Follow-up review pass
The marker matched the module name and then required " has no attribute" right after it. CPython
words the same fault four ways, and the head of this branch had just made the 3.13
from '<file>'clause optional, which covers two of them. The other two carry no such clause at all:
The first is what
from torchvision import Xraises while torchvision is still executing, which is ashape torchvision's own
__init__produces, and the second is what a repeat import raises once asubmodule has failed to initialise. Both reach this probe through the same lazy import in
transformers, and both were read as a healthy box. The marker now anchors on
partially initialized module 'torchvision'and nothing after it, which covers three of the four wordings at once, plus onealternative for the submodule form, which names torchvision as the parent instead. Every negative
case on the branch still passes, and a typo on a fully imported torchvision still cannot produce any
of these words.
Two of the new cases provoke the wording from the running interpreter rather than quoting it, so a
future CPython rewording fails loudly instead of switching the probe off quietly, which is how the
3.13 clause got past the first round.
Separately,
test_a_file_shadowing_torchvision_is_named_rather_than_blamed_on_the_binarynow skipswhen torchvision is not installed. A shadow only exists relative to an installed torchvision, so
_shadowing_torchvision_pathreturns None by design where there is none, and the case failed ratherthan skipped on every environment without torchvision, which several of the test environments here
are.
End to end on Python 3.13, with a package named
torchvisionwhose__init__touches an attributeon itself while it is still executing, which is what a torchvision with a dead extension does:
import unslothdies with the rawAttributeErroron main and on the branch as it stood, and namesthe broken torchvision plus
UNSLOTH_SKIP_TORCHVISION_CHECK=1after this commit. The marker was alsochecked against the message each of CPython 3.9, 3.10, 3.11, 3.12, 3.13 and 3.14 actually produces.
Fixes #1793
Fixes #9580