Yeyito commited on
Commit
8ea42fc
1 Parent(s): d649c17

Functional

Browse files
.gitignore CHANGED
@@ -1,4 +1,4 @@
1
  Environment/
2
  out/
3
  flagged/
4
-
 
1
  Environment/
2
  out/
3
  flagged/
4
+ Evaluations/
app.py CHANGED
@@ -2,6 +2,9 @@ import gradio as gr
2
  import subprocess
3
  import os
4
  import sys
 
 
 
5
 
6
  # Add the path to the "src" directory of detect-pretrain-code-contamination to the sys.path
7
  project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), "detect-pretrain-code-contamination"))
@@ -9,17 +12,300 @@ src_dir = os.path.join(project_root, "src")
9
  sys.path.insert(0, src_dir)
10
 
11
  import run as evaluator # Import the run module
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
- def evaluate(model):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  return evaluator.main(
15
- target_model="roneneldan/TinyStories-1M",
16
- ref_model="roneneldan/TinyStories-Instruct-1M",
17
  output_dir="out",
18
- data="truthful_qa",
19
  length=64,
20
  key_name="input",
21
  ratio_gen=0.4
22
- ) # Call the run_main function directly
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
 
24
- iface = gr.Interface(fn=evaluate, inputs="text", outputs="text")
25
- iface.launch()
 
2
  import subprocess
3
  import os
4
  import sys
5
+ import time
6
+ import pandas as pd
7
+ from threading import Thread
8
 
9
  # Add the path to the "src" directory of detect-pretrain-code-contamination to the sys.path
10
  project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), "detect-pretrain-code-contamination"))
 
12
  sys.path.insert(0, src_dir)
13
 
14
  import run as evaluator # Import the run module
15
+ from src.css_html import custom_css
16
+ from src.text_content import ABOUT_TEXT, SUBMISSION_TEXT, SUBMISSION_TEXT_2
17
+ from src.envs import API, H4_TOKEN, REPO_ID
18
+ from huggingface_hub import HfApi
19
+ from src.utils import (
20
+ AutoEvalColumn,
21
+ fields,
22
+ is_model_on_hub,
23
+ make_clickable_names,
24
+ styled_error,
25
+ styled_message,
26
+ )
27
 
28
+ COLS = [c.name for c in fields(AutoEvalColumn) if not c.hidden]
29
+ TYPES = [c.type for c in fields(AutoEvalColumn) if not c.hidden]
30
+ COLS_LITE = [c.name for c in fields(AutoEvalColumn) if c.displayed_by_default and not c.hidden]
31
+ TYPES_LITE = [c.type for c in fields(AutoEvalColumn) if c.displayed_by_default and not c.hidden]
32
+
33
+ # CONFIGURATION:
34
+ ref_model = "huggyllama/llama-7b"
35
+ test_datasets = ["truthful_qa","cais/mmlu","ai2_arc","gsm8k","Rowan/hellaswag","winogrande"]
36
+ modelQueue = []
37
+
38
+ def restart_space(): #Most dumbest update function to ever exist, I'm sobbing in tears as I've tried to make gradio update the leaderboard literally any other way.
39
+ API.restart_space(repo_id=REPO_ID, token=H4_TOKEN)
40
+
41
+
42
+ def save_to_txt(model, results, model_type):
43
+ file_path = "data/code_eval_board.csv"
44
+
45
+ with open(file_path, "a") as f:
46
+ f.write(f"\n{model_type},{model}," + str(results["arc"]) + "," + str(results["hellaswag"]) + "," + str(results["mmlu"]) + "," + str(results["truthfulQA"]) + "," + str(results["winogrande"]) + "," + str(results["gsm8k"]))
47
+ f.close()
48
+
49
+ restart_space()
50
+
51
+ def run_test(model,ref_model,data):
52
+ print(f"|| TESTING {data} ||")
53
  return evaluator.main(
54
+ target_model=f"{model}",
55
+ ref_model=f"{ref_model}",
56
  output_dir="out",
57
+ data=f"{data}",
58
  length=64,
59
  key_name="input",
60
  ratio_gen=0.4
61
+ ) # Call the main function in detect-pretrain-code-contamination/src/run.py
62
+
63
+ def evaluate(model,model_type):
64
+ global ref_model
65
+ print(f"|| EVALUATING {model} ||")
66
+ results = {
67
+ "arc": run_test(model, ref_model, test_datasets[2]),
68
+ "hellaswag": run_test(model, ref_model, test_datasets[4]),
69
+ "mmlu": run_test(model, ref_model, test_datasets[1]),
70
+ "truthfulQA": run_test(model, ref_model, test_datasets[0]),
71
+ "winogrande": run_test(model, ref_model, test_datasets[5]),
72
+ "gsm8k": run_test(model, ref_model, test_datasets[3]),
73
+ "ref_model": ref_model,
74
+ }
75
+
76
+ # Save to .txt file in /Evaluations/{model}
77
+ save_to_txt(model, results, model_type)
78
+ return "\n".join([f"{k}:{results[k]}" for k in results])
79
+
80
+ def worker_thread():
81
+ global modelQueue, server
82
+ while True:
83
+ for submission in modelQueue:
84
+ evaluate(submission[0],submission[1].split(" ")[0])
85
+ modelQueue.pop(modelQueue.index(submission))
86
+ time.sleep(1)
87
+ time.sleep(1)
88
+
89
+ def queue(model,model_type):
90
+ global modelQueue
91
+ modelQueue.append([model,model_type])
92
+ print(f"QUEUE:\n{modelQueue}")
93
+
94
+
95
+ ### bigcode/bigcode-models-leaderboard
96
+ def add_new_eval(
97
+ model: str,
98
+ revision: str,
99
+ precision: str,
100
+ model_type: str,
101
+ ):
102
+ precision = precision
103
+
104
+ if model_type is None or model_type == "" or model_type == []:
105
+ return styled_error("Please select a model type.")
106
+ print(model_type)
107
+ # check the model actually exists before adding the eval
108
+ if revision == "":
109
+ revision = "main"
110
+
111
+ model_on_hub, error = is_model_on_hub(model, revision)
112
+ if not model_on_hub:
113
+ return styled_error(f'Model "{model}" {error}')
114
+
115
+ print("Adding new eval")
116
+ queue(model,model_type)
117
+ return styled_message("Your request has been submitted to the evaluation queue!\n")
118
+
119
+ def select_columns(df, columns):
120
+ always_here_cols = [
121
+ AutoEvalColumn.model_type_symbol.name,
122
+ AutoEvalColumn.model.name,
123
+ ]
124
+ # We use COLS to maintain sorting
125
+ filtered_df = df[
126
+ always_here_cols + [c for c in COLS if c in df.columns and c in columns]
127
+ ]
128
+ return filtered_df
129
+
130
+
131
+ def filter_items(df, leaderboard_table, query):
132
+ if query == "All":
133
+ return df[leaderboard_table.columns]
134
+ else:
135
+ query = query[0] # take only the emoji character
136
+ filtered_df = df[(df["T"] == query)]
137
+ return filtered_df[leaderboard_table.columns]
138
+
139
+ def search_table(df, leaderboard_table, query):
140
+ filtered_df = df[(df["Models"].str.contains(query, case=False))]
141
+ return filtered_df[leaderboard_table.columns]
142
+
143
+ demo = gr.Blocks(css=custom_css)
144
+ with demo:
145
+ with gr.Row():
146
+ gr.Markdown(
147
+ """<div style="text-align: center;"><h1> 📄 LLM Contamination Detector </h1></div>\
148
+ <br>\
149
+ <p>Inspired from the <a href="https://huggingface.co/spaces/HuggingFaceH4/open_llm_leaderboard">🤗 Open LLM Leaderboard</a> and <a href="https://huggingface.co/spaces/bigcode/bigcode-models-leaderboard">🤗 Big Code Models Leaderboard ⭐</a>, we use an implementation of <a href="https://huggingface.co/papers/2310.16789">Detecting Pretraining Data from Large Language Models</a> paper found in <a href="https://github.com/swj0419/detect-pretrain-code-contamination/tree/master">this github repo</a>, to provide contamination scores for LLMs on the datasets used by Open LLM Leaderboard.\
150
+ This space should NOT be used to flag or accuse models of cheating / being contamined, instead, it should form part of a holistic assesment by the parties involved.</p>""",
151
+ elem_classes="markdown-text",
152
+ )
153
+
154
+ with gr.Tabs(elem_classes="tab-buttons") as tabs:
155
+ with gr.Column():
156
+ with gr.Tabs(elem_classes="A100-tabs") as A100_tabs:
157
+ with gr.TabItem("🔍 Evaluations", id=0):
158
+ with gr.Column():
159
+ with gr.Accordion("➡️ See filters", open=False):
160
+ shown_columns = gr.CheckboxGroup(
161
+ choices=[
162
+ c
163
+ for c in COLS
164
+ if c
165
+ not in [
166
+ AutoEvalColumn.dummy.name,
167
+ AutoEvalColumn.model.name,
168
+ AutoEvalColumn.model_type_symbol.name,
169
+ ]
170
+ ],
171
+ value=[
172
+ c
173
+ for c in COLS_LITE
174
+ if c
175
+ not in [
176
+ AutoEvalColumn.dummy.name,
177
+ AutoEvalColumn.model.name,
178
+ AutoEvalColumn.model_type_symbol.name,
179
+ ]
180
+ ],
181
+ label="",
182
+ elem_id="column-select",
183
+ interactive=True,
184
+ )
185
+ # with gr.Column(min_width=780):
186
+ with gr.Row():
187
+ search_bar = gr.Textbox(
188
+ placeholder="🔍 Search for a model and press ENTER...",
189
+ show_label=False,
190
+ elem_id="search-bar",
191
+ )
192
+ filter_columns = gr.Radio(
193
+ label="⏚ Filter model types",
194
+ choices=["All", "🟢 Base", "🔶 Finetuned"],
195
+ value="All",
196
+ elem_id="filter-columns",
197
+ )
198
+
199
+ df = pd.read_csv("data/code_eval_board.csv")
200
+ leaderboard_df = gr.components.Dataframe(
201
+ value=df[
202
+ [
203
+ AutoEvalColumn.model_type_symbol.name,
204
+ AutoEvalColumn.model.name,
205
+ ]
206
+ + shown_columns.value
207
+ ],
208
+ headers=[
209
+ AutoEvalColumn.model_type_symbol.name,
210
+ AutoEvalColumn.model.name,
211
+ ]
212
+ + shown_columns.value,
213
+ datatype=TYPES,
214
+ elem_id="leaderboard-table",
215
+ interactive=False,
216
+ )
217
+
218
+ hidden_leaderboard_df = gr.components.Dataframe(
219
+ value=df,
220
+ headers=COLS,
221
+ datatype=["str" for _ in range(len(COLS))],
222
+ visible=False,
223
+ )
224
+
225
+ search_bar.submit(
226
+ search_table,
227
+ [hidden_leaderboard_df, leaderboard_df, search_bar],
228
+ leaderboard_df,
229
+ )
230
+
231
+ filter_columns.change(
232
+ filter_items,
233
+ [hidden_leaderboard_df, leaderboard_df, filter_columns],
234
+ leaderboard_df,
235
+ )
236
+
237
+ shown_columns.change(
238
+ select_columns,
239
+ [hidden_leaderboard_df, shown_columns],
240
+ leaderboard_df,
241
+ )
242
+
243
+ gr.Markdown(
244
+ """
245
+ **Notes:**
246
+ - The Huggingface team is working on their own implementation of this paper as a space, I'll be leaving this space up until that's available.
247
+ - Some scores may not be entirely accurate according to the paper cited as I still work out the kinks and innacuracies of this implementation.
248
+ - For any issues, questions, or comments either open a discussion in this space's community tab or message me directly to my discord: yeyito777.
249
+ - Make sure to check the pinned discussion in this space's community tab for implementation details I'm not 100% about.
250
+ """,
251
+ elem_classes="markdown-text",
252
+ )
253
+
254
+ with gr.TabItem("📝 About", id=2):
255
+ gr.Markdown(ABOUT_TEXT, elem_classes="markdown-text")
256
+ with gr.TabItem("🛠️ Submit models", id=3):
257
+ gr.Markdown(SUBMISSION_TEXT)
258
+ gr.Markdown(
259
+ "## 📤 Submit a model here:", elem_classes="markdown-text"
260
+ )
261
+ with gr.Column():
262
+ with gr.Row():
263
+ model_name = gr.Textbox(label="Model name")
264
+ revision_name = gr.Textbox(
265
+ label="revision", placeholder="main"
266
+ )
267
+ with gr.Row():
268
+ precision = gr.Dropdown(
269
+ choices=[
270
+ "float16",
271
+ "bfloat16",
272
+ "8bit",
273
+ "4bit",
274
+ ],
275
+ label="Precision",
276
+ multiselect=False,
277
+ value="float16",
278
+ interactive=True,
279
+ )
280
+ model_type = gr.Dropdown(
281
+ choices=["🟢 base", "🔶 instruction-tuned"],
282
+ label="Model type",
283
+ multiselect=False,
284
+ value=None,
285
+ interactive=True,
286
+ )
287
+ submit_button = gr.Button("Submit Eval")
288
+ submission_result = gr.Markdown()
289
+ submit_button.click(
290
+ add_new_eval,
291
+ inputs=[model_name, revision_name, precision, model_type],
292
+ outputs=[submission_result],
293
+ )
294
+ gr.Markdown(SUBMISSION_TEXT_2)
295
+
296
+ thread = Thread(target=worker_thread)
297
+ thread.start()
298
+ demo.launch()
299
+
300
+ # Some worries:
301
+ # 1. Am I testing things correctly in eval.py, following the template format?
302
+
303
+ # 2. Am I choosing the correct splits in run.py? The higherarchy I use is: test > val > train
304
+ # (As in: if test exists, I go with that, then validation, then default)
305
+
306
+ # 3. I decided to go with winogrande_debiased instead of winogrande_l arbitrarily.
307
+ # (Not sure which one open llm leaderboard uses, or what is the standard)
308
+
309
+ # 4. I'm unsure why in eval.py we append the output at the end of the input.
310
 
311
+ # 5. Currently I'm using huggyllama/llama-7b as ref_model, should I switch to llama2-7B? Maybe Mistral-7B?
 
data/code_eval_board.csv ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ T,Models,ARC,HellaSwag,MMLU,TruthfulQA,Winogrande,GSM8K
2
+ 🟢,roneneldan/TinyStories-1M,0.1 % 0.1,0.1 % 0.1,0.1 % 0.1,0.1 % 0.1,0.1 % 0.1,0.1 % 0.1
requirements.txt CHANGED
@@ -8,3 +8,4 @@ matplotlib
8
  scikit-learn
9
  accelerate
10
  gradio
 
 
8
  scikit-learn
9
  accelerate
10
  gradio
11
+ plotly
src/__pycache__/css_html.cpython-311.pyc ADDED
Binary file (1.46 kB). View file
 
src/__pycache__/envs.cpython-311.pyc ADDED
Binary file (496 Bytes). View file
 
src/__pycache__/text_content.cpython-311.pyc ADDED
Binary file (2.07 kB). View file
 
src/__pycache__/utils.cpython-311.pyc ADDED
Binary file (5.02 kB). View file
 
src/add_json_csv.py ADDED
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import pandas as pd
3
+ from utils import model_hyperlink
4
+
5
+ def add_model_readme(df):
6
+ # write model ids to README.md
7
+ with open("README.md", "r") as f:
8
+ lines = f.readlines()
9
+
10
+ links = df["Links"].astype(str)
11
+ for link in links:
12
+ try:
13
+ model_id = link.split(".co/")[1]
14
+ # verify line doesn't exist
15
+ if f"- {model_id}\n" in lines:
16
+ continue
17
+ lines.insert(-1, f"- {model_id}\n")
18
+ except IndexError:
19
+ print(f"link {link} is not valid")
20
+
21
+ with open("README.md", "w") as f:
22
+ f.writelines(lines)
23
+
24
+ df = pd.read_csv("data/raw_scores.csv")
25
+ COLS = df.columns.to_list()
26
+ # add column models_query with same values a smodels at the end of columns
27
+ df.insert(len(COLS), "models_query", df["Models"])
28
+ print(f"all cols {df.columns.to_list()}")
29
+ # average score
30
+ mean_columns = df.iloc[:,5:-3]
31
+ # print cols in mean_columns
32
+ print("cols", mean_columns.columns.to_list())
33
+ df.insert(len(mean_columns.columns.to_list()), "Average score", mean_columns.mean(axis=1).round(2))
34
+
35
+ # add win rate columns for each language
36
+ old_size = len(df.columns)
37
+
38
+ for col in df.columns[6:-2]:
39
+ df[col + " rank"] = df[col].rank(ascending=False)
40
+ df[col + " rank"] = len(df) - (df[col + " rank"] - 1)
41
+ df["Win Rate"] = df.iloc[:, old_size:].mean(axis=1).round(2)
42
+ df = df.drop(df.columns[old_size:-1], axis=1)
43
+ df = df[["Models", "Size (B)", "Win Rate"] + df.columns[2:-1].tolist()]
44
+
45
+ # sort with regard to column win rate
46
+ df = df.sort_values(by=["Win Rate"], ascending=False)
47
+ # add column with model links as https://huggingface.co/WizardLM/WizardCoder-15B-V1.0, https://huggingface.co/bigcode/starcoder, https://huggingface.co/bigcode/starcoderbase, https://huggingface.co/bigcode/starcoderbase-7b,
48
+ # https://huggingface.co/bigcode/starcoderbase-3b, https://huggingface.co/bigcode/starcoderbase-1b, https://huggingface.co/bigcode/santacoder, https://huggingface.co/replit/replit-code-v1-3b, https://huggingface.co/THUDM/codegeex2-6b
49
+
50
+ links = {
51
+ "WizardCoder-15B-V1.0": "https://huggingface.co/WizardLM/WizardCoder-15B-V1.0",
52
+ "WizardCoder-3B-V1.0": "https://huggingface.co/WizardLM/WizardCoder-3B-V1.0",
53
+ "WizardCoder-1B-V1.0": "https://huggingface.co/WizardLM/WizardCoder-1B-V1.0",
54
+ "WizardCoder-Python-34B-V1.0": "https://huggingface.co/WizardLM/WizardCoder-Python-34B-V1.0",
55
+ "WizardCoder-Python-13B-V1.0": "https://huggingface.co/WizardLM/WizardCoder-Python-13B-V1.0",
56
+ "OctoCoder-15B": "https://huggingface.co/bigcode/octocoder",
57
+ "OctoGeeX-7B": "https://huggingface.co/bigcode/octogeex",
58
+ "StableCode-3B": "https://huggingface.co/stabilityai/stablecode-completion-alpha-3b",
59
+ "StarCoder-15B": "https://huggingface.co/bigcode/starcoder",
60
+ "StarCoderBase-15B": "https://huggingface.co/bigcode/starcoderbase",
61
+ "StarCoderBase-7B": "https://huggingface.co/bigcode/starcoderbase-7b",
62
+ "StarCoderBase-3B": "https://huggingface.co/bigcode/starcoderbase-3b",
63
+ "StarCoderBase-1.1B": "https://huggingface.co/bigcode/starcoderbase-1b",
64
+ "SantaCoder-1.1B": "https://huggingface.co/bigcode/santacoder",
65
+ "Replit-2.7B": "https://huggingface.co/replit/replit-code-v1-3b",
66
+ "CodeGeex2-6B": "https://huggingface.co/THUDM/codegeex2-6b",
67
+ "CodeGen25-7B-multi": "https://huggingface.co/Salesforce/codegen25-7b-multi",
68
+ "CodeGen25-7B-mono": "https://huggingface.co/Salesforce/codegen25-7b-mono",
69
+ "CodeGen-16B-Multi": "https://huggingface.co/Salesforce/codegen-16B-multi",
70
+ "DeciCoder-1B": "https://huggingface.co/Deci/DeciCoder-1b",
71
+ "Phind-CodeLlama-34B-v1": "https://huggingface.co/phind/Phind-CodeLlama-34B-v1",
72
+ "Phind-CodeLlama-34B-Python-v1": "https://huggingface.co/phind/Phind-CodeLlama-34B-Python-v1",
73
+ "Phind-CodeLlama-34B-v2": "https://huggingface.co/phind/Phind-CodeLlama-34B-v2",
74
+ "Falcon-180B": "https://huggingface.co/tiiuae/falcon-180B",
75
+ "Refact-1.6B": "https://huggingface.co/smallcloudai/Refact-1_6B-fim",
76
+ "Phi-1": "https://huggingface.co/microsoft/phi-1",
77
+ "CodeShell-7B": "https://huggingface.co/WisdomShell/CodeShell-7B",
78
+ "DeepSeek-Coder-1b-base": "https://huggingface.co/deepseek-ai/deepseek-coder-1.3b-base",
79
+ "DeepSeek-Coder-7b-base": "https://huggingface.co/deepseek-ai/deepseek-coder-6.7b-base",
80
+ "DeepSeek-Coder-33b-base": "https://huggingface.co/deepseek-ai/deepseek-coder-33b-base",
81
+ }
82
+
83
+ codellamas = ['CodeLlama-7b', 'CodeLlama-7b-Python', 'CodeLlama-7b-Instruct', 'CodeLlama-13b', 'CodeLlama-13b-Python', 'CodeLlama-13b-Instruct', 'CodeLlama-34b', 'CodeLlama-34b-Python', 'CodeLlama-34b-Instruct']
84
+ for codellama in codellamas:
85
+ links[codellama] = f"https://huggingface.co/codellama/{codellama}-hf"
86
+
87
+ df["Links"] = df["Models"].map(links)
88
+
89
+ df.insert(0, "T", "🟢")
90
+ patterns = ["WizardCoder", "Octo", "Instruct", "Phind", "Refact"]
91
+ df.loc[df["Models"].str.contains('|'.join(patterns)), "T"] = "🔶"
92
+ df.loc[df["Models"].str.contains('|'.join(patterns)), "T"] = "🔶"
93
+ df.loc[df["Models"].str.contains('|'.join(["CodeShell", "DeepSeek"])), "T"] = "🔴"
94
+ # add clumn submission_pr with empty fiels except for CodeShell with link AA
95
+ df["Submission PR"] = ""
96
+ df.loc[df["Models"].str.contains('|'.join(["CodeShell"])), "Submission PR"] = "https://huggingface.co/spaces/bigcode/bigcode-models-leaderboard/discussions/16"
97
+ df.loc[df["Models"].str.contains('|'.join(["DeepSeek-Coder-1b-base"])), "Submission PR"] = "https://huggingface.co/spaces/bigcode/bigcode-models-leaderboard/discussions/33"
98
+ df.loc[df["Models"].str.contains('|'.join(["DeepSeek-Coder-7b-base"])), "Submission PR"] = "https://huggingface.co/spaces/bigcode/bigcode-models-leaderboard/discussions/32"
99
+ df.loc[df["Models"].str.contains('|'.join(["DeepSeek-Coder-33b-base"])), "Submission PR"] = "https://huggingface.co/spaces/bigcode/bigcode-models-leaderboard/discussions/31"
100
+
101
+
102
+ # print first 5 rows and 10 cols
103
+ print(df.iloc[:5, :-1])
104
+ df.to_csv("data/code_eval_board.csv", index=False)
105
+
106
+ # fill readme
107
+ add_model_readme(df)
108
+ print("Readme filled")
src/build.py ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ from utils import model_hyperlink
3
+
4
+ def add_model_readme(df):
5
+ # write model ids to README.md
6
+ with open("README.md", "r") as f:
7
+ lines = f.readlines()
8
+
9
+ links = df["Links"].astype(str)
10
+ for link in links:
11
+ try:
12
+ model_id = link.split(".co/")[1]
13
+ # verify line doesn't exist
14
+ if f"- {model_id}\n" in lines:
15
+ continue
16
+ lines.insert(-1, f"- {model_id}\n")
17
+ except IndexError:
18
+ print(f"link {link} is not valid")
19
+
20
+ with open("README.md", "w") as f:
21
+ f.writelines(lines)
22
+
23
+ df = pd.read_csv("data/raw_scores.csv")
24
+ COLS = df.columns.to_list()
25
+ # add column models_query with same values a smodels at the end of columns
26
+ df.insert(len(COLS), "models_query", df["Models"])
27
+ print(f"all cols {df.columns.to_list()}")
28
+ # average score
29
+ mean_columns = df.iloc[:,5:-3]
30
+ # print cols in mean_columns
31
+ print("cols", mean_columns.columns.to_list())
32
+ df.insert(len(mean_columns.columns.to_list()), "Average score", mean_columns.mean(axis=1).round(2))
33
+
34
+ # add win rate columns for each language
35
+ old_size = len(df.columns)
36
+
37
+ for col in df.columns[6:-2]:
38
+ df[col + " rank"] = df[col].rank(ascending=False)
39
+ df[col + " rank"] = len(df) - (df[col + " rank"] - 1)
40
+ df["Win Rate"] = df.iloc[:, old_size:].mean(axis=1).round(2)
41
+ df = df.drop(df.columns[old_size:-1], axis=1)
42
+ df = df[["Models", "Size (B)", "Win Rate"] + df.columns[2:-1].tolist()]
43
+
44
+ # sort with regard to column win rate
45
+ df = df.sort_values(by=["Win Rate"], ascending=False)
46
+ # add column with model links as https://huggingface.co/WizardLM/WizardCoder-15B-V1.0, https://huggingface.co/bigcode/starcoder, https://huggingface.co/bigcode/starcoderbase, https://huggingface.co/bigcode/starcoderbase-7b,
47
+ # https://huggingface.co/bigcode/starcoderbase-3b, https://huggingface.co/bigcode/starcoderbase-1b, https://huggingface.co/bigcode/santacoder, https://huggingface.co/replit/replit-code-v1-3b, https://huggingface.co/THUDM/codegeex2-6b
48
+
49
+ links = {
50
+ "WizardCoder-15B-V1.0": "https://huggingface.co/WizardLM/WizardCoder-15B-V1.0",
51
+ "WizardCoder-3B-V1.0": "https://huggingface.co/WizardLM/WizardCoder-3B-V1.0",
52
+ "WizardCoder-1B-V1.0": "https://huggingface.co/WizardLM/WizardCoder-1B-V1.0",
53
+ "WizardCoder-Python-34B-V1.0": "https://huggingface.co/WizardLM/WizardCoder-Python-34B-V1.0",
54
+ "WizardCoder-Python-13B-V1.0": "https://huggingface.co/WizardLM/WizardCoder-Python-13B-V1.0",
55
+ "OctoCoder-15B": "https://huggingface.co/bigcode/octocoder",
56
+ "OctoGeeX-7B": "https://huggingface.co/bigcode/octogeex",
57
+ "StableCode-3B": "https://huggingface.co/stabilityai/stablecode-completion-alpha-3b",
58
+ "StarCoder-15B": "https://huggingface.co/bigcode/starcoder",
59
+ "StarCoderBase-15B": "https://huggingface.co/bigcode/starcoderbase",
60
+ "StarCoderBase-7B": "https://huggingface.co/bigcode/starcoderbase-7b",
61
+ "StarCoderBase-3B": "https://huggingface.co/bigcode/starcoderbase-3b",
62
+ "StarCoderBase-1.1B": "https://huggingface.co/bigcode/starcoderbase-1b",
63
+ "SantaCoder-1.1B": "https://huggingface.co/bigcode/santacoder",
64
+ "Replit-2.7B": "https://huggingface.co/replit/replit-code-v1-3b",
65
+ "CodeGeex2-6B": "https://huggingface.co/THUDM/codegeex2-6b",
66
+ "CodeGen25-7B-multi": "https://huggingface.co/Salesforce/codegen25-7b-multi",
67
+ "CodeGen25-7B-mono": "https://huggingface.co/Salesforce/codegen25-7b-mono",
68
+ "CodeGen-16B-Multi": "https://huggingface.co/Salesforce/codegen-16B-multi",
69
+ "DeciCoder-1B": "https://huggingface.co/Deci/DeciCoder-1b",
70
+ "Phind-CodeLlama-34B-v1": "https://huggingface.co/phind/Phind-CodeLlama-34B-v1",
71
+ "Phind-CodeLlama-34B-Python-v1": "https://huggingface.co/phind/Phind-CodeLlama-34B-Python-v1",
72
+ "Phind-CodeLlama-34B-v2": "https://huggingface.co/phind/Phind-CodeLlama-34B-v2",
73
+ "Falcon-180B": "https://huggingface.co/tiiuae/falcon-180B",
74
+ "Refact-1.6B": "https://huggingface.co/smallcloudai/Refact-1_6B-fim",
75
+ "Phi-1": "https://huggingface.co/microsoft/phi-1",
76
+ "CodeShell-7B": "https://huggingface.co/WisdomShell/CodeShell-7B",
77
+ "DeepSeek-Coder-1b-base": "https://huggingface.co/deepseek-ai/deepseek-coder-1.3b-base",
78
+ "DeepSeek-Coder-7b-base": "https://huggingface.co/deepseek-ai/deepseek-coder-6.7b-base",
79
+ "DeepSeek-Coder-33b-base": "https://huggingface.co/deepseek-ai/deepseek-coder-33b-base",
80
+ }
81
+
82
+ codellamas = ['CodeLlama-7b', 'CodeLlama-7b-Python', 'CodeLlama-7b-Instruct', 'CodeLlama-13b', 'CodeLlama-13b-Python', 'CodeLlama-13b-Instruct', 'CodeLlama-34b', 'CodeLlama-34b-Python', 'CodeLlama-34b-Instruct']
83
+ for codellama in codellamas:
84
+ links[codellama] = f"https://huggingface.co/codellama/{codellama}-hf"
85
+
86
+ df["Links"] = df["Models"].map(links)
87
+
88
+ df.insert(0, "T", "🟢")
89
+ patterns = ["WizardCoder", "Octo", "Instruct", "Phind", "Refact"]
90
+ df.loc[df["Models"].str.contains('|'.join(patterns)), "T"] = "🔶"
91
+ df.loc[df["Models"].str.contains('|'.join(patterns)), "T"] = "🔶"
92
+ df.loc[df["Models"].str.contains('|'.join(["CodeShell", "DeepSeek"])), "T"] = "🔴"
93
+ # add clumn submission_pr with empty fiels except for CodeShell with link AA
94
+ df["Submission PR"] = ""
95
+ df.loc[df["Models"].str.contains('|'.join(["CodeShell"])), "Submission PR"] = "https://huggingface.co/spaces/bigcode/bigcode-models-leaderboard/discussions/16"
96
+ df.loc[df["Models"].str.contains('|'.join(["DeepSeek-Coder-1b-base"])), "Submission PR"] = "https://huggingface.co/spaces/bigcode/bigcode-models-leaderboard/discussions/33"
97
+ df.loc[df["Models"].str.contains('|'.join(["DeepSeek-Coder-7b-base"])), "Submission PR"] = "https://huggingface.co/spaces/bigcode/bigcode-models-leaderboard/discussions/32"
98
+ df.loc[df["Models"].str.contains('|'.join(["DeepSeek-Coder-33b-base"])), "Submission PR"] = "https://huggingface.co/spaces/bigcode/bigcode-models-leaderboard/discussions/31"
99
+
100
+
101
+ # print first 5 rows and 10 cols
102
+ print(df.iloc[:5, :-1])
103
+ df.to_csv("data/code_eval_board.csv", index=False)
104
+
105
+ # fill readme
106
+ add_model_readme(df)
107
+ print("Readme filled")
src/css_html.py ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ # source: https://huggingface.co/spaces/HuggingFaceH4/open_llm_leaderboard/blob/main/src/assets/css_html_js.py
3
+ custom_css = """
4
+ #changelog-text {
5
+ font-size: 16px !important;
6
+ }
7
+ #changelog-text h2 {
8
+ font-size: 18px !important;
9
+ }
10
+ .markdown-text {
11
+ font-size: 16px !important;
12
+ }
13
+ #models-to-add-text {
14
+ font-size: 18px !important;
15
+ }
16
+ #citation-button span {
17
+ font-size: 16px !important;
18
+ }
19
+ #citation-button textarea {
20
+ font-size: 16px !important;
21
+ }
22
+ #citation-button > label > button {
23
+ margin: 6px;
24
+ transform: scale(1.3);
25
+ }
26
+ #leaderboard-table {
27
+ margin-top: 15px
28
+ }
29
+ #leaderboard-table-lite {
30
+ margin-top: 15px
31
+ }
32
+ #search-bar-table-box > div:first-child {
33
+ background: none;
34
+ border: none;
35
+ }
36
+
37
+ #search-bar {
38
+ padding: 0px;
39
+ }
40
+ /* Hides the final AutoEvalColumn */
41
+ #llm-benchmark-tab-table table td:last-child,
42
+ #llm-benchmark-tab-table table th:last-child {
43
+ display: none;
44
+ }
45
+ /* Limit the width of the first AutoEvalColumn so that names don't expand too much */
46
+ table td:first-child,
47
+ table th:first-child {
48
+ max-width: 400px;
49
+ overflow: auto;
50
+ white-space: nowrap;
51
+ }
52
+ .tab-buttons button {
53
+ font-size: 20px;
54
+ }
55
+ #scale-logo {
56
+ border-style: none !important;
57
+ box-shadow: none;
58
+ display: block;
59
+ margin-left: auto;
60
+ margin-right: auto;
61
+ max-width: 600px;
62
+ }
63
+ #scale-logo .download {
64
+ display: none;
65
+ }
66
+ """
src/envs.py ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ import os
2
+ from huggingface_hub import HfApi
3
+
4
+ H4_TOKEN = os.environ.get("H4_TOKEN", None)
5
+ REPO_ID = "Yeyito/llm_contamination_detector"
6
+ API = HfApi(token=H4_TOKEN)
src/text_content.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ ABOUT_TEXT = """# Background
3
+ Model contamination is an obstacle that many model creators face and has become a growing issue amongst the top scorers in [🤗 Open LLM Leaderboard](https://huggingface.co/spaces/HuggingFaceH4/open_llm_leaderboard). This work is an implementation of the [Detecting Pretraining Data from Large Language Models](https://huggingface.co/papers/2310.16789) following the template provided by [this github repo](https://github.com/swj0419/detect-pretrain-code-contamination/tree/master). I'm aware the Hugginface Team is working on their own implementation of this working directly with the authors of the paper mentioned above. Until that's ready I hope this serves as a metric for evaluating model contamination in open source llms.
4
+
5
+ # Disclaimer
6
+ This space should NOT be used to flag or accuse models of cheating / being contamined. Instead, it should form part of a holistic assesment by the parties involved. The main goal of this space is to provide more transparency as to what the contents of the datasets used to train models are take whatever is shown in the evaluation's tab as a grain of salt and draw your own conclusions from the data.
7
+
8
+ As a final note, I've outlined my main concerns with this implementation in a pinned discussion under the community tab. Any type of help would be greatly appreciated :)"""
9
+
10
+ SUBMISSION_TEXT = """
11
+ <h1 align="center">
12
+ Submitting models for evaluation.
13
+ </h1>
14
+ This space is still highly experimental, try to not submit any GGUF, GPTQ or AWQ models, but their raw fp16/bf16 versions. Also try to not submit any model above 13B parameters in size as this space is not equipped with the hardware to handle that.
15
+
16
+ """
17
+
18
+ SUBMISSION_TEXT_2 = """
19
+ If you encounter any issues while submitting please make a community post about it, or message my discord directly: yeyito777!
20
+ """
src/utils.py ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ # source: https://huggingface.co/spaces/HuggingFaceH4/open_llm_leaderboard/blob/main/src/utils_display.py
3
+ from dataclasses import dataclass
4
+ import plotly.graph_objects as go
5
+ from transformers import AutoConfig
6
+
7
+ # These classes are for user facing column names, to avoid having to change them
8
+ # all around the code when a modif is needed
9
+ @dataclass
10
+ class ColumnContent:
11
+ name: str
12
+ type: str
13
+ displayed_by_default: bool
14
+ hidden: bool = False
15
+
16
+
17
+ def fields(raw_class):
18
+ return [
19
+ v for k, v in raw_class.__dict__.items() if k[:2] != "__" and k[-2:] != "__"
20
+ ]
21
+
22
+
23
+ @dataclass(frozen=True)
24
+ class AutoEvalColumn: # Auto evals column
25
+ model_type_symbol = ColumnContent("T", "str", True)
26
+ model = ColumnContent("Models", "markdown", True)
27
+ ARC = ColumnContent("ARC", "number", True)
28
+ HellaSwag = ColumnContent("HellaSwag", "number", True)
29
+ MMLU = ColumnContent("MMLU", "number", True)
30
+ TruthfulQA = ColumnContent("TruthfulQA", "number", True)
31
+ Winogrande = ColumnContent("Winogrande", "number", True)
32
+ GSM8K = ColumnContent("GSM8K", "number", True)
33
+ dummy = ColumnContent("Models", "str", True)
34
+
35
+
36
+ def model_hyperlink(link, model_name):
37
+ return f'<a target="_blank" href="{link}" style="color: var(--link-text-color); text-decoration: underline;text-decoration-style: dotted;">{model_name}</a>'
38
+
39
+
40
+ def make_clickable_names(df):
41
+ df["Models"] = df.apply(
42
+ lambda row: model_hyperlink(row["Links"], row["Models"]), axis=1
43
+ )
44
+ return df
45
+
46
+ def styled_error(error):
47
+ return f"<p style='color: red; font-size: 20px; text-align: center;'>{error}</p>"
48
+
49
+
50
+ def styled_warning(warn):
51
+ return f"<p style='color: orange; font-size: 20px; text-align: center;'>{warn}</p>"
52
+
53
+
54
+ def styled_message(message):
55
+ return f"<p style='color: green; font-size: 20px; text-align: center;'>{message}</p>"
56
+
57
+
58
+ def has_no_nan_values(df, columns):
59
+ return df[columns].notna().all(axis=1)
60
+
61
+
62
+ def has_nan_values(df, columns):
63
+ return df[columns].isna().any(axis=1)
64
+
65
+
66
+ def is_model_on_hub(model_name: str, revision: str) -> bool:
67
+ try:
68
+ AutoConfig.from_pretrained(model_name, revision=revision, trust_remote_code=False)
69
+ return True, None
70
+
71
+ except ValueError:
72
+ return (
73
+ False,
74
+ "needs to be launched with `trust_remote_code=True`. For safety reason, we do not allow these models to be automatically submitted to the leaderboard.",
75
+ )
76
+
77
+ except Exception as e:
78
+ print(f"Could not get the model config from the hub.: {e}")
79
+ return False, "was not found on hub!"