|
20 | 20 |
|
21 | 21 | from transformers import AutoModelForCausalLM, AutoTokenizer, RecurrentGemmaConfig, is_torch_available, set_seed |
22 | 22 | from transformers.testing_utils import ( |
| 23 | + Expectations, |
23 | 24 | require_bitsandbytes, |
24 | 25 | require_read_token, |
25 | 26 | require_torch, |
@@ -215,20 +216,30 @@ def test_2b_generate(self): |
215 | 216 | @require_read_token |
216 | 217 | def test_2b_sample(self): |
217 | 218 | set_seed(0) |
218 | | - EXPECTED_TEXT = ['Where is Paris ?\n\nChoose the word or phrase that is closest in meaning to the word in capital letters.\n\nREDEEM\n(A) sort out\n(B) think over\n(C) turn in\n(D) take back\n\nWrite the correct word in the space next to each definition. Use each word only once.\n\nto badly damage\n\nOn the lines provided below, write <em>P</em> if the underlined word group is a phrase and <em>NP</em> if it is not a phrase. Example $\\underline{\\text{P}}$ 1. We have finally discovered the secret $\\underline{\\text{of delicious pizza. }}$'] # fmt: skip |
| 219 | + expectations = Expectations( |
| 220 | + { |
| 221 | + (None, None): [ |
| 222 | + "What is Deep learning ?\n\nDeep learning is the next frontier in computer vision. It is an Artificial Intelligence (AI) discipline that is rapidly being adopted across industries. The success of Deep" |
| 223 | + ], |
| 224 | + ("cuda", 8): [ |
| 225 | + "What is Deep learning ?\n\nDeep learning is the next frontier in computer vision, it’s an incredibly powerful branch of artificial intelligence.\n\nWhat is Dalle?\n\nDalle is", |
| 226 | + ], |
| 227 | + } |
| 228 | + ) |
| 229 | + EXPECTED_TEXT = expectations.get_expectation() |
219 | 230 | model = AutoModelForCausalLM.from_pretrained(self.model_id).to(torch_device) |
220 | 231 |
|
221 | 232 | tokenizer = AutoTokenizer.from_pretrained(self.model_id) |
222 | | - inputs = tokenizer("Where is Paris ?", return_tensors="pt", padding=True).to(torch_device) |
223 | | - output = model.generate(**inputs, max_new_tokens=128, do_sample=True) |
| 233 | + inputs = tokenizer("What is Deep learning ?", return_tensors="pt", padding=True).to(torch_device) |
| 234 | + output = model.generate(**inputs, max_new_tokens=32, do_sample=True) |
224 | 235 | output_text = tokenizer.batch_decode(output, skip_special_tokens=True) |
225 | 236 |
|
226 | 237 | self.assertEqual(output_text, EXPECTED_TEXT) |
227 | 238 |
|
228 | 239 | @require_bitsandbytes |
229 | 240 | @require_read_token |
230 | 241 | def test_model_2b_8bit(self): |
231 | | - EXPECTED_TEXTS = ['Hello I am doing a project on the topic of "The impact of the internet on the society" and I am looking', "Hi today I'm going to show you how to make a simple and easy to make a simple and easy"] # fmt: skip |
| 242 | + EXPECTED_TEXTS = ['Hello I am doing a project on the topic of "The impact of social media on the society" and I am looking', "Hi today I'm going to show you how to make a simple and easy to make a 3D"] # fmt: skip |
232 | 243 |
|
233 | 244 | model = AutoModelForCausalLM.from_pretrained( |
234 | 245 | "gg-hf/recurrent-gemma-2b-hf", device_map={"": torch_device}, load_in_8bit=True, torch_dtype=torch.bfloat16 |
|
0 commit comments