infinity icon indicating copy to clipboard operation
infinity copied to clipboard

fixed super.init in SentenceTransformerPatched

Open raul3820 opened this issue 6 months ago • 0 comments

Related Issue

The problem stems from the __init__ method of the parent class, SentenceTransformer. This method uses self.__class__.__name__ to set a configuration value.

When subclass SentenceTransformerPatched calls super().__init__(), self.__class__.__name__ evaluates to "SentenceTransformerPatched". The parent class's internal logic is not designed for this and expects the name to be "SentenceTransformer", which leads to incorrect config and problems like this:

WARNING: No sentence-transformers model found with name temp/models/model_1752105604572. Creating a new one with mean pooling.

The fix avoids calling super().__init__() directly. Instead, it creates a temporary instance of the base SentenceTransformer class, which initializes correctly. It then copies the state from this temporary object to the current instance (self), effectively bypassing the problematic check while still properly initializing the object.

Checklist

  • [x] I have read the CONTRIBUTING guidelines.
  • [ ] I have added tests to cover my changes.
  • [ ] I have updated the documentation (docs folder) accordingly.

Additional Notes

I tried to run the poetry tests but got stuck here:

Installing dependencies from lock file

Finding the necessary packages for the current system

Package operations: 167 installs, 1 update, 0 removals, 3 skipped

  - Installing certifi (2024.8.30): Pending...
Checking if keyring is available
  - Installing charset-normalizer (3.4.0): Pending...
  - Installing frozenlist (1.4.1): Pending...
  - Installing idna (3.10): Pending...
  - Installing multidict (6.1.0): Pending...
  - Installing nvidia-nvjitlink-cu12 (12.4.127): Pending...
  - Installing propcache (0.2.0): Pending...
  - Installing urllib3 (2.2.3): Pending...
[keyring:keyring.backend] Loading KWallet
[keyring:keyring.backend] Loading SecretService
[keyring:keyring.backend] Loading Windows
[keyring:keyring.backend] Loading chainer
[keyring:keyring.backend] Loading libsecret
[keyring:keyring.backend] Loading macOS
Using keyring backend 'SecretService Keyring'

raul3820 avatar Jul 10 '25 08:07 raul3820