-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use cosine as the rank score (#708)
* fix: use cosine as the rank score * fix: return cosine or probls as rank score * fix: add logit scale * fix: unittest * fix: use softmax as para name * fix: return both softmax and cosine * fix: numpy softmax
- Loading branch information
Showing
7 changed files
with
135 additions
and
78 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
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,19 @@ | ||
import pytest | ||
import numpy as np | ||
from clip_server.executors.helper import numpy_softmax | ||
|
||
|
||
@pytest.mark.parametrize('shape', [(5, 10), (5, 10, 10)]) | ||
@pytest.mark.parametrize('axis', [-1, 1, 0]) | ||
def test_numpy_softmax(shape, axis): | ||
import torch | ||
|
||
logits = np.random.random(shape) | ||
|
||
np_softmax = numpy_softmax(logits, axis=axis) | ||
torch_softmax = torch.from_numpy(logits).softmax(dim=axis).numpy() | ||
np.testing.assert_array_almost_equal(np_softmax, torch_softmax) | ||
|
||
np_softmax = numpy_softmax(logits, axis=axis) | ||
torch_softmax = torch.from_numpy(logits).softmax(dim=axis).numpy() | ||
np.testing.assert_array_almost_equal(np_softmax, torch_softmax) |
Oops, something went wrong.