Repository navigation
Expand file tree
/
Copy pathtest.py
More file actions
57 lines (51 loc) · 2.84 KB
/
Copy pathtest.py
File metadata and controls
57 lines (51 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from FlagEmbedding import FlagReranker, FlagLLMReranker, LayerWiseFlagLLMReranker
import time
import torch
print('\n ---------using bge-reranker-gemma--------\n')
starttime = time.time()
reranker_gemma = FlagLLMReranker('/data/disk2/zhangzh/models/BAAI/bge-reranker-v2-gemma',use_fp16=True)
time1 = time.time()
scores1 = reranker_gemma.compute_score([['what is panda?', 'hi'], ['what is panda?', 'The giant panda (Ailuropoda melanoleuca), sometimes called a panda bear or simply panda, is a bear species endemic to China.']],normalize=True)
# print(f"Gmem: {torch.cuda.memory_allocated()/ 1024**3:.2f} GB")
time2 = time.time()
print(f"gemma_scores:{scores1}")
load_time1 = round(time1 - starttime, 3)
run_time1 = round(time2 - time1, 3)
print(f'load_time:{load_time1}')
print(f'run_time:{run_time1}')
print('\n --------using bge-reranker-minicpm--------\n')
time5 = time.time()
reranker_LayerWise = LayerWiseFlagLLMReranker('/data/disk2/zhangzh/models/BAAI/bge-reranker-v2-minicpm-layerwise', use_fp16=True)
time3 = time.time()
scores2 = reranker_LayerWise.compute_score([['what is panda?', 'hi'], ['what is panda?', 'The giant panda (Ailuropoda melanoleuca), sometimes called a panda bear or simply panda, is a bear species endemic to China.']], cutoff_layers=[28], normalize=True)
# print(f"Gmem: {torch.cuda.memory_allocated()/ 1024**3:.2f} GB")
time4 = time.time()
print(f"minicpm_scores:{scores2}")
load_time2 = round(time3-time5, 3)
run_time2 = round(time4 - time3, 3)
print(f'load_time:{load_time2}')
print(f'run_time:{run_time2}')
time6 = time.time()
print('\n --------using bge-reranker-m3--------\n')
reranker_m3 = FlagReranker('/data/disk2/zhangzh/models/BAAI/bge-reranker-v2-m3', use_fp16=True)
time7 = time.time()
scores3 = reranker_m3.compute_score([['what is panda?', 'hi'], ['what is panda?', 'The giant panda (Ailuropoda melanoleuca), sometimes called a panda bear or simply panda, is a bear species endemic to China.']], normalize=True)
# print(f"Gmem: {torch.cuda.memory_allocated()/ 1024**3:.2f} GB")
time8 = time.time()
print(f"m3_scores:{scores3}")
load_time3 = round(time7-time6, 3)
run_time3 = round(time8 - time7, 3)
print(f'load_time:{load_time3}')
print(f'run_time:{run_time3}')
time9 = time.time()
print('\n --------using bge-reranker-large--------\n')
reranker_large = FlagReranker('/data/disk2/zhangzh/models/BAAI/bge-reranker-large', use_fp16=True)
time10 = time.time()
scores3 = reranker_large.compute_score([['what is panda?', 'hi'], ['what is panda?', 'The giant panda (Ailuropoda melanoleuca), sometimes called a panda bear or simply panda, is a bear species endemic to China.']], normalize=True)
# print(f"Gmem: {torch.cuda.memory_allocated()/ 1024**3:.2f} GB")
time11 = time.time()
print(f"reranker_large_scores:{scores3}")
load_time4 = round(time10-time9, 3)
run_time4 = round(time11 - time10, 3)
print(f'load_time:{load_time4}')
print(f'run_time:{run_time4}')