Skip to content

Commit 0c962e9

Browse files
dlutwydlutwy
authored andcommitted
fix: handle INFONCE_HARD_NEGATIVES as integer if provided (#4545)
Co-authored-by: dlutwy <[email protected]~>
1 parent 4947d5b commit 0c962e9

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

swift/plugin/loss.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,8 @@ def calculate_infonce_metrics(embeddings, labels):
174174
from scipy.stats import pearsonr, spearmanr
175175
hard_negatives = os.environ.get('INFONCE_HARD_NEGATIVES', None)
176176
use_batch = strtobool(os.environ.get('INFONCE_USE_BATCH', 'True'))
177+
if hard_negatives is not None:
178+
hard_negatives = int(hard_negatives)
177179
split_tensors = _parse_multi_negative_sentences(torch.tensor(embeddings), torch.tensor(labels), hard_negatives)
178180
split_tensors = [t.numpy() for t in split_tensors]
179181
can_batched = hard_negatives is not None

0 commit comments

Comments
 (0)