Repository navigation
Introduce compatibility with transformers v5, Sentence Transformers v6 and huggingface_hub v1 - #647
Conversation
…6 and huggingface_hub v1 Also covers datasets v4 and v5, adds Python 3.13 support, reworks the CI matrix into explicit dependency presets and fixes ONNX export with recent torch, onnx and skl2onnx releases.
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
The namespace-less "sst2" id no longer resolves on datasets 5 with huggingface_hub 1.x, and the unauthenticated matrix hits Hub rate limits on the minimum-pins cells.
There was a problem hiding this comment.
🟡 Changes recommended
SetFitModel._from_pretrained can still raise an uncaught TypeError on huggingface_hub v1 when proxies/resume_download are provided, undermining the stated compatibility goal.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR updates SetFit to remain compatible across major ecosystem changes (transformers v5, Sentence Transformers v6, huggingface_hub v1, datasets v4/v5) while keeping support for older pinned versions, and modernizes CI/testing to cover those compatibility branches.
Changes:
- Added
setfit/compat.pyto centralize version-dependent imports/paths and updated SetFit internals to use it. - Updated training argument propagation and callback wiring to work with transformers v5 behavior changes (
report_to, warmup handling, logging_dir). - Refreshed exporters (ONNX/OpenVINO) and expanded tests + CI matrix (Python 3.13, explicit dependency presets).
File summaries
| File | Description |
|---|---|
| tests/test_trainer.py | Switches losses import to compat and adds tests for report_to + warmup behavior. |
| tests/test_modeling.py | Updates dataset ID and adds coverage for local_files_only loading without SetFit files. |
| tests/test_model_card.py | Updates dataset ID and adds a model-card generation regression test with codecarbon installed. |
| tests/test_deprecated_trainer.py | Aligns deprecated trainer tests with compat losses + solver search-space change. |
| tests/test_deprecated_trainer_distillation.py | Uses compat losses for distillation tests. |
| tests/exporters/test_openvino.py | Makes OpenVINO test imports conditional to avoid hard dependency. |
| src/setfit/utils.py | Switches Sentence Transformers losses import to compat. |
| src/setfit/training_args.py | Adds transformers v5-aware logging_dir behavior and delegates unknown attrs to underlying transformers args. |
| src/setfit/trainer.py | Routes version-specific ST/transformers pieces through compat; updates callback and warmup/logging propagation; converts dataset columns to lists for datasets v4 behavior. |
| src/setfit/trainer_distillation.py | Uses compat losses and normalizes dataset column access to lists. |
| src/setfit/span/modeling.py | Guards docstring slicing against None docstrings. |
| src/setfit/modeling.py | Updates head base class via compat and adjusts hf_hub_download error handling for hub v1 exceptions. |
| src/setfit/model_card.py | Prevents codecarbon v3 “not started” reporting errors from breaking model-card generation. |
| src/setfit/exporters/openvino.py | Adjusts OpenVINO import path for 2026+ while keeping backward compatibility. |
| src/setfit/exporters/onnx.py | Forces legacy torch.onnx exporter when supported and updates sklearn-head conversion path. |
| src/setfit/compat.py | New compatibility shim for transformers/ST moved modules and default_logdir. |
| setup.py | Updates dependency constraints/extras, adds Python 3.13 classifier and python_requires>=3.9. |
| .github/workflows/tests.yml | Expands CI matrix to Python 3.13 and adds explicit compat presets + HF token for rate limiting. |
Review details
Suppressed comments (1)
src/setfit/modeling.py:818
- Same issue as the config download: if
proxiesorresume_downloadare passed, huggingface_hub v1 may raiseTypeErrordue to unsupported kwargs, and the error isn't caught here. Retrying without those keys keepsSetFitModel.from_pretrainedcompatible while still honoring them on older hub versions.
try:
model_head_file = hf_hub_download(filename=MODEL_HEAD_NAME, **download_kwargs)
except (HfHubHTTPError, EntryNotFoundError):
logger.info(
f"{MODEL_HEAD_NAME} not found on HuggingFace Hub, initialising classification head with random weights."
" You should TRAIN this model on a downstream task to use it for predictions and inference."
)
model_head_file = None
- Files reviewed: 18/18 changed files
- Comments generated: 3
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
…ment The dependency cache post-step spent several minutes uploading the whole Python install on every cache miss, more than the install itself takes.
…ack set The default callbacks of transformers and Sentence Transformers can change between versions, the test only cares that report_to="none" attaches none.
Hello!
Heads up, this PR was AI-generated and human-reviewed.
Pull Request overview
Details
SetFit had fallen behind the rest of the ecosystem. It no longer imported on transformers v5 (
default_logdirmoved), loading any model from the Hub failed on huggingface_hub v1 (HfHubHTTPErrorno longer derives fromrequests, andproxiesandresume_downloadwere removed fromhf_hub_download), everysentence_transformers.losses,models,training_argsandmodel_cardimport warns on Sentence Transformers v5.4+, and the CI had been red on every cell since April. This PR keeps support for the old versions (transformers 4.41, Sentence Transformers 3.0, huggingface_hub 0.24, datasets 2.15) while adding the new ones.The version dependent imports now live in
setfit/compat.py, which tries the Sentence Transformers v5.4+ module paths first and falls back to the old ones, and importsdefault_logdirfromtransformers.integrations.integration_utilswith a fallback.SetFitModel.from_pretrainedcatches bothHfHubHTTPErrorandEntryNotFoundError, because on huggingface_hub v1 the offline andlocal_files_only=Truemisses raise aLocalEntryNotFoundErrorthat no longer inherits fromHfHubHTTPError.On transformers v5,
warmup_ratioandlogging_dirare gone, so the warmup proportion is now passed as a fractionalwarmup_steps, andlogging_diris ignored with a warning (v5 readsTENSORBOARD_LOGGING_DIRinstead).report_toandseedare now given to the innerSentenceTransformerTrainingArgumentsat construction, since the integration callbacks are created inTrainer.__init__. Before,report_towas applied afterwards and silently ignored:report_to="none"still attached the CodeCarbon callback on transformers v4, and with the v5 default of"none"all reporting would have disappeared. Soreport_tois honoured now, which is a small behaviour change. Finally, the integration callbacks of transformers (Trackio, W&B) started reading arguments that the SetFitTrainingArgumentsdoes not define, such asargs.project, so the SetFit arguments now defer unknown attributes to the transformers arguments of the underlying trainer. Custom callbacks keep receiving the SetFit arguments as before.datasets v4 returns a lazy
Columnfordataset["text"], which is converted to a list inTrainer.evaluateanddataset_to_parameters. The ONNX exporter requests the legacy exporter explicitly (torch 2.9 defaults to the dynamo based one, which does not support the opsets used here) and converts the scikit-learn head with a float32 input, matching the float32 embeddings of the body. The double precision path it used to have never actually ran: its type check compared against anonnxconverter_commonclass that skl2onnx stopped using, and skl2onnx 1.20 no longer ships that dependency at all.openvino.runtimewas removed in openvino 2026, so the OpenVINO exporter falls back to the top level API. The model card skips emissions data when the codecarbon tracker cannot report, since recent codecarbon 3.x releases raise for a tracker that was never started, e.g. when saving before training with codecarbon installed.On the packaging side,
evaluate>=0.4.6is required as older versions cannot download metric scripts with huggingface_hub v1 (HfFolderis gone), the codecarbon range excludes 2.6 (print spam) and 2.7 and 2.8 (a second tracker in the same process, whichAbsaTrainercreates, fails with a missing_cloud),hummingbird-mlmoved out of thetestsextra as it pinsonnx<=1.16.1without Python 3.13 wheels, and spaCy is unpinned on Python 3.10+. Python 3.9 keepsspacy<3.8,numpy<2andonnx<1.17through environment markers: the spaCy 3.8 line depends on blis releases without 3.9 wheels, the spaCy 3.7 binaries need numpy 1.x, and the 3.9 wheels of onnx 1.17 to 1.19 crash on Windows oncepyarrow.datasethas been imported. These were previously hidden by thespacy<3.7.6pin and by the openvino and hummingbird extras pinning numpy and onnx.The CI matrix now runs
.[tests]on Python 3.9 to 3.13 on both operating systems, plus two presets asincludeentries:.[compat_tests](the minimum pins) on 3.9 and the new.[compat_tests_v4](transformers<5, sentence-transformers<6, huggingface_hub<1, datasets<5) on 3.11. That is 14 jobs instead of 16. The minimum pins no longer run on 3.12, where pandas 1.5.3 has no wheels (that cell failed at the install step before), and the three presets cover each branch insetfit/compat.py: Sentence Transformers 3.0, 4 to 5.3, and 5.4+, next to transformers v4 versus v5 and huggingface_hub v0 versus v1. Without the v4 preset, that generation was only tested because Python 3.9 happens to resolve to it.I ran the full suite locally on Windows for each kind of cell:
.[tests], Python 3.13.[tests], Python 3.9.[compat_tests_v4], Python 3.11.[compat_tests], Python 3.9The skips are the CUDA only tests, the OpenVINO test and the two Optuna tests (optuna is not part of
.[tests]). The suite also passes against the sentence-transformers 6.1 dev checkout with transformers 5.15 and huggingface_hub 1.24, with the Sentence Transformers deprecated import warnings turned into errors.A few caveats. With transformers v5,
warmup_proportion=1.0results in a single warmup step, as transformers reads awarmup_stepsof 1 or more as a step count. The hyperparameter search tests no longer sample theliblinearsolver, which scikit-learn 1.9 rejects for multiclass problems, and the hyperparameter optimization guide has the same solver in its search space.