|
14 | 14 | # limitations under the License.
|
15 | 15 | """
|
16 | 16 |
|
| 17 | +import copy |
17 | 18 | import os
|
18 | 19 | import unittest
|
19 | 20 | import weakref
|
@@ -120,6 +121,48 @@ def test_multiple_sampling_params(self):
|
120 | 121 | outputs = self.llm.generate(prompts=self.PROMPTS, sampling_params=None)
|
121 | 122 | self.assertEqual(len(self.PROMPTS), len(outputs))
|
122 | 123 |
|
| 124 | + def test_consistency_single_prompt_tokens_chat(self): |
| 125 | + """Test consistency between different prompt input formats""" |
| 126 | + sampling_params = SamplingParams(temperature=1.0, top_p=0.0) |
| 127 | + |
| 128 | + for prompt_token_ids in self.TOKEN_IDS: |
| 129 | + with self.subTest(prompt_token_ids=prompt_token_ids): |
| 130 | + output1 = self.llm.chat(messages=[prompt_token_ids], sampling_params=sampling_params) |
| 131 | + output2 = self.llm.chat( |
| 132 | + [{"prompt": "", "prompt_token_ids": prompt_token_ids}], sampling_params=sampling_params |
| 133 | + ) |
| 134 | + self.assert_outputs_equal(output1, output2) |
| 135 | + |
| 136 | + def test_multiple_sampling_params_chat(self): |
| 137 | + """Test multiple sampling parameters combinations""" |
| 138 | + sampling_params = [ |
| 139 | + SamplingParams(temperature=0.01, top_p=0.95), |
| 140 | + SamplingParams(temperature=0.3, top_p=0.95), |
| 141 | + SamplingParams(temperature=0.7, top_p=0.95), |
| 142 | + SamplingParams(temperature=0.99, top_p=0.95), |
| 143 | + ] |
| 144 | + |
| 145 | + prompts = copy.copy(self.PROMPTS) |
| 146 | + # Multiple SamplingParams should be matched with each prompt |
| 147 | + outputs = self.llm.chat(messages=prompts, sampling_params=sampling_params) |
| 148 | + self.assertEqual(len(self.PROMPTS), len(outputs)) |
| 149 | + |
| 150 | + prompts = copy.copy(self.PROMPTS) |
| 151 | + # Exception raised if size mismatch |
| 152 | + with self.assertRaises(ValueError): |
| 153 | + self.llm.chat(messages=prompts, sampling_params=sampling_params[:3]) |
| 154 | + |
| 155 | + prompts = copy.copy(self.PROMPTS) |
| 156 | + # Single SamplingParams should be applied to every prompt |
| 157 | + single_sampling_params = SamplingParams(temperature=0.3, top_p=0.95) |
| 158 | + outputs = self.llm.chat(messages=prompts, sampling_params=single_sampling_params) |
| 159 | + self.assertEqual(len(self.PROMPTS), len(outputs)) |
| 160 | + |
| 161 | + prompts = copy.copy(self.PROMPTS) |
| 162 | + # sampling_params is None, default params should be applied |
| 163 | + outputs = self.llm.chat(messages=prompts, sampling_params=None) |
| 164 | + self.assertEqual(len(self.PROMPTS), len(outputs)) |
| 165 | + |
123 | 166 |
|
124 | 167 | if __name__ == "__main__":
|
125 | 168 | unittest.main()
|
0 commit comments