Skip to content

Bug: sentence-transformers export fails due to removed _text_length attribute in version 5.4.0 #1680

@MissLostCodes

Description

@MissLostCodes

Description

Exporting sentence-transformers models using the OpenVINO exporter fails with an AttributeError related to the _text_length attribute.

This is leading multiple failing tests :

FAILED tests/openvino/test_exporters_cli.py::OVCLIExportTestCase::test_exporters_cli_full_quantization_10_feature_extraction - subprocess.CalledProcessError: Command 'optimum-cli export openvino --task feature-extraction --model optimum-intel-internal-testing/stsb-bert-tiny-safetensors --quant-mode int8 --library sentence_transformers --dataset c4 --num-samples 1 /tmp/tmp8apu_q83' returned non-zero exit status 1.
FAILED tests/openvino/test_exporters_cli.py::OVCLIExportTestCase::test_exporters_cli_sentence_transformers - AttributeError: type object 'SentenceTransformer' has no attribute '_text_length'. Did you mean: '_input_length'?

Reproduction
Reproduce the bug in this notebook

Run the following command:

optimum-cli export openvino \
  --task feature-extraction \
  --model optimum-intel-internal-testing/stsb-bert-tiny-safetensors \
  --quant-mode int8 \
  --library sentence_transformers \
  --dataset c4 \
  --num-samples 1 \
  ov_model

Error

Traceback (most recent call last):
  File "/usr/local/bin/optimum-cli", line 6, in <module>
    sys.exit(main())
             ^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/optimum/commands/optimum_cli.py", line 219, in main
    service.run()
  File "/usr/local/lib/python3.12/dist-packages/optimum/commands/export/openvino.py", line 485, in run
    _main_quantize(
  File "/usr/local/lib/python3.12/dist-packages/optimum/exporters/openvino/__main__.py", line 681, in _main_quantize
    model = model_cls.from_pretrained(
            ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/optimum/intel/openvino/modeling_base.py", line 613, in from_pretrained
    return super().from_pretrained(
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/optimum/modeling_base.py", line 407, in from_pretrained
    return from_pretrained_method(
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/optimum/intel/openvino/modeling_sentence_transformers.py", line 97, in _from_pretrained
    model = super()._from_pretrained(
            ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/optimum/intel/openvino/modeling_base.py", line 534, in _from_pretrained
    model = cls(
            ^^^^
  File "/usr/local/lib/python3.12/dist-packages/optimum/intel/openvino/modeling_sentence_transformers.py", line 30, in __init__
    self._text_length = MethodType(SentenceTransformer._text_length, self)
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: type object 'SentenceTransformer' has no attribute '_text_length'. Did you mean: '_input_length'?

Root Cause

The exporter binds the private _text_length method from SentenceTransformer. However, this attribute has been removed in recent versions of the sentence-transformers library.

The binding appears to be unused in the current implementation (dead binding).

Expected Behavior

The export should complete successfully without relying on removed or private attributes.

Environment
optimum-intel: current main
sentence-transformers: latest(5.4.0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions