en_core_web_hftrf-3.8.1 fails to load with spacy-transformers 1.4.0 (safetensors weights)
Summary
en_core_web_hftrf-3.8.1 (release) ships with transformer weights in safetensors format and pins spacy-transformers>=1.4.0,<1.5.0. However, spacy-transformers 1.4.0 cannot load safetensors weights — HFShim.from_bytes calls torch.load() which only handles pickle/zip format.
The safetensors migration (explosion/spacy-transformers#423, commit 2cba136) landed on master 3 days after the 1.4.0 release, so there is currently no released version of spacy-transformers that can load this model.
Steps to reproduce
pip install spacy==3.8.7 spacy-transformers==1.4.0
pip install en_core_web_hftrf==3.8.1
python -c "import spacy; spacy.load('en_core_web_hftrf')"
Error
_pickle.UnpicklingError: Weights only load failed. [...]
WeightsUnpickler error: Unsupported operand 64
With weights_only=False forced, the error becomes:
_pickle.UnpicklingError: invalid load key, '@'
The first byte of the state is 0x40 (@), which is the start of a safetensors header (little-endian u64 header length), not a pickle stream.
Environment
- Python 3.12
- spacy 3.8.7
- spacy-transformers 1.4.0
- torch 2.8.0
Request
Could a new release of spacy-transformers be cut to include the safetensors migration from explosion/spacy-transformers#423? Currently there is no way to use en_core_web_hftrf-3.8.1 with a released version of spacy-transformers.
Hi @maripastor-mr,
Thank you for the detailed report.
I was able to reproduce the issue and would like to investigate it further. I'll look into the loading path in spacy-transformers and verify whether the safetensors support introduced in PR #423 resolves the incompatibility with en_core_web_hftrf-3.8.1.
If there are no objections, I'd be happy to work on a fix and submit a PR.
oh interesting, that _pickle.UnpicklingError with the @ key totally gave it away for me too, I hit the same thing a couple days back trying to load en_core_web_hftrf-3.8.1 after a fresh pip install with spacy-transformers 1.4.0. turns out, spacy-transformers 1.4.0 just doesn't have any safetensors support at all, like you said, it's still calling torch.load() under the hood expecting a pickle. I actually tried to quick-patch HFShim to use safetensors.torch.load_file and it sorta worked locally, but the model metadata was all out of sync since the release itself wasn't built for that flow.
The annoying part is the model README and the pip dependencies will happily let you install this broken combo since it pins >=1.4.0 but that commit for safetensors only hit master after 1.4.0 was cut. I didn't spot a workaround besides checking out spacy-transformers from master and installing that. Feels like the model should have either waited for a new spacy-transformers release, or the dependency range should've been stricter to avoid this weird limbo. Anyway, yeah, only thing that's worked for me is running with the unreleased spacy-transformers branch directly until a new version drops.