-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add model kwargs to SentenceTransformersRanker (#6627)
* Add model_kwargs to SentenceTransformersRanker * Add unit test * Add unit tests for the torch dtype extraction * Add release notes * Fix formatting * Fix patch * Make function more explicit
- Loading branch information
Showing
6 changed files
with
81 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
enhancements: | ||
- | | ||
Add model_kwargs argument to SentenceTransformersRanker to be able to pass through HF transformers loading options | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import pytest | ||
import torch | ||
|
||
from haystack.utils.torch_utils import resolve_torch_dtype | ||
|
||
|
||
def test_extract_torch_dtype() -> None: | ||
torch_dtype = resolve_torch_dtype(**{"torch_dtype": torch.float16}) | ||
assert torch_dtype == torch.float16 | ||
|
||
|
||
def test_extract_torch_dtype_none() -> None: | ||
torch_dtype = resolve_torch_dtype(**{}) | ||
assert torch_dtype is None | ||
|
||
|
||
def test_extract_torch_dtype_str() -> None: | ||
torch_dtype = resolve_torch_dtype(**{"torch_dtype": "torch.float16"}) | ||
assert torch_dtype == torch.float16 | ||
|
||
|
||
def test_extract_torch_dtype_auto() -> None: | ||
torch_dtype = resolve_torch_dtype(**{"torch_dtype": "auto"}) | ||
assert torch_dtype == "auto" | ||
|
||
|
||
def test_extract_torch_dtype_invalid() -> None: | ||
with pytest.raises(ValueError): | ||
_ = resolve_torch_dtype(**{"torch_dtype": "random string"}) |