-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_questqe.py
65 lines (51 loc) · 1.41 KB
/
test_questqe.py
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
58
59
60
61
62
63
64
65
from langchain.prompts import PromptTemplate
from quest.model.vllm import VLLM
from quest.core import Quest
from quest.proposal import SuffixProposal
from quest.index import Uniform
from quest.reward.mt import QEModel
import os
def integrated_test():
template = PromptTemplate.from_template(
"Translate this from {source_language} to {target_language}:\n{source_language}: {source_sentence}\n{target_language}:"
)
test_input_data = [
{
"source_language": "English",
"target_language": "French",
"source_sentence": "Hello, how are you?",
}
]
sources = [
data["source_sentence"]
for data in test_input_data
]
model = VLLM(
model_path="haoranxu/ALMA-7B",
prompt_template=template,
download_dir=os.environ.get(
"HF_HOME", "/tmp/"
),
gpu_memory_utilization=0.6,
)
reward = QEModel(
"Unbabel/wmt23-cometkiwi-da"
) # sentiment model.
reward.set_sources(
sources
) # QE model requires sources to be set.
index = Uniform()
chain = Quest(
input_data=test_input_data,
reward=reward,
proposal=SuffixProposal(
model=model, dist=index
),
)
chain_outputs = chain.run(
steps=10,
use_tqdm=True,
)
print(chain_outputs.samples)
integrated_test()
print("passed all tests")