Skip to content

build: require Python 3.11 and PEFT 0.22 - #30

Merged
redchupa merged 1 commit into
masterfrom
build/python-3.11-peft-0.22
Dec 3, 2026
Merged

redchupa merged 1 commit into
masterfrom
build/python-3.11-peft-0.22

Conversation

@redchupa

@redchupa redchupa commented Dec 2, 2026

Copy link
Copy Markdown
Owner

Roadmap, stage 2: adds a "dependencies" item that records the decision to require Python ≥ 3.11 and PEFT ≥ 0.22, and ticks it.

What and why

Python 3.10 reached its end of life in October 2026. PEFT 0.22.0 (2026-11-19) fixes the MoE target conversion that #28 worked around inside Heretic (huggingface/peft#3711, fixed by huggingface/peft#3715: a target is kept as a module when every module it matches is an nn.Linear), but PEFT 0.22 requires Python ≥ 3.11. This PR drops Python 3.10 and removes the workaround.

  • pyproject.toml: requires-python = ">=3.11", no 3.10 classifier, peft~=0.22.
  • uv.lock: regenerated with uv lock (uv 0.13.12; still revision = 5). PEFT moves 0.21.2 → 0.22.0 and nothing else moves: the rest of the diff only removes what Python 3.10 needed (tomli, exceptiongroup, async-timeout, importlib-resources, greenlet, and the 3.10-only versions of numpy, pandas, scipy, scikit-learn, networkx and sqlalchemy). torch and torchvision stay unpinned (2.14.1 in the lock, as before). Dependabot's chore(deps): bump the python-minor-and-patch group across 1 directory with 5 updates #8 bumps peft to 0.21.3 along with four other packages; this PR supersedes its peft part.
  • CI matrix: 3.11–3.15. README: "Python 3.11+".
  • model.py: no_peft_target_conversion() is gone; add_lora_adapters() calls get_peft_model() directly.

The check after get_peft_model() didn't work, so it is fixed here. #28 also added a check that every target got a LoRA adapter. It read peft_config.target_modules after get_peft_model(), but PEFT's conversion rewrites that same set in place (deliberately; convert_peft_config_for_transformers says "the conversion should be in-place"), so a target that PEFT dropped was also missing from the list being checked. With the workaround that didn't matter, because the conversion never ran; without it, the check is the only guard. It now checks the targets as they were before get_peft_model(). Verified with PEFT 0.21.2, which still has the bug: without the workaround, the old check let apply_lora() return with unadapted modules, the new one raises

Exception: PEFT didn't add LoRA adapters to 2 modules (such as model.layers.0.mlp.down_proj, model.layers.1.mlp.shared_experts.down_proj), so they can't be modified.

A new unit test, test_dropped_target_raises, simulates PEFT dropping a target in place; it fails with #28's check ("Exception not raised") and passes with this one.

Two small things that come with dropping 3.10:

  • The two # TODO: Replace this with hashlib.file_digest when we drop support for Python 3.10. helpers (utils.get_file_sha256, tests/run_tests.py) now use hashlib.file_digest. Same digests.
  • With the target version at 3.11, ruff's UP017 asks for datetime.UTC instead of timezone.utc (3 places, ruff check --fix). datetime.UTC is datetime.timezone.utc, so nothing changes at runtime.

Testing

  • The checks listed in CLAUDE.md pass locally, or I explain below why not.
  • No tests/*/SHA256SUMS.* file changes, or the description explains why model outputs are meant to change.

Windows 11, Python 3.12.13, torch 2.14.1+cpu, transformers 5.18.0. "Baseline" is master at b51d969 (with #28, so PEFT 0.21.2 with the workaround), run on the same machine.

  • ruff format --check, ruff check --extend-select I, ty check --error-on-warning, unit tests (165; the 2 expected failures as on master), uv build: pass. The wheel says Requires-Python: >=3.11 and Requires-Dist: peft~=0.22.
  • tests/test_lora_targets.py (from fix: keep the dense and shared-expert projections of MoE models in the LoRA targets #28: small Qwen3-Next, DeepSeek V3 and Llama models built from their configurations) passes without the workaround, so PEFT 0.22 keeps the dense and shared-expert down_proj targets. With PEFT 0.21.2 and no workaround, the Qwen3-Next and DeepSeek V3 tests fail, now with the error above.
  • get_merged_model()'s 4-bit path calls add_lora_adapters() a second time, with the same LoraConfig, which PEFT's conversion has already processed. Simulated with the same small Qwen3-Next and DeepSeek V3 models (the "reloaded" base model built from the same seed instead of quantizing): every target gets an adapter again, and the merged weights are identical to merging the adapters directly.
  • NemotronH (feat: support NemotronH by modifying its attention, MLP and MoE layers #29) isn't affected either way: PEFT's conversion table has no entry for nemotron_h.
  • Reproducibility tests (uv run tests/run_tests.py), baseline vs. this branch: every weight file (model.safetensors, adapter_model.safetensors) of all 11 tests is byte-identical. Against the committed hashes, both runs fail the same 5 tests on this machine (deepseek-v4, deepseek-v4-ara, gemma-3, gemma-4e, qwen3.5-moe), so those are differences of this machine, not of this change. The only file that differs between the two runs is adapter_config.json of the three adapter exports: peft_version 0.21.2 → 0.22.0, PEFT's new astra_config: null, and the order of target_modules, which PEFT writes from a set (it differs from run to run anyway). No SHA256SUMS file changes.
  • End to end, tiny-random/qwen3-next-moe (the model fix: keep the dense and shared-expert projections of MoE models in the LoRA targets #28 fixed) with the settings of tests/qwen3.5-moe (Abliteration, merged) and tests/qwen3.5-moe-ara (ARA, adapter). This is the check that matters for the conversion: none of the reproducibility test models is in PEFT's conversion table, so they never ran it. Both complete. Every file of the Abliteration export is byte-identical to the baseline's (5 of its 442 tensors differ from the original model: the attention output projections of layers 1–3 and the shared expert's down_proj of layers 2 and 3), and so are the ARA adapter weights. The ARA adapter_config.json differs in peft_version, the new astra_config: null, the order of target_modules, and "target_parameters": [] instead of null, which PEFT's conversion sets when it runs and leaves the targets as they are.
  • PEFT 0.22 also scales LoRA deltas in place when merging (ENH Scale delta weights in place when merging huggingface/peft#4147: delta.mul_(scaling) instead of delta * scaling, the same arithmetic). Since fix: score trials with the adapters merged into the weights #26, every trial is scored with the adapters merged, so the identical results above cover that too.

AI use declaration

  • I wrote this pull request (code and description) entirely by myself.
  • I used AI to write some or all of this pull request, and I have reviewed all of it myself,
    understand it, and can answer questions about it without relying on the AI.

🤖 Generated with Claude Code

Python 3.10 reached its end of life in October 2026. PEFT 0.22 fixes the
MoE target conversion that #28 worked around (huggingface/peft#3711,
fixed by huggingface/peft#3715), but it requires Python 3.11, so drop
Python 3.10 and remove the workaround.

- pyproject.toml: requires-python >= 3.11, no 3.10 classifier,
  peft~=0.22. uv.lock regenerated with uv 0.13.12 (still revision 5):
  PEFT 0.21.2 -> 0.22.0; the rest only drops what Python 3.10 needed.
- CI matrix without 3.10, README says Python 3.11+.
- model.py: remove no_peft_target_conversion(). Keep the check that
  every target got a LoRA adapter, but check the targets as they were
  before get_peft_model(): PEFT rewrites peft_config.target_modules in
  place, so the old check never saw a target that PEFT dropped.
- test_lora_targets.py: test that the check raises when PEFT drops a
  target.
- Resolve the "when we drop Python 3.10" TODOs with hashlib.file_digest,
  and use datetime.UTC, which ruff (UP017) asks for now that the target
  version is 3.11.
- ROADMAP: record the decision and tick it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@redchupa
redchupa merged commit cb1fe8f into master Dec 3, 2026
5 checks passed
@redchupa
redchupa deleted the build/python-3.11-peft-0.22 branch December 3, 2026 00:10
@redchupa redchupa mentioned this pull request Dec 4, 2026
3 of 4 tasks
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.

1 participant