File size: 7,053 Bytes
c607184
 
 
 
 
 
8e20010
 
 
 
c607184
 
 
8e20010
c607184
bba9479
c607184
bba9479
8e20010
 
 
c607184
 
 
8e20010
c607184
 
 
8e20010
 
 
 
 
 
 
 
5d9d806
8e20010
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c607184
 
 
 
 
8e20010
 
 
 
c607184
 
 
8e20010
 
 
 
 
c607184
 
 
 
 
8e20010
c607184
 
 
 
0985eef
c607184
 
 
 
 
 
 
 
 
5d9d806
 
8e20010
c607184
 
 
 
 
8e20010
 
 
 
c607184
 
 
8e20010
c607184
 
 
8e20010
 
0985eef
 
5d9d806
0985eef
 
8e20010
 
c607184
5d9d806
 
0985eef
5d9d806
bba9479
5d9d806
bba9479
0985eef
 
 
5d9d806
c607184
 
8e20010
c607184
 
 
8e20010
 
0985eef
 
5d9d806
0985eef
 
8e20010
 
c607184
5d9d806
 
0985eef
5d9d806
bba9479
5d9d806
bba9479
0985eef
 
 
5d9d806
c607184
 
8e20010
 
 
 
 
c607184
0985eef
 
5d9d806
0985eef
 
8e20010
 
 
5d9d806
 
0985eef
5d9d806
bba9479
5d9d806
bba9479
0985eef
 
 
5d9d806
8e20010
 
c607184
8e20010
c607184
8e20010
 
 
c607184
 
 
5d9d806
 
0985eef
bba9479
5d9d806
bba9479
c607184
0985eef
 
5d9d806
0985eef
 
8e20010
 
 
c607184
 
5d9d806
c607184
bba9479
c607184
bba9479
5d9d806
 
 
8e20010
 
 
 
 
5d9d806
 
 
c607184
8e20010
 
 
 
 
 
c607184
8e20010
 
 
c607184
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "U8RTc2PmnX-v"
      },
      "source": [
        "Initial setup"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "kGW7vfRkrqHe"
      },
      "outputs": [],
      "source": [
        "!pip install -r https://huggingface.co/flunardelli/llm-metaeval/raw/main/requirements.txt"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "2I850FIsCVNw"
      },
      "outputs": [],
      "source": [
        "from datetime import datetime\n",
        "import os\n",
        "from huggingface_hub import login, upload_folder\n",
        "from google.colab import userdata\n",
        "import shutil\n",
        "\n",
        "HF_TOKEN = userdata.get('HF_TOKEN')\n",
        "login(HF_TOKEN, True)\n",
        "BASE_DATASET='mmlu'\n",
        "REPO_ID='flunardelli/llm-metaeval'\n",
        "BASE_FOLDER=f\"/content/{BASE_DATASET}/\"#{datetime.now().strftime('%Y-%m-%dT%H-%M-%S')}\n",
        "OUTPUT_FOLDER=os.path.join(BASE_FOLDER,'output')\n",
        "TASK_FOLDER=os.path.join(BASE_FOLDER,'tasks')\n",
        "#shutil.rmtree(BASE_FOLDER)\n",
        "os.makedirs(OUTPUT_FOLDER)\n",
        "os.makedirs(TASK_FOLDER)\n",
        "os.environ['HF_TOKEN'] = HF_TOKEN\n",
        "os.environ['OUTPUT_FOLDER'] = OUTPUT_FOLDER\n",
        "os.environ['TASK_FOLDER'] = TASK_FOLDER\n",
        "\n",
        "def hf_upload_folder(folder_path):\n",
        "  upload_folder(\n",
        "      folder_path=folder_path,\n",
        "      path_in_repo=\"evals/\",\n",
        "      repo_id=REPO_ID,\n",
        "      token=HF_TOKEN,\n",
        "      repo_type=\"dataset\"\n",
        "  )\n",
        "\n",
        "def create_task(content, filename):\n",
        "  filename_path = os.path.join(TASK_FOLDER,filename)\n",
        "  with open(filename_path, \"w\") as f:\n",
        "    f.write(content)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "Jd2JwKZaPkNS"
      },
      "source": [
        "Create task for MMLU all datasets"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "xP0cC_sHih7C"
      },
      "outputs": [],
      "source": [
        "YAML_mmlu_en_us_string = \"\"\"\n",
        "task: mmlu_all\n",
        "dataset_path: cais/mmlu\n",
        "dataset_name: all\n",
        "description: \"MMLU dataset\"\n",
        "test_split: test\n",
        "fewshot_split: dev\n",
        "fewshot_config:\n",
        "  sampler: first_n\n",
        "num_fewshot: 5\n",
        "output_type: multiple_choice\n",
        "doc_to_text: \"{{question.strip()}}\\nA. {{choices[0]}}\\nB. {{choices[1]}}\\nC. {{choices[2]}}\\nD. {{choices[3]}}\\nAnswer:\"\n",
        "doc_to_choice: [\"A\", \"B\", \"C\", \"D\"]\n",
        "doc_to_target: answer\n",
        "metric_list:\n",
        "  - metric: acc\n",
        "    aggregation: mean\n",
        "    higher_is_better: true\n",
        "\"\"\"\n",
        "create_task(YAML_mmlu_en_us_string, 'mmlu_en_us.yaml')\n",
        "os.environ['TASKS'] = 'mmlu_all'\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "mJjo_A5tP-Td"
      },
      "source": [
        "Llama Models"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "IzP5nyP0Gwk8"
      },
      "outputs": [],
      "source": [
        "!lm_eval \\\n",
        "--model hf --model_args pretrained=meta-llama/Llama-3.2-1B-Instruct,revision=d0a2081ed47e20ce524e8bc5d132f3fad2f69ff0,trust_remote_code=False,dtype=bfloat16,parallelize=True \\\n",
        "--tasks $TASKS \\\n",
        "--include_path $TASK_FOLDER/. --output $OUTPUT_FOLDER --log_samples \\\n",
        "--batch_size auto &> run.log\n",
        "#--limit 10 \\"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "uMoitxJkHerH"
      },
      "outputs": [],
      "source": [
        "hf_upload_folder(BASE_FOLDER)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "oIACOAhDW5ow"
      },
      "outputs": [],
      "source": [
        "!lm_eval \\\n",
        "--model hf --model_args pretrained=meta-llama/Llama-3.2-3B-Instruct,revision=392a143b624368100f77a3eafaa4a2468ba50a72,trust_remote_code=False,dtype=bfloat16,parallelize=True \\\n",
        "--tasks $TASKS \\\n",
        "--include_path $TASK_FOLDER/. --output $OUTPUT_FOLDER --log_samples \\\n",
        "--batch_size auto &> run.log\n",
        "#--limit 10 \\"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "eIUOqu5sHfkM"
      },
      "outputs": [],
      "source": [
        "hf_upload_folder(BASE_FOLDER)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "cFFYPzBIYGf7"
      },
      "outputs": [],
      "source": [
        "!lm_eval \\\n",
        "--model hf --model_args pretrained=meta-llama/Meta-Llama-3-8B,revision=62bd457b6fe961a42a631306577e622c83876cb6,trust_remote_code=False,dtype=bfloat16,parallelize=True \\\n",
        "--tasks $TASKS \\\n",
        "--include_path $TASK_FOLDER/. --output $OUTPUT_FOLDER --log_samples \\\n",
        "--batch_size auto &> run.log\n",
        "#--limit 10 \\"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "xsL82Q4SHgMn"
      },
      "outputs": [],
      "source": [
        "hf_upload_folder(BASE_FOLDER)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "1fEX-49hQ-Be"
      },
      "source": [
        "Mistral Models"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": true,
        "id": "ilu9_ulWTy3p"
      },
      "outputs": [],
      "source": [
        "!lm_eval \\\n",
        "--model hf --model_args pretrained=mistralai/Mixtral-8x7B-Instruct-v0.1,revision=41bd4c9e7e4fb318ca40e721131d4933966c2cc1,trust_remote_code=False,dtype=bfloat16,parallelize=True \\\n",
        "--tasks $TASKS \\\n",
        "--include_path $TASK_FOLDER/. --output $OUTPUT_FOLDER  --log_samples \\\n",
        "--batch_size auto &> run.log\n",
        "#--limit 10 \\"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "jE5r8gVDHhAz"
      },
      "outputs": [],
      "source": [
        "hf_upload_folder(BASE_FOLDER)"
      ]
    }
  ],
  "metadata": {
    "accelerator": "GPU",
    "colab": {
      "gpuType": "L4",
      "machine_shape": "hm",
      "provenance": []
    },
    "kernelspec": {
      "display_name": "Python 3",
      "name": "python3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}