chore: import upstream snapshot with attribution

This commit is contained in:
wehub-resource-sync
2026-07-13 13:39:21 +08:00
commit bc34f6df14
1149 changed files with 328099 additions and 0 deletions
@@ -0,0 +1,32 @@
import os
from FlagEmbedding import FlagAutoReranker
def test_base_multi_devices():
model = FlagAutoReranker.from_finetuned(
'BAAI/bge-reranker-v2-gemma',
use_fp16=True,
query_instruction_for_rerank="A: ",
passage_instruction_for_rerank="B: ",
devices=["cuda:3", "cuda:4"], # if you don't have GPUs, you can use ["cpu", "cpu"]
cache_dir=os.getenv('HF_HUB_CACHE', None),
)
pairs = [
["What is the capital of France?", "Paris is the capital of France."],
["What is the capital of France?", "The population of China is over 1.4 billion people."],
["What is the population of China?", "Paris is the capital of France."],
["What is the population of China?", "The population of China is over 1.4 billion people."]
] * 100
scores = model.compute_score(pairs)
print(scores[:4])
if __name__ == '__main__':
test_base_multi_devices()
print("--------------------------------")
print("Expected Output:")
print("[ 9.1484375 -4.50390625 -5.53125 10.21875 ]")
@@ -0,0 +1,32 @@
import os
from FlagEmbedding import FlagAutoReranker
def test_base_multi_devices():
model = FlagAutoReranker.from_finetuned(
'BAAI/bge-reranker-v2-gemma',
use_fp16=True,
query_instruction_for_rerank="A: ",
passage_instruction_for_rerank="B: ",
devices=["cuda:3"], # if you don't have GPUs, you can use ["cpu", "cpu"]
cache_dir=os.getenv('HF_HUB_CACHE', None),
)
pairs = [
["What is the capital of France?", "Paris is the capital of France."],
["What is the capital of France?", "The population of China is over 1.4 billion people."],
["What is the population of China?", "Paris is the capital of France."],
["What is the population of China?", "The population of China is over 1.4 billion people."]
] * 100
scores = model.compute_score(pairs)
print(scores[:4])
if __name__ == '__main__':
test_base_multi_devices()
print("--------------------------------")
print("Expected Output:")
print("[9.171875, -4.49609375, -5.5234375, 10.2109375]")
@@ -0,0 +1,33 @@
import os
from FlagEmbedding import FlagAutoReranker
def test_base_multi_devices():
model = FlagAutoReranker.from_finetuned(
'BAAI/bge-reranker-v2-minicpm-layerwise',
use_fp16=True,
query_instruction_for_rerank="A: ",
passage_instruction_for_rerank="B: ",
trust_remote_code=True,
devices=["cuda:3", "cuda:4"], # if you don't have GPUs, you can use ["cpu", "cpu"]
cache_dir=os.getenv('HF_HUB_CACHE', None),
)
pairs = [
["What is the capital of France?", "Paris is the capital of France."],
["What is the capital of France?", "The population of China is over 1.4 billion people."],
["What is the population of China?", "Paris is the capital of France."],
["What is the population of China?", "The population of China is over 1.4 billion people."]
] * 100
scores = model.compute_score(pairs, cutoff_layers=[28])
print(scores[:4])
if __name__ == '__main__':
test_base_multi_devices()
print("--------------------------------")
print("Expected Output:")
print("[1.939453125, -12.71875, -11.78125, 2.189453125]")
@@ -0,0 +1,33 @@
import os
from FlagEmbedding import FlagAutoReranker
def test_base_multi_devices():
model = FlagAutoReranker.from_finetuned(
'BAAI/bge-reranker-v2-minicpm-layerwise',
use_fp16=True,
query_instruction_for_rerank="A: ",
passage_instruction_for_rerank="B: ",
trust_remote_code=True,
devices=["cuda:3"], # if you don't have GPUs, you can use ["cpu", "cpu"]
cache_dir=os.getenv('HF_HUB_CACHE', None),
)
pairs = [
["What is the capital of France?", "Paris is the capital of France."],
["What is the capital of France?", "The population of China is over 1.4 billion people."],
["What is the population of China?", "Paris is the capital of France."],
["What is the population of China?", "The population of China is over 1.4 billion people."]
] * 100
scores = model.compute_score(pairs, cutoff_layers=[28])
print(scores[:4])
if __name__ == '__main__':
test_base_multi_devices()
print("--------------------------------")
print("Expected Output:")
print("[1.939453125, -12.71875, -11.78125, 2.189453125]")
@@ -0,0 +1,33 @@
import os
from FlagEmbedding import FlagAutoReranker
def test_base_multi_devices():
model = FlagAutoReranker.from_finetuned(
'BAAI/bge-reranker-v2.5-gemma2-lightweight',
use_fp16=True,
query_instruction_for_rerank="A: ",
passage_instruction_for_rerank="B: ",
trust_remote_code=True,
devices=["cuda:3", "cuda:4"], # if you don't have GPUs, you can use ["cpu", "cpu"]
cache_dir=os.getenv('HF_HUB_CACHE', None),
)
pairs = [
["What is the capital of France?", "Paris is the capital of France."],
["What is the capital of France?", "The population of China is over 1.4 billion people."],
["What is the population of China?", "Paris is the capital of France."],
["What is the population of China?", "The population of China is over 1.4 billion people."]
] * 100
scores = model.compute_score(pairs, cutoff_layers=[28], compress_ratio=2, compress_layers=[24, 40])
print(scores[:4])
if __name__ == '__main__':
test_base_multi_devices()
print("--------------------------------")
print("Expected Output:")
print("[25.375, 8.734375, 9.8359375, 26.15625]")
@@ -0,0 +1,33 @@
import os
from FlagEmbedding import FlagAutoReranker
def test_base_multi_devices():
model = FlagAutoReranker.from_finetuned(
'BAAI/bge-reranker-v2.5-gemma2-lightweight',
use_fp16=True,
query_instruction_for_rerank="A: ",
passage_instruction_for_rerank="B: ",
trust_remote_code=True,
devices=["cuda:3"], # if you don't have GPUs, you can use ["cpu", "cpu"]
cache_dir=os.getenv('HF_HUB_CACHE', None),
)
pairs = [
["What is the capital of France?", "Paris is the capital of France."],
["What is the capital of France?", "The population of China is over 1.4 billion people."],
["What is the population of China?", "Paris is the capital of France."],
["What is the population of China?", "The population of China is over 1.4 billion people."]
] * 100
scores = model.compute_score(pairs, cutoff_layers=[28], compress_ratio=2, compress_layers=[24, 40])
print(scores[:4])
if __name__ == '__main__':
test_base_multi_devices()
print("--------------------------------")
print("Expected Output:")
print("[25.375, 8.734375, 9.8359375, 26.15625]")
@@ -0,0 +1,32 @@
import os
from FlagEmbedding import FlagLLMReranker
def test_base_multi_devices():
model = FlagLLMReranker(
'BAAI/bge-reranker-v2-gemma',
use_fp16=True,
query_instruction_for_rerank="A: ",
passage_instruction_for_rerank="B: ",
devices=["cuda:3", "cuda:4"], # if you don't have GPUs, you can use ["cpu", "cpu"]
cache_dir=os.getenv('HF_HUB_CACHE', None),
)
pairs = [
["What is the capital of France?", "Paris is the capital of France."],
["What is the capital of France?", "The population of China is over 1.4 billion people."],
["What is the population of China?", "Paris is the capital of France."],
["What is the population of China?", "The population of China is over 1.4 billion people."]
] * 100
scores = model.compute_score(pairs)
print(scores[:4])
if __name__ == '__main__':
test_base_multi_devices()
print("--------------------------------")
print("Expected Output:")
print("[ 9.1484375 -4.50390625 -5.53125 10.21875 ]")
@@ -0,0 +1,32 @@
import os
from FlagEmbedding import FlagLLMReranker
def test_base_multi_devices():
model = FlagLLMReranker(
'BAAI/bge-reranker-v2-gemma',
use_fp16=True,
query_instruction_for_rerank="A: ",
passage_instruction_for_rerank="B: ",
devices=["cuda:3"], # if you don't have GPUs, you can use ["cpu", "cpu"]
cache_dir=os.getenv('HF_HUB_CACHE', None),
)
pairs = [
["What is the capital of France?", "Paris is the capital of France."],
["What is the capital of France?", "The population of China is over 1.4 billion people."],
["What is the population of China?", "Paris is the capital of France."],
["What is the population of China?", "The population of China is over 1.4 billion people."]
] * 100
scores = model.compute_score(pairs)
print(scores[:4])
if __name__ == '__main__':
test_base_multi_devices()
print("--------------------------------")
print("Expected Output:")
print("[9.171875, -4.49609375, -5.5234375, 10.2109375]")
@@ -0,0 +1,33 @@
import os
from FlagEmbedding import LayerWiseFlagLLMReranker
def test_base_multi_devices():
model = LayerWiseFlagLLMReranker(
'BAAI/bge-reranker-v2-minicpm-layerwise',
use_fp16=True,
query_instruction_for_rerank="A: ",
passage_instruction_for_rerank="B: ",
trust_remote_code=True,
devices=["cuda:3"], # if you don't have GPUs, you can use ["cpu", "cpu"]
cache_dir=os.getenv('HF_HUB_CACHE', None),
)
pairs = [
["What is the capital of France?", "Paris is the capital of France."],
["What is the capital of France?", "The population of China is over 1.4 billion people."],
["What is the population of China?", "Paris is the capital of France."],
["What is the population of China?", "The population of China is over 1.4 billion people."]
] * 100
scores = model.compute_score(pairs, cutoff_layers=[28])
print(scores[:4])
if __name__ == '__main__':
test_base_multi_devices()
print("--------------------------------")
print("Expected Output:")
print("[1.939453125, -12.71875, -11.78125, 2.189453125]")
@@ -0,0 +1,33 @@
import os
from FlagEmbedding import LayerWiseFlagLLMReranker
def test_base_multi_devices():
model = LayerWiseFlagLLMReranker(
'BAAI/bge-reranker-v2-minicpm-layerwise',
use_fp16=True,
query_instruction_for_rerank="A: ",
passage_instruction_for_rerank="B: ",
trust_remote_code=True,
devices=["cuda:3"], # if you don't have GPUs, you can use ["cpu", "cpu"]
cache_dir=os.getenv('HF_HUB_CACHE', None),
)
pairs = [
["What is the capital of France?", "Paris is the capital of France."],
["What is the capital of France?", "The population of China is over 1.4 billion people."],
["What is the population of China?", "Paris is the capital of France."],
["What is the population of China?", "The population of China is over 1.4 billion people."]
] * 100
scores = model.compute_score(pairs, cutoff_layers=[28])
print(scores[:4])
if __name__ == '__main__':
test_base_multi_devices()
print("--------------------------------")
print("Expected Output:")
print("[1.939453125, -12.71875, -11.78125, 2.189453125]")
@@ -0,0 +1,33 @@
import os
from FlagEmbedding import LightWeightFlagLLMReranker
def test_base_multi_devices():
model = LightWeightFlagLLMReranker(
'BAAI/bge-reranker-v2.5-gemma2-lightweight',
use_fp16=True,
query_instruction_for_rerank="A: ",
passage_instruction_for_rerank="B: ",
trust_remote_code=True,
devices=["cuda:3", "cuda:4"], # if you don't have GPUs, you can use ["cpu", "cpu"]
cache_dir=os.getenv('HF_HUB_CACHE', None),
)
pairs = [
["What is the capital of France?", "Paris is the capital of France."],
["What is the capital of France?", "The population of China is over 1.4 billion people."],
["What is the population of China?", "Paris is the capital of France."],
["What is the population of China?", "The population of China is over 1.4 billion people."]
] * 100
scores = model.compute_score(pairs, cutoff_layers=[28], compress_ratio=2, compress_layers=[24, 40])
print(scores[:4])
if __name__ == '__main__':
test_base_multi_devices()
print("--------------------------------")
print("Expected Output:")
print("[25.375, 8.734375, 9.8359375, 26.15625]")
@@ -0,0 +1,33 @@
import os
from FlagEmbedding import LightWeightFlagLLMReranker
def test_base_multi_devices():
model = LightWeightFlagLLMReranker(
'BAAI/bge-reranker-v2.5-gemma2-lightweight',
use_fp16=True,
query_instruction_for_rerank="A: ",
passage_instruction_for_rerank="B: ",
trust_remote_code=True,
devices=["cuda:3"], # if you don't have GPUs, you can use ["cpu", "cpu"]
cache_dir=os.getenv('HF_HUB_CACHE', None),
)
pairs = [
["What is the capital of France?", "Paris is the capital of France."],
["What is the capital of France?", "The population of China is over 1.4 billion people."],
["What is the population of China?", "Paris is the capital of France."],
["What is the population of China?", "The population of China is over 1.4 billion people."]
] * 100
scores = model.compute_score(pairs, cutoff_layers=[28], compress_ratio=2, compress_layers=[24, 40])
print(scores[:4])
if __name__ == '__main__':
test_base_multi_devices()
print("--------------------------------")
print("Expected Output:")
print("[25.375, 8.734375, 9.8359375, 26.15625]")