slimfrikha abdalgader commited on
Commit
bd8d2e7
·
verified ·
1 Parent(s): cb3354e

delete test file (#12)

Browse files

- delete test file (85011d87470197f5712603fe27484293d54e6047)


Co-authored-by: Abdalgader Abubaker <abdalgader@users.noreply.huggingface.co>

Files changed (1) hide show
  1. test.py +0 -93
test.py DELETED
@@ -1,93 +0,0 @@
1
- import os
2
- import random
3
-
4
- # Set environment variables FIRST, before any other imports
5
- os.environ["PYTHONHASHSEED"] = "42"
6
- os.environ["CUBLAS_WORKSPACE_CONFIG"] = ":16:8"
7
- os.environ["TOKENIZERS_PARALLELISM"] = "false"
8
-
9
- from pathlib import Path
10
-
11
- import numpy as np
12
- import torch
13
- from tqdm import tqdm
14
- from transformers import AutoTokenizer
15
- from transformers import set_seed as transformers_set_seed
16
- from vllm import LLM, SamplingParams
17
-
18
- current_dir = Path(__file__).parent
19
-
20
-
21
- def set_seed(seed: int = 42):
22
- """Set seed for reproducibility across all libraries"""
23
- random.seed(seed)
24
- np.random.seed(seed)
25
- torch.manual_seed(seed)
26
-
27
- if torch.cuda.is_available():
28
- torch.cuda.manual_seed(seed)
29
- torch.cuda.manual_seed_all(seed)
30
-
31
- transformers_set_seed(seed)
32
- torch.use_deterministic_algorithms(True)
33
- torch.backends.cudnn.deterministic = True
34
- torch.backends.cudnn.benchmark = False
35
-
36
-
37
- def main() -> None:
38
- set_seed(41)
39
- path = "../Falcon-H1R-7B"
40
- tokenizer = AutoTokenizer.from_pretrained(path)
41
- samples = [
42
- "hi",
43
- "what is 1+1?",
44
- "what is the capital of france?",
45
- "who are you?",
46
- "solve 3x+1=0",
47
- "Write a python function that returns the factorial of a number using recursion.",
48
- "A train leaves Station A at 9:00 AM traveling at 60 mph toward Station B. Another train leaves Station B at 10:00 AM traveling at 80 mph toward Station A. If the stations are 280 miles apart, at what time do the trains meet?",
49
- "Find the sum of all integer bases $b>9$ for which $17_b$ is a divisor of $97_b.$",
50
- ]
51
-
52
- # prepare Vllm input
53
- inputs = [
54
- tokenizer.apply_chat_template(
55
- [{"role": "user", "content": sample}],
56
- tokenize=False,
57
- add_generation_prompt=True,
58
- )
59
- # + "<think>\n</think>\n"
60
- for sample in tqdm(samples)
61
- ]
62
-
63
- # Load model in vllm
64
- llm_kwargs = {
65
- "model": path,
66
- "trust_remote_code": True,
67
- "tensor_parallel_size": 2,
68
- }
69
- llm = LLM(**llm_kwargs)
70
-
71
- # Sampling params
72
- gen_kwargs = {
73
- "max_tokens": 32768,
74
- "temperature": 0.6,
75
- "top_p": 0.95,
76
- "stop": ["<|endoftext|>", "<|im_end|>", "</s>", "<|eot_id|>", "<|end|>"],
77
- }
78
- sampling_params = SamplingParams(**gen_kwargs)
79
-
80
- # generate
81
- outputs = llm.generate(inputs, sampling_params)
82
- generated_texts = [output.outputs[0].text for output in outputs]
83
-
84
- # display
85
- for sample, generated_text in zip(samples, generated_texts):
86
- print("User:")
87
- print(sample)
88
- print("Assisant:")
89
- print(generated_text)
90
- print("-" * 50)
91
-
92
-
93
- main()