opyate commited on
Commit
8af234b
1 Parent(s): 385a891

Upload notebook.ipynb

Browse files
Files changed (1) hide show
  1. notebook.ipynb +743 -0
notebook.ipynb ADDED
@@ -0,0 +1,743 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "metadata": {},
6
+ "source": [
7
+ "# Dataset"
8
+ ]
9
+ },
10
+ {
11
+ "cell_type": "code",
12
+ "execution_count": 2,
13
+ "metadata": {},
14
+ "outputs": [
15
+ {
16
+ "name": "stderr",
17
+ "output_type": "stream",
18
+ "text": [
19
+ "/home/opyate/Documents/code/datura-ai/.venv/lib/python3.12/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
20
+ " from .autonotebook import tqdm as notebook_tqdm\n"
21
+ ]
22
+ }
23
+ ],
24
+ "source": [
25
+ "import datasets\n",
26
+ "\n",
27
+ "dataset = datasets.load_dataset(\"tiiuae/falcon-refinedweb\", streaming=True, split=\"train\")"
28
+ ]
29
+ },
30
+ {
31
+ "cell_type": "code",
32
+ "execution_count": 30,
33
+ "metadata": {},
34
+ "outputs": [
35
+ {
36
+ "name": "stdout",
37
+ "output_type": "stream",
38
+ "text": [
39
+ "{'content': 'these birches can be found in many places in Europe - the photos is from a short trip to Baden-Baden in 2007. the clouds in the background are the messengers of the storm Kyrill. here are some more moments of the trip: Baden-Baden.\\n-\\n“ast/ray” is a bilingual wordplay: “ast” means “twig” in German. and while “Baden-Baden” sounds like wordplay, too, it is the actual name of a rather well-know spa town that also dates back to Roman times. “Bad” is the German word for “bath”.\\nMirror effect turned out nice. I like', 'url': 'http://100parts.wordpress.com/2012/08/04/astray-baden-baden-day-31/', 'timestamp': datetime.datetime(2013, 5, 18, 10, 42), 'dump': 'CC-MAIN-2013-20', 'segment': '1368696382261', 'image_urls': []}\n",
40
+ "{'content': 'Watch Survivor Redemption Island Season 22 Episode 11: A Mystery Package Online S22e11 Free Stream Megavideo\\nArticle by StreamThatSeries\\nHorray!time for another dose of very exciting reality series with lots of twists.You must watch survivor redemption island season 22 episode 11 tonight with a title of “Mystery Package” coz surely this will stir things up on the merge tribe murlonio. But in case you will the episode on your television set at home , just follow through the link here to watch survivor redemption island season 22 episode 11 a mystery package online for free at anyhotstuff.com\\nHere’s some sort or recaps and tidbits for last week’s episode: 5. Rice Capades – I don’t really know where to begin with talking about Phillip this week. I know that I certainly don’t want to use the c-word to describe Phillip’s behavior. However, through all of the histrionics in this episode, one thing is clear: You can no longer make the argument that Phillip is playing a game with any sort of strategy.\\nPhillip told us last week that his intention was to get Boston Rob to want Phillip next to him at the end of the game. However, at this point Phillip is not showing any signs that winning this game is his objective at all. Phillip is certainly entitled to having an opinion and feeling the way he does but part of being a good Survivor player is occasionally hiding your feelings in the interests of winning the game. Phillip’s aggressive behavior has all but assured himself a zero percent chance at the million dollars. Even if Phillip makes it to the final three, he would need five votes to win the game. Considering that there will likely be five Zapatera tribe members on the jury, this incident is going to stick to Phillip like a certain color on rice.\\n4. The Great Divide – Besides for Phillip, I think the most unique thing about this season of Survivor is the lack of a merge. Oh, it technically happened, but this is the only season of Survivor I can remember where the merged tribe not only has a separate alliance but separate shelters and separate food rations too. Actually, this isn’t that uncommon, I know a lot of people in bad marriages who live the same way. The big question going forward will be how much will the Zapateras hold Boston Rob accountable for being shut out to this degree? Phillip has done a lot to take the heat off of Rob but don’t be surprised if at the end of the game, the Zapatera tribe continues to act as a group and completely vote together for whomever treated them best – which is why I maintain one of the three Ometepe women have a great shot to win this game.\\n3. Saving Sheppard – This season, I have spent much more time breaking down Boston Rob’s decisions in the game than any of the other players. In my opinion, Rob has far more control in this game than any other Survivor may have had at this point in history. Since Rob is controlling the vote, did Rob make the right move by keeping Phillip this week? On the one hand, he realizes that getting rid of Phillip would end a lot of the drama around camp and may even create some goodwill among the remaining Zapateras. Instead, Rob chose to keep Phillip around for another week and I agree with his decision. Phillip Sheppard is the best thing that happened to Boston Rob this season because Phillip���s distractions keep everybody from thinking about the game. When Phillip is going off about rice, feathers or kung fu, nobody is ever asking themselves about their position in the tribe or some big move they’re going to make – and that’s exactly how Boston Rob wants it to be.\\n2. Tribal Counseling – It was no surprise that the feud between Phillip and Steve spilled over in to this week’s tribal council. I thought that Jeff Probst showed why he is the best host on television by exploring both sides of the debate. What I still don’t understand is what happened to Phillip’s shirt? Has there ever been a Survivor contestant to attend tribal council topless before? Now with Julie gone the prospects seem pretty slim that Phillip will ever find his bathing suit. Phillip now can only hope to win a reward at some point to find the first clue to the hidden bathing suit.\\n1. Three’s Company – This week we had our first ever three-way duel on Redemption Island, which ended in Mike and Matt moving on and David getting eliminated. I think the top 2 people advancing at Redemption Island seems like it would help Matt in his quest to return to the game since it seems unlikely he would ever come in last (unless the duel involved having a strategy of some sort). Unfortunately, it looks like Redemption Island is starting to really take its toll on Matt. In Matt’s prayers he says that he doesn’t want to be on Survivor anymore but is simply carrying out God’s will. You would think that having an extra person on Redemption Island might help cheer Matt up a little bit, but apparently Mike Chisel isn’t that great of a roommate.\\nWhat you waiting for, watch Survivor: Redemption Island season 22 Episode 11 a Mystery Package Survivor: Redemption Tropical isle Year twenty-two Event 11: We all Can’t stand A lot of our Tribe is currently approaching globally regarding tv set landscape an important subject due to this usually are We all Dislike Much of our Tribe. So that it signifies usual account a single tribe has long been dislike other tribe the reason why? Inside the landscape with the Survivor: Redemption Tropical isle Month or year twenty-two Show 11 On line aboard just what occur inside this landscape. He together with Kristina duel at Redemption Island. On the Ometepe campy, tribe unity commences to help you out unravel. Thus test in order to savor Survivor: Redemption Tropical isle Length twenty-two Show 11 online. Survivor: Redemption Tropical area Period twenty-two Show 11:. Of which CBS Survivor: Redemption Tropical isle 22?11 show on tv alongside subject We all Can’t stand Many of our Tribe Survivor: Redemption Tropical isle Season twenty-two Event 11: EVERY Puzzle Deal. This particular CBS Survivor: Redemption Tropical isle 22?11 show on tv combined with subject ANY Puzzle Package deal shown about Saturday, Annual percentage rates 29 2011 for 08: 00 EVENING HOURS. This can be a new conclusion regarding Survivor: Redemption Tropical isle Year or so twenty-two Event 11: VIRTUALLY ANY Puzzle Deal: About Redemption Tropical isle, He will be having a mechanical disappointment, one more castaway will be voted through your video game. Previous shows: Episode 10 “Rice Wars” Phillip and also Steve clash. Episode 9 “The Colleague System” Rob tries to be able to secure an Ometepe connections, but Grant may really do the one to jeopardize the item. Survivor is an American version of this Survivor reality television sport show, itself derived from the Swedish television series Journey Robinson originally created in 1997 by Charlie Parsons. This series premiered on May perhaps 31, 2000 on CBS. It can be hosted by veteran television system personality, reporter and one-time performance show emcee Jeff Probst, who might be also an executive designer, and also executive that is caused by Mark Burnett and main creator Charlie Parsons. WATCH HERE : Watch Survivor: Redemption Island Season 22 Episode 11 The show maroons a small grouping strangers (as one or longer tribes) in a destitute locale, where they ought to provide food, water, open fire, and shelter for themselves, while competing in challenges to earn either a reward, or an immunity from expulsion from the game yearly of the successive votes for elimination. While a great deal rarer than elimination by vote, medical conditions, such as injury or infection, need eliminated several contestants. The last 2 or three survivors face a jury historically made from at least the final seven players voted shut off. That jury interrogates one last few, and then votes for those winner of the distinction of Sole Survivor in addition to a million dollar prize. The first U. S. season of Survivor followed identical general format as the particular Swedish series, but, subsequently, the show has introduced several twists over the core rules to keep the players on their toes and prevent players from influenced by strategies that succeeded with prior seasons. These alters have included tribal buttons, seasons starting with well over two tribes, the abil vity to exile a gamer from a tribe for a few days, and hidden immun ity idols that players are able to use to save themselves for tribal council. Season 22 It season’s cast features typically the return of Rob MICHAEL. and Russell. This is Russell’s third time for the show and Rob METERS. ‘s fourth. It is the very first time in the show’s hist ory that your cont estant has played several individual times. This per iod also feat ures two past NFL players (Grant and also Steve). CBS today annou nced 16 of 18 castaw ays who will compete against each additi onal on SURV IVOR: REDEMPTI ON TROPICAL ISLAND, when the Em my Award-win ning series returns as for the 22nd season, Wednesday, February. 16 (8: 00-9: 00 EVENING, ET/PT) on the CBS Video Network. Two of your 18 cas taways, to be reve aled later this 7-day period, are form er casta ways who will return to seek redemption. This edition of SURVI VOR will include a new twist when, for when, castaways who have been elimi nated th rough the ga me will have possibi lity to seek rede mption and re turn for the opport unity to win the mil lion mone tary prize. Each week at Tribal Coun cil beca use a cast away is vot ed from, they will be brou ght to an isola ted isl and gen erally known as “Rede mption Isla nd, ” where they ‘ll live alo ne in ex ile. To last on Redempt ion Isla nd, they must com pete in a duel about the next person elimin ated wit hin Tr ibal Cou ncil and pumped to the Island. The winner of each duel earns an appro priate to contin ue figh ting for ena ble you to retu rn to the game and the chance to compete for the subj ect of Sole Sur vivor; the part icular los er is sent hou se. The bat tle unfolds in Nica ragua where 18 casta ways will pos sibly be divi ded into two Trib es of nine: the Omet epe Tr ibe and then the Zapatera Tribe. The tr ibes are derived from indivi duals fro m all dif ferent bac kgrounds aid ed by the same ultimate goal: for being the Sole Survi vor. While 16 of yo ur cont estants are new to the competi tion, two are former castaways that will be gi ven an other opportu nity to com pete for the million dollar prize andf the other last shot at redem ption.\\nAbout the Author\\nWatch FULL EPISODE here for Free', 'url': 'http://100percentwinnersblog.com/watch-survivor-redemption-island-season-22-episode-11-a-mystery-package-online-s22e11-free-stream-megavideo/', 'timestamp': datetime.datetime(2013, 5, 18, 11, 2, 3), 'dump': 'CC-MAIN-2013-20', 'segment': '1368696382261', 'image_urls': []}\n",
41
+ "{'content': 'Pesky?\\nthis was a high school project for a president campaign in our government class, yes thats him, for a school project, you guys are crazy\\ni know his dad from work. very cool and funny guy!!', 'url': 'http://101squadron.com/blog/2007/05/pesky-peculiarities-of-css.html/comment-page-1', 'timestamp': datetime.datetime(2013, 5, 18, 10, 21, 35), 'dump': 'CC-MAIN-2013-20', 'segment': '1368696382261', 'image_urls': [['http://101squadron.com/uploaded_images/Conger_89_cal-757679.jpg', None], [\"http://101squadron.com/uploaded_images/Hammerin'-Hank-Conger-795118.jpg\", None], ['http://101squadron.com/uploaded_images/hconger06108180bm-753187.jpg', None], ['http://101squadron.com/uploaded_images/HHMex8Au-794539.jpg', None], ['http://101squadron.com/uploaded_images/Conger-back-712123.jpg', None]]}\n",
42
+ "{'content': 'metalkingdom.net [ 80′s @ 8 Feature Video – Big City Nights [VIDEO] By Chris Chapman March 13, 2012 It\\'s time to rock out to those talented Germans Rudolf and Klaus from the Scorpions! \"Big City Nights\" wasn\\'t as big as \"Rock You Like A Hurricane\" or \"Winds Of Change\", but it still stands the test of time. Read More Category: 80\\'s @ 8 Featured Video Tags: 80\\'s, big city nights, love at first sting, Scorpions Send to a friend! Print this page Share on Facebook Share on Twitter Pin it! Reddit This!', 'url': 'http://1037theloon.com/tags/scorpions/', 'timestamp': datetime.datetime(2013, 5, 18, 10, 21, 51), 'dump': 'CC-MAIN-2013-20', 'segment': '1368696382261', 'image_urls': []}\n",
43
+ "{'content': 'Splice Review\\nBlack Ops Escalation Map Pack [VIDEO]\\nScream 4 Review-No Spoilers\\nBest seem\\nThrashman’s Metal Pick Of The Week\\nNightmare On Elm Street [VIDEO]\\n2011 Dodge Charger\\nMr Skin’s Anatomy Awards\\n', 'url': 'http://1063thebuzz.com/category/reviews/page/7/', 'timestamp': datetime.datetime(2013, 5, 18, 10, 31, 9), 'dump': 'CC-MAIN-2013-20', 'segment': '1368696382261', 'image_urls': [['https://s3.amazonaws.com/tsm-images/global/1x1.gif', 'rotten-sound-cursed-large-promo-album-pic rotten-sound-cursed-large-promo-album-pic'], ['https://s3.amazonaws.com/tsm-images/global/1x1.gif', 'rotten-sound-cursed-large-promo-album-pic rotten-sound-cursed-large-promo-album-pic'], ['https://s3.amazonaws.com/tsm-images/global/1x1.gif', 'Twicebroken and Joshua David Twicebroken and Joshua David'], ['https://s3.amazonaws.com/tsm-images/global/1x1.gif', 'splice dimension films'], ['https://s3.amazonaws.com/tsm-images/global/1x1.gif', 'hqdefault24 hqdefault24'], ['https://s3.amazonaws.com/tsm-images/global/1x1.gif', 'radioclown radioclown'], ['https://s3.amazonaws.com/tsm-images/global/1x1.gif', 'hqdefault15 hqdefault15'], ['https://s3.amazonaws.com/tsm-images/global/1x1.gif', 'Life On Kandahar Air Base Life On Kandahar Air Base'], ['https://s3.amazonaws.com/tsm-images/global/1x1.gif', 'Havok-TimeIsUp-300x300 Havok-TimeIsUp-300x300'], ['https://s3.amazonaws.com/tsm-images/global/1x1.gif', 'nightmare-300x244 freddy k'], ['https://s3.amazonaws.com/tsm-images/global/1x1.gif', '2011-dodge-charger-embed-4 2011-dodge-charger-embed-4'], ['https://s3.amazonaws.com/tsm-images/global/1x1.gif', 'Mr Skin Mr Skin'], ['https://s3.amazonaws.com/tsm-images/global/1x1.gif', 'hqdefault10 hqdefault10']]}\n"
44
+ ]
45
+ }
46
+ ],
47
+ "source": [
48
+ "dataset\n",
49
+ "\n",
50
+ "# show the first few examples\n",
51
+ "for example in dataset.take(5):\n",
52
+ " print(example)\n"
53
+ ]
54
+ },
55
+ {
56
+ "cell_type": "markdown",
57
+ "metadata": {},
58
+ "source": [
59
+ "# Model and tokenizer"
60
+ ]
61
+ },
62
+ {
63
+ "cell_type": "code",
64
+ "execution_count": 4,
65
+ "metadata": {},
66
+ "outputs": [
67
+ {
68
+ "name": "stderr",
69
+ "output_type": "stream",
70
+ "text": [
71
+ "You are using the default legacy behaviour of the <class 'transformers.models.llama.tokenization_llama_fast.LlamaTokenizerFast'>. This is expected, and simply means that the `legacy` (previous) behavior will be used so nothing changes for you. If you want to use the new behaviour, set `legacy=False`. This should only be set if you understand what it means, and thoroughly read the reason why this was added as explained in https://github.com/huggingface/transformers/pull/24565 - if you loaded a llama tokenizer from a GGUF file you can ignore this message.\n",
72
+ "Loading checkpoint shards: 100%|██████████| 2/2 [00:02<00:00, 1.07s/it]\n"
73
+ ]
74
+ }
75
+ ],
76
+ "source": [
77
+ "import torch\n",
78
+ "from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig\n",
79
+ "\n",
80
+ "model_id = \"luodian/llama-7b-hf\"\n",
81
+ "bnb_config = BitsAndBytesConfig(\n",
82
+ " load_in_4bit=True,\n",
83
+ " bnb_4bit_compute_dtype=torch.bfloat16\n",
84
+ ")\n",
85
+ "\n",
86
+ "tokenizer = AutoTokenizer.from_pretrained(model_id)\n",
87
+ "tokenizer.pad_token = tokenizer.eos_token\n",
88
+ "\n",
89
+ "model = AutoModelForCausalLM.from_pretrained(model_id, quantization_config=bnb_config, \n",
90
+ " device_map=\"auto\")"
91
+ ]
92
+ },
93
+ {
94
+ "cell_type": "code",
95
+ "execution_count": 5,
96
+ "metadata": {},
97
+ "outputs": [
98
+ {
99
+ "name": "stdout",
100
+ "output_type": "stream",
101
+ "text": [
102
+ "Number of tokens in sample: 150\n",
103
+ "Number of tokens in sample: 2731\n",
104
+ "Number of tokens in sample: 52\n",
105
+ "Number of tokens in sample: 162\n",
106
+ "Number of tokens in sample: 78\n",
107
+ "Number of tokens in sample: 257\n",
108
+ "Number of tokens in sample: 1074\n",
109
+ "Number of tokens in sample: 505\n",
110
+ "Number of tokens in sample: 592\n",
111
+ "Number of tokens in sample: 932\n"
112
+ ]
113
+ }
114
+ ],
115
+ "source": [
116
+ "for example in dataset.take(10):\n",
117
+ " token_count = len(tokenizer.encode(example['content']))\n",
118
+ " print(f\"Number of tokens in sample: {token_count}\") "
119
+ ]
120
+ },
121
+ {
122
+ "cell_type": "markdown",
123
+ "metadata": {},
124
+ "source": [
125
+ "# Function to calculate validation loss"
126
+ ]
127
+ },
128
+ {
129
+ "cell_type": "code",
130
+ "execution_count": 5,
131
+ "metadata": {},
132
+ "outputs": [],
133
+ "source": [
134
+ "def calculate_validation_loss(model, dataloader):\n",
135
+ " model.eval()\n",
136
+ " total_loss = 0\n",
137
+ "\n",
138
+ " with torch.no_grad():\n",
139
+ " for batch in dataloader:\n",
140
+ " batch = {k: v.to(model.device) for k, v in batch.items()}\n",
141
+ " outputs = model(**batch, labels=batch[\"input_ids\"])\n",
142
+ " loss = outputs.loss\n",
143
+ " total_loss += loss.item()\n",
144
+ "\n",
145
+ " average_loss = total_loss / len(dataloader)\n",
146
+ " return average_loss"
147
+ ]
148
+ },
149
+ {
150
+ "cell_type": "markdown",
151
+ "metadata": {},
152
+ "source": [
153
+ "# Prepare data"
154
+ ]
155
+ },
156
+ {
157
+ "cell_type": "code",
158
+ "execution_count": 9,
159
+ "metadata": {},
160
+ "outputs": [],
161
+ "source": [
162
+ "def tokenize_function(examples):\n",
163
+ " return tokenizer(examples[\"content\"], padding=\"max_length\", truncation=True, max_length=512) "
164
+ ]
165
+ },
166
+ {
167
+ "cell_type": "code",
168
+ "execution_count": 13,
169
+ "metadata": {},
170
+ "outputs": [],
171
+ "source": [
172
+ "sample_size = 1000 # small, for a quick experiment\n",
173
+ "\n",
174
+ "# Approximate 80/20 split while streaming\n",
175
+ "train_dataset = []\n",
176
+ "validation_dataset = []\n",
177
+ "for i, item in enumerate(dataset):\n",
178
+ " if i % 5 == 0: # Every 5th item goes to validation (approximately 20%)\n",
179
+ " validation_dataset.append(item)\n",
180
+ " else:\n",
181
+ " train_dataset.append(item)\n",
182
+ " if len(train_dataset) >= sample_size and len(validation_dataset) >= (sample_size // 4): \n",
183
+ " # Stop once we have enough samples for both training and validation\n",
184
+ " break\n",
185
+ "\n",
186
+ "# Tokenize the training and validation samples\n",
187
+ "tokenized_train_dataset = []\n",
188
+ "for item in train_dataset:\n",
189
+ " tokenized_item = tokenize_function(item)\n",
190
+ " tokenized_train_dataset.append(tokenized_item)\n",
191
+ "\n",
192
+ "tokenized_validation_dataset = []\n",
193
+ "for item in validation_dataset:\n",
194
+ " tokenized_item = tokenize_function(item)\n",
195
+ " tokenized_validation_dataset.append(tokenized_item)\n",
196
+ "\n",
197
+ "# Convert to Dataset objects if needed\n",
198
+ "from datasets import Dataset\n",
199
+ "tokenized_train_dataset = Dataset.from_list(tokenized_train_dataset)\n",
200
+ "tokenized_validation_dataset = Dataset.from_list(tokenized_validation_dataset)\n",
201
+ "\n",
202
+ "# Convert the tokenized datasets to PyTorch tensors\n",
203
+ "tokenized_train_dataset.set_format(type='torch', columns=['input_ids', 'attention_mask'])\n",
204
+ "tokenized_validation_dataset.set_format(type='torch', columns=['input_ids', 'attention_mask'])\n"
205
+ ]
206
+ },
207
+ {
208
+ "cell_type": "markdown",
209
+ "metadata": {},
210
+ "source": [
211
+ "# Before training"
212
+ ]
213
+ },
214
+ {
215
+ "cell_type": "markdown",
216
+ "metadata": {},
217
+ "source": [
218
+ "## Calculate validation loss"
219
+ ]
220
+ },
221
+ {
222
+ "cell_type": "code",
223
+ "execution_count": 14,
224
+ "metadata": {},
225
+ "outputs": [
226
+ {
227
+ "name": "stderr",
228
+ "output_type": "stream",
229
+ "text": [
230
+ "We detected that you are passing `past_key_values` as a tuple and this is deprecated and will be removed in v4.43. Please use an appropriate `Cache` class (https://huggingface.co/docs/transformers/v4.41.3/en/internal/generation_utils#transformers.Cache)\n"
231
+ ]
232
+ },
233
+ {
234
+ "name": "stdout",
235
+ "output_type": "stream",
236
+ "text": [
237
+ "Validation loss before training: 9.958484322547912\n"
238
+ ]
239
+ }
240
+ ],
241
+ "source": [
242
+ "from torch.utils.data import DataLoader\n",
243
+ "\n",
244
+ "validation_dataloader = DataLoader(tokenized_validation_dataset, batch_size=2) \n",
245
+ "loss_before_training = calculate_validation_loss(model, validation_dataloader)\n",
246
+ "print(f\"Validation loss before training: {loss_before_training}\")"
247
+ ]
248
+ },
249
+ {
250
+ "cell_type": "markdown",
251
+ "metadata": {},
252
+ "source": [
253
+ "## Benchmark"
254
+ ]
255
+ },
256
+ {
257
+ "cell_type": "markdown",
258
+ "metadata": {},
259
+ "source": [
260
+ "Run this command:\n",
261
+ "\n",
262
+ "```\n",
263
+ "accelerate launch -m lm_eval --model hf \\\n",
264
+ " --model_args pretrained=luodian/llama-7b-hf,load_in_4bit=True,dtype=\"bfloat16\" \\\n",
265
+ " --tasks mmlu,hellaswag,truthfulqa \\\n",
266
+ " --batch_size auto:4 \\\n",
267
+ " --log_samples \\\n",
268
+ " --output_path results/before-training\n",
269
+ "```\n",
270
+ "\n",
271
+ "Output:\n",
272
+ "\n",
273
+ "```\n",
274
+ "hf (pretrained=luodian/llama-7b-hf,load_in_4bit=True,dtype=bfloat16), gen_kwargs: (None), limit: None, num_fewshot: None, batch_size: auto:4 (16,64,64,64)\n",
275
+ "| Tasks |Version|Filter|n-shot| Metric | | Value | |Stderr|\n",
276
+ "|---------------------------------------|------:|------|-----:|-----------|---|-------:|---|-----:|\n",
277
+ "|hellaswag | 1|none | 0|acc |↑ | 0.5646|± |0.0049|\n",
278
+ "| | |none | 0|acc_norm |↑ | 0.7498|± |0.0043|\n",
279
+ "|mmlu | 2|none | |acc |↑ | 0.3126|± |0.0039|\n",
280
+ "| - humanities | 2|none | |acc |↑ | 0.3101|± |0.0067|\n",
281
+ "| - formal_logic | 1|none | 0|acc |↑ | 0.2778|± |0.0401|\n",
282
+ "| - high_school_european_history | 1|none | 0|acc |↑ | 0.3939|± |0.0382|\n",
283
+ "| - high_school_us_history | 1|none | 0|acc |↑ | 0.3824|± |0.0341|\n",
284
+ "| - high_school_world_history | 1|none | 0|acc |↑ | 0.3671|± |0.0314|\n",
285
+ "| - international_law | 1|none | 0|acc |↑ | 0.3884|± |0.0445|\n",
286
+ "| - jurisprudence | 1|none | 0|acc |↑ | 0.3519|± |0.0462|\n",
287
+ "| - logical_fallacies | 1|none | 0|acc |↑ | 0.3067|± |0.0362|\n",
288
+ "| - moral_disputes | 1|none | 0|acc |↑ | 0.3555|± |0.0258|\n",
289
+ "| - moral_scenarios | 1|none | 0|acc |↑ | 0.2380|± |0.0142|\n",
290
+ "| - philosophy | 1|none | 0|acc |↑ | 0.3441|± |0.0270|\n",
291
+ "| - prehistory | 1|none | 0|acc |↑ | 0.3364|± |0.0263|\n",
292
+ "| - professional_law | 1|none | 0|acc |↑ | 0.2803|± |0.0115|\n",
293
+ "| - world_religions | 1|none | 0|acc |↑ | 0.4503|± |0.0382|\n",
294
+ "| - other | 2|none | |acc |↑ | 0.3399|± |0.0084|\n",
295
+ "| - business_ethics | 1|none | 0|acc |↑ | 0.3300|± |0.0473|\n",
296
+ "| - clinical_knowledge | 1|none | 0|acc |↑ | 0.3208|± |0.0287|\n",
297
+ "| - college_medicine | 1|none | 0|acc |↑ | 0.2775|± |0.0341|\n",
298
+ "| - global_facts | 1|none | 0|acc |↑ | 0.3500|± |0.0479|\n",
299
+ "| - human_aging | 1|none | 0|acc |↑ | 0.3094|± |0.0310|\n",
300
+ "| - management | 1|none | 0|acc |↑ | 0.2524|± |0.0430|\n",
301
+ "| - marketing | 1|none | 0|acc |↑ | 0.3718|± |0.0317|\n",
302
+ "| - medical_genetics | 1|none | 0|acc |↑ | 0.4200|± |0.0496|\n",
303
+ "| - miscellaneous | 1|none | 0|acc |↑ | 0.4291|± |0.0177|\n",
304
+ "| - nutrition | 1|none | 0|acc |↑ | 0.3235|± |0.0268|\n",
305
+ "| - professional_accounting | 1|none | 0|acc |↑ | 0.2801|± |0.0268|\n",
306
+ "| - professional_medicine | 1|none | 0|acc |↑ | 0.2500|± |0.0263|\n",
307
+ "| - virology | 1|none | 0|acc |↑ | 0.2952|± |0.0355|\n",
308
+ "| - social sciences | 2|none | |acc |↑ | 0.3052|± |0.0083|\n",
309
+ "| - econometrics | 1|none | 0|acc |↑ | 0.2544|± |0.0410|\n",
310
+ "| - high_school_geography | 1|none | 0|acc |↑ | 0.2828|± |0.0321|\n",
311
+ "| - high_school_government_and_politics| 1|none | 0|acc |↑ | 0.3161|± |0.0336|\n",
312
+ "| - high_school_macroeconomics | 1|none | 0|acc |↑ | 0.2538|± |0.0221|\n",
313
+ "| - high_school_microeconomics | 1|none | 0|acc |↑ | 0.2395|± |0.0277|\n",
314
+ "| - high_school_psychology | 1|none | 0|acc |↑ | 0.3358|± |0.0202|\n",
315
+ "| - human_sexuality | 1|none | 0|acc |↑ | 0.2901|± |0.0398|\n",
316
+ "| - professional_psychology | 1|none | 0|acc |↑ | 0.3333|± |0.0191|\n",
317
+ "| - public_relations | 1|none | 0|acc |↑ | 0.3000|± |0.0439|\n",
318
+ "| - security_studies | 1|none | 0|acc |↑ | 0.2286|± |0.0269|\n",
319
+ "| - sociology | 1|none | 0|acc |↑ | 0.4179|± |0.0349|\n",
320
+ "| - us_foreign_policy | 1|none | 0|acc |↑ | 0.3900|± |0.0490|\n",
321
+ "| - stem | 2|none | |acc |↑ | 0.2965|± |0.0081|\n",
322
+ "| - abstract_algebra | 1|none | 0|acc |↑ | 0.2600|± |0.0441|\n",
323
+ "| - anatomy | 1|none | 0|acc |↑ | 0.3407|± |0.0409|\n",
324
+ "| - astronomy | 1|none | 0|acc |↑ | 0.3487|± |0.0388|\n",
325
+ "| - college_biology | 1|none | 0|acc |↑ | 0.3403|± |0.0396|\n",
326
+ "| - college_chemistry | 1|none | 0|acc |↑ | 0.2700|± |0.0446|\n",
327
+ "| - college_computer_science | 1|none | 0|acc |↑ | 0.3300|± |0.0473|\n",
328
+ "| - college_mathematics | 1|none | 0|acc |↑ | 0.3000|± |0.0461|\n",
329
+ "| - college_physics | 1|none | 0|acc |↑ | 0.1765|± |0.0379|\n",
330
+ "| - computer_security | 1|none | 0|acc |↑ | 0.3500|± |0.0479|\n",
331
+ "| - conceptual_physics | 1|none | 0|acc |↑ | 0.3106|± |0.0303|\n",
332
+ "| - electrical_engineering | 1|none | 0|acc |↑ | 0.3310|± |0.0392|\n",
333
+ "| - elementary_mathematics | 1|none | 0|acc |↑ | 0.2619|± |0.0226|\n",
334
+ "| - high_school_biology | 1|none | 0|acc |↑ | 0.3645|± |0.0274|\n",
335
+ "| - high_school_chemistry | 1|none | 0|acc |↑ | 0.2512|± |0.0305|\n",
336
+ "| - high_school_computer_science | 1|none | 0|acc |↑ | 0.3800|± |0.0488|\n",
337
+ "| - high_school_mathematics | 1|none | 0|acc |↑ | 0.2481|± |0.0263|\n",
338
+ "| - high_school_physics | 1|none | 0|acc |↑ | 0.2450|± |0.0351|\n",
339
+ "| - high_school_statistics | 1|none | 0|acc |↑ | 0.2639|± |0.0301|\n",
340
+ "| - machine_learning | 1|none | 0|acc |↑ | 0.3125|± |0.0440|\n",
341
+ "|truthfulqa_gen | 3|none | 0|bleu_acc |↑ | 0.2766|± |0.0157|\n",
342
+ "| | |none | 0|bleu_diff |↑ |-10.2902|± |0.8441|\n",
343
+ "| | |none | 0|bleu_max |↑ | 26.5005|± |0.8063|\n",
344
+ "| | |none | 0|rouge1_acc |↑ | 0.2619|± |0.0154|\n",
345
+ "| | |none | 0|rouge1_diff|↑ |-13.4103|± |0.8561|\n",
346
+ "| | |none | 0|rouge1_max |↑ | 51.0861|± |0.8835|\n",
347
+ "| | |none | 0|rouge2_acc |↑ | 0.2240|± |0.0146|\n",
348
+ "| | |none | 0|rouge2_diff|↑ |-15.4705|± |1.0517|\n",
349
+ "| | |none | 0|rouge2_max |↑ | 35.0729|± |1.0250|\n",
350
+ "| | |none | 0|rougeL_acc |↑ | 0.2619|± |0.0154|\n",
351
+ "| | |none | 0|rougeL_diff|↑ |-13.6375|± |0.8721|\n",
352
+ "| | |none | 0|rougeL_max |↑ | 48.4303|± |0.8983|\n",
353
+ "|truthfulqa_mc1 | 2|none | 0|acc |↑ | 0.2069|± |0.0142|\n",
354
+ "|truthfulqa_mc2 | 2|none | 0|acc |↑ | 0.3252|± |0.0131|\n",
355
+ "\n",
356
+ "| Groups |Version|Filter|n-shot|Metric| |Value | |Stderr|\n",
357
+ "|------------------|------:|------|------|------|---|-----:|---|-----:|\n",
358
+ "|mmlu | 2|none | |acc |↑ |0.3126|± |0.0039|\n",
359
+ "| - humanities | 2|none | |acc |↑ |0.3101|± |0.0067|\n",
360
+ "| - other | 2|none | |acc |↑ |0.3399|± |0.0084|\n",
361
+ "| - social sciences| 2|none | |acc |↑ |0.3052|± |0.0083|\n",
362
+ "| - stem | 2|none | |acc |↑ |0.2965|± |0.0081|\n",
363
+ "\n",
364
+ "```\n",
365
+ "\n"
366
+ ]
367
+ },
368
+ {
369
+ "cell_type": "markdown",
370
+ "metadata": {},
371
+ "source": [
372
+ "# Training"
373
+ ]
374
+ },
375
+ {
376
+ "cell_type": "markdown",
377
+ "metadata": {},
378
+ "source": [
379
+ "## Define training loop"
380
+ ]
381
+ },
382
+ {
383
+ "cell_type": "code",
384
+ "execution_count": 15,
385
+ "metadata": {},
386
+ "outputs": [],
387
+ "source": [
388
+ "from transformers import AdamW, get_linear_schedule_with_warmup\n",
389
+ "\n",
390
+ "optimizer = AdamW(model.parameters(), lr=5e-5)\n",
391
+ "\n",
392
+ "num_epochs = 3\n",
393
+ "num_training_steps = num_epochs * len(tokenized_train_dataset)\n",
394
+ "lr_scheduler = get_linear_schedule_with_warmup(\n",
395
+ " optimizer, num_warmup_steps=0, num_training_steps=num_training_steps\n",
396
+ ")"
397
+ ]
398
+ },
399
+ {
400
+ "cell_type": "markdown",
401
+ "metadata": {},
402
+ "source": [
403
+ "## Dataloader for training"
404
+ ]
405
+ },
406
+ {
407
+ "cell_type": "code",
408
+ "execution_count": 16,
409
+ "metadata": {},
410
+ "outputs": [],
411
+ "source": [
412
+ "from torch.utils.data import DataLoader\n",
413
+ "\n",
414
+ "train_dataloader = DataLoader(tokenized_train_dataset, shuffle=True, batch_size=2) "
415
+ ]
416
+ },
417
+ {
418
+ "cell_type": "markdown",
419
+ "metadata": {},
420
+ "source": [
421
+ "## Run training loop"
422
+ ]
423
+ },
424
+ {
425
+ "cell_type": "code",
426
+ "execution_count": 20,
427
+ "metadata": {},
428
+ "outputs": [
429
+ {
430
+ "name": "stderr",
431
+ "output_type": "stream",
432
+ "text": [
433
+ " 23%|██▎ | 686/3000 [04:50<16:20, 2.36it/s]\n"
434
+ ]
435
+ },
436
+ {
437
+ "name": "stdout",
438
+ "output_type": "stream",
439
+ "text": [
440
+ "Epoch 1/3 - Average Loss: 2.9037\n"
441
+ ]
442
+ },
443
+ {
444
+ "name": "stderr",
445
+ "output_type": "stream",
446
+ "text": []
447
+ },
448
+ {
449
+ "name": "stdout",
450
+ "output_type": "stream",
451
+ "text": [
452
+ "Epoch 2/3 - Average Loss: 2.0474\n"
453
+ ]
454
+ },
455
+ {
456
+ "name": "stderr",
457
+ "output_type": "stream",
458
+ "text": []
459
+ },
460
+ {
461
+ "name": "stdout",
462
+ "output_type": "stream",
463
+ "text": [
464
+ "Epoch 3/3 - Average Loss: 1.4295\n"
465
+ ]
466
+ }
467
+ ],
468
+ "source": [
469
+ "from tqdm.auto import tqdm\n",
470
+ "\n",
471
+ "progress_bar = tqdm(range(num_training_steps))\n",
472
+ "\n",
473
+ "model.train()\n",
474
+ "for epoch in range(num_epochs):\n",
475
+ " total_loss = 0\n",
476
+ "\n",
477
+ " for batch in train_dataloader:\n",
478
+ " batch = {k: v.to(model.device) for k, v in batch.items()}\n",
479
+ " outputs = model(**batch, labels=batch[\"input_ids\"])\n",
480
+ " loss = outputs.loss\n",
481
+ " total_loss += loss.item()\n",
482
+ " loss.backward()\n",
483
+ "\n",
484
+ " optimizer.step()\n",
485
+ " lr_scheduler.step()\n",
486
+ " optimizer.zero_grad()\n",
487
+ " progress_bar.update(1)\n",
488
+ "\n",
489
+ " average_loss = total_loss / len(train_dataloader)\n",
490
+ " print(f\"Epoch {epoch+1}/{num_epochs} - Average Loss: {average_loss:.4f}\") # Print the loss"
491
+ ]
492
+ },
493
+ {
494
+ "cell_type": "markdown",
495
+ "metadata": {},
496
+ "source": [
497
+ "## Loss minimisation\n",
498
+ "\n",
499
+ "We see clear loss minimisation after just a few training loops (3 epochs over 1000 samples).\n",
500
+ "\n",
501
+ "Epoch 1/3 - Average Loss: 2.9037\n",
502
+ "\n",
503
+ "Epoch 2/3 - Average Loss: 2.0474\n",
504
+ "\n",
505
+ "Epoch 3/3 - Average Loss: 1.4295"
506
+ ]
507
+ },
508
+ {
509
+ "cell_type": "markdown",
510
+ "metadata": {},
511
+ "source": [
512
+ "# Push model to hub"
513
+ ]
514
+ },
515
+ {
516
+ "cell_type": "code",
517
+ "execution_count": 22,
518
+ "metadata": {},
519
+ "outputs": [
520
+ {
521
+ "name": "stderr",
522
+ "output_type": "stream",
523
+ "text": [
524
+ "model.safetensors: 100%|██████████| 4.17G/4.17G [05:49<00:00, 11.9MB/s]\n"
525
+ ]
526
+ },
527
+ {
528
+ "data": {
529
+ "text/plain": [
530
+ "CommitInfo(commit_url='https://huggingface.co/opyate/llama-7b-hf-redefined-3ep-1k/commit/ba69710ff29bd8ef8e0eb2460fde7cf0b8d1522c', commit_message='Upload LlamaForCausalLM', commit_description='', oid='ba69710ff29bd8ef8e0eb2460fde7cf0b8d1522c', pr_url=None, pr_revision=None, pr_num=None)"
531
+ ]
532
+ },
533
+ "execution_count": 22,
534
+ "metadata": {},
535
+ "output_type": "execute_result"
536
+ }
537
+ ],
538
+ "source": [
539
+ "from huggingface_hub import HfApi\n",
540
+ "\n",
541
+ "api = HfApi()\n",
542
+ "\n",
543
+ "trained_model_id = \"opyate/llama-7b-hf-redefined-3ep-1k\"\n",
544
+ "api.create_repo(repo_id=trained_model_id)\n",
545
+ "tokenizer.push_to_hub(trained_model_id)\n",
546
+ "model.push_to_hub(trained_model_id)"
547
+ ]
548
+ },
549
+ {
550
+ "cell_type": "markdown",
551
+ "metadata": {},
552
+ "source": [
553
+ "# After training"
554
+ ]
555
+ },
556
+ {
557
+ "cell_type": "markdown",
558
+ "metadata": {},
559
+ "source": [
560
+ "## Calculate validation loss"
561
+ ]
562
+ },
563
+ {
564
+ "cell_type": "code",
565
+ "execution_count": 23,
566
+ "metadata": {},
567
+ "outputs": [
568
+ {
569
+ "name": "stdout",
570
+ "output_type": "stream",
571
+ "text": [
572
+ "Validation loss before training: 9.958484322547912\n",
573
+ "Validation loss after training: 3.7852714624404906\n"
574
+ ]
575
+ }
576
+ ],
577
+ "source": [
578
+ "loss_after_training = calculate_validation_loss(model, validation_dataloader)\n",
579
+ "print(f\"Validation loss before training: {loss_before_training}\")\n",
580
+ "print(f\"Validation loss after training: {loss_after_training}\")"
581
+ ]
582
+ },
583
+ {
584
+ "cell_type": "markdown",
585
+ "metadata": {},
586
+ "source": [
587
+ "Observation: validation loss also minimised after training the model."
588
+ ]
589
+ },
590
+ {
591
+ "cell_type": "markdown",
592
+ "metadata": {},
593
+ "source": [
594
+ "## Benchmark\n",
595
+ "\n",
596
+ "Run this command:\n",
597
+ "\n",
598
+ "```\n",
599
+ "accelerate launch -m lm_eval --model hf \\\n",
600
+ " --model_args pretrained=opyate/llama-7b-hf-redefined-3ep-1k,load_in_4bit=True,dtype=\"bfloat16\" \\\n",
601
+ " --tasks mmlu,hellaswag,truthfulqa \\\n",
602
+ " --batch_size auto:4 \\\n",
603
+ " --log_samples \\\n",
604
+ " --output_path results/after-training\n",
605
+ "```\n",
606
+ "\n",
607
+ "Output:\n",
608
+ "\n",
609
+ "```\n",
610
+ "hf (pretrained=opyate/llama-7b-hf-redefined-3ep-1k,load_in_4bit=True,dtype=bfloat16), gen_kwargs: (None), limit: None, num_fewshot: None, batch_size: auto:4 (16,64,64,64)\n",
611
+ "| Tasks |Version|Filter|n-shot| Metric | | Value | |Stderr|\n",
612
+ "|---------------------------------------|------:|------|-----:|-----------|---|------:|---|-----:|\n",
613
+ "|hellaswag | 1|none | 0|acc |↑ | 0.2922|± |0.0045|\n",
614
+ "| | |none | 0|acc_norm |↑ | 0.3176|± |0.0046|\n",
615
+ "|mmlu | 2|none | |acc |↑ | 0.2400|± |0.0036|\n",
616
+ "| - humanities | 2|none | |acc |↑ | 0.2436|± |0.0063|\n",
617
+ "| - formal_logic | 1|none | 0|acc |↑ | 0.2698|± |0.0397|\n",
618
+ "| - high_school_european_history | 1|none | 0|acc |↑ | 0.2182|± |0.0323|\n",
619
+ "| - high_school_us_history | 1|none | 0|acc |↑ | 0.2843|± |0.0317|\n",
620
+ "| - high_school_world_history | 1|none | 0|acc |↑ | 0.2574|± |0.0285|\n",
621
+ "| - international_law | 1|none | 0|acc |↑ | 0.2314|± |0.0385|\n",
622
+ "| - jurisprudence | 1|none | 0|acc |↑ | 0.2778|± |0.0433|\n",
623
+ "| - logical_fallacies | 1|none | 0|acc |↑ | 0.2638|± |0.0346|\n",
624
+ "| - moral_disputes | 1|none | 0|acc |↑ | 0.2601|± |0.0236|\n",
625
+ "| - moral_scenarios | 1|none | 0|acc |↑ | 0.2380|± |0.0142|\n",
626
+ "| - philosophy | 1|none | 0|acc |↑ | 0.2283|± |0.0238|\n",
627
+ "| - prehistory | 1|none | 0|acc |↑ | 0.2623|± |0.0245|\n",
628
+ "| - professional_law | 1|none | 0|acc |↑ | 0.2327|± |0.0108|\n",
629
+ "| - world_religions | 1|none | 0|acc |↑ | 0.2339|± |0.0325|\n",
630
+ "| - other | 2|none | |acc |↑ | 0.2594|± |0.0078|\n",
631
+ "| - business_ethics | 1|none | 0|acc |↑ | 0.3200|± |0.0469|\n",
632
+ "| - clinical_knowledge | 1|none | 0|acc |↑ | 0.2528|± |0.0267|\n",
633
+ "| - college_medicine | 1|none | 0|acc |↑ | 0.2486|± |0.0330|\n",
634
+ "| - global_facts | 1|none | 0|acc |↑ | 0.2900|± |0.0456|\n",
635
+ "| - human_aging | 1|none | 0|acc |↑ | 0.3857|± |0.0327|\n",
636
+ "| - management | 1|none | 0|acc |↑ | 0.2524|± |0.0430|\n",
637
+ "| - marketing | 1|none | 0|acc |↑ | 0.2735|± |0.0292|\n",
638
+ "| - medical_genetics | 1|none | 0|acc |↑ | 0.2600|± |0.0441|\n",
639
+ "| - miscellaneous | 1|none | 0|acc |↑ | 0.2414|± |0.0153|\n",
640
+ "| - nutrition | 1|none | 0|acc |↑ | 0.2451|± |0.0246|\n",
641
+ "| - professional_accounting | 1|none | 0|acc |↑ | 0.2447|± |0.0256|\n",
642
+ "| - professional_medicine | 1|none | 0|acc |↑ | 0.1912|± |0.0239|\n",
643
+ "| - virology | 1|none | 0|acc |↑ | 0.2892|± |0.0353|\n",
644
+ "| - social sciences | 2|none | |acc |↑ | 0.2327|± |0.0076|\n",
645
+ "| - econometrics | 1|none | 0|acc |↑ | 0.2193|± |0.0389|\n",
646
+ "| - high_school_geography | 1|none | 0|acc |↑ | 0.1818|± |0.0275|\n",
647
+ "| - high_school_government_and_politics| 1|none | 0|acc |↑ | 0.2021|± |0.0290|\n",
648
+ "| - high_school_macroeconomics | 1|none | 0|acc |↑ | 0.2077|± |0.0206|\n",
649
+ "| - high_school_microeconomics | 1|none | 0|acc |↑ | 0.2353|± |0.0276|\n",
650
+ "| - high_school_psychology | 1|none | 0|acc |↑ | 0.2349|± |0.0182|\n",
651
+ "| - human_sexuality | 1|none | 0|acc |↑ | 0.2443|± |0.0377|\n",
652
+ "| - professional_psychology | 1|none | 0|acc |↑ | 0.2598|± |0.0177|\n",
653
+ "| - public_relations | 1|none | 0|acc |↑ | 0.2909|± |0.0435|\n",
654
+ "| - security_studies | 1|none | 0|acc |↑ | 0.2041|± |0.0258|\n",
655
+ "| - sociology | 1|none | 0|acc |↑ | 0.2587|± |0.0310|\n",
656
+ "| - us_foreign_policy | 1|none | 0|acc |↑ | 0.2600|± |0.0441|\n",
657
+ "| - stem | 2|none | |acc |↑ | 0.2226|± |0.0074|\n",
658
+ "| - abstract_algebra | 1|none | 0|acc |↑ | 0.3100|± |0.0465|\n",
659
+ "| - anatomy | 1|none | 0|acc |↑ | 0.2519|± |0.0375|\n",
660
+ "| - astronomy | 1|none | 0|acc |↑ | 0.1711|± |0.0306|\n",
661
+ "| - college_biology | 1|none | 0|acc |↑ | 0.2292|± |0.0351|\n",
662
+ "| - college_chemistry | 1|none | 0|acc |↑ | 0.2200|± |0.0416|\n",
663
+ "| - college_computer_science | 1|none | 0|acc |↑ | 0.1300|± |0.0338|\n",
664
+ "| - college_mathematics | 1|none | 0|acc |↑ | 0.2400|± |0.0429|\n",
665
+ "| - college_physics | 1|none | 0|acc |↑ | 0.1667|± |0.0371|\n",
666
+ "| - computer_security | 1|none | 0|acc |↑ | 0.1600|± |0.0368|\n",
667
+ "| - conceptual_physics | 1|none | 0|acc |↑ | 0.2766|± |0.0292|\n",
668
+ "| - electrical_engineering | 1|none | 0|acc |↑ | 0.2483|± |0.0360|\n",
669
+ "| - elementary_mathematics | 1|none | 0|acc |↑ | 0.2196|± |0.0213|\n",
670
+ "| - high_school_biology | 1|none | 0|acc |↑ | 0.2097|± |0.0232|\n",
671
+ "| - high_school_chemistry | 1|none | 0|acc |↑ | 0.2217|± |0.0292|\n",
672
+ "| - high_school_computer_science | 1|none | 0|acc |↑ | 0.2200|± |0.0416|\n",
673
+ "| - high_school_mathematics | 1|none | 0|acc |↑ | 0.3000|± |0.0279|\n",
674
+ "| - high_school_physics | 1|none | 0|acc |↑ | 0.1457|± |0.0288|\n",
675
+ "| - high_school_statistics | 1|none | 0|acc |↑ | 0.1667|± |0.0254|\n",
676
+ "| - machine_learning | 1|none | 0|acc |↑ | 0.2768|± |0.0425|\n",
677
+ "|truthfulqa_gen | 3|none | 0|bleu_acc |↑ | 0.0073|± |0.0030|\n",
678
+ "| | |none | 0|bleu_diff |↑ | 0.0010|± |0.0008|\n",
679
+ "| | |none | 0|bleu_max |↑ | 0.0187|± |0.0088|\n",
680
+ "| | |none | 0|rouge1_acc |↑ | 0.0220|± |0.0051|\n",
681
+ "| | |none | 0|rouge1_diff|↑ |-0.0077|± |0.0277|\n",
682
+ "| | |none | 0|rouge1_max |↑ | 0.0726|± |0.0213|\n",
683
+ "| | |none | 0|rouge2_acc |↑ | 0.0024|± |0.0017|\n",
684
+ "| | |none | 0|rouge2_diff|↑ | 0.0031|± |0.0043|\n",
685
+ "| | |none | 0|rouge2_max |↑ | 0.0048|± |0.0039|\n",
686
+ "| | |none | 0|rougeL_acc |↑ | 0.0220|± |0.0051|\n",
687
+ "| | |none | 0|rougeL_diff|↑ |-0.0093|± |0.0278|\n",
688
+ "| | |none | 0|rougeL_max |↑ | 0.0709|± |0.0208|\n",
689
+ "|truthfulqa_mc1 | 2|none | 0|acc |↑ | 0.2277|± |0.0147|\n",
690
+ "|truthfulqa_mc2 | 2|none | 0|acc |↑ | 0.4685|± |0.0171|\n",
691
+ "\n",
692
+ "| Groups |Version|Filter|n-shot|Metric| |Value | |Stderr|\n",
693
+ "|------------------|------:|------|------|------|---|-----:|---|-----:|\n",
694
+ "|mmlu | 2|none | |acc |↑ |0.2400|± |0.0036|\n",
695
+ "| - humanities | 2|none | |acc |↑ |0.2436|± |0.0063|\n",
696
+ "| - other | 2|none | |acc |↑ |0.2594|± |0.0078|\n",
697
+ "| - social sciences| 2|none | |acc |↑ |0.2327|± |0.0076|\n",
698
+ "| - stem | 2|none | |acc |↑ |0.2226|± |0.0074|\n",
699
+ "```"
700
+ ]
701
+ },
702
+ {
703
+ "cell_type": "markdown",
704
+ "metadata": {},
705
+ "source": [
706
+ "# Conclusion\n",
707
+ "\n",
708
+ "The benchmarks generally performed worse after training. E.g. before training, `hellaswag` on `acc_norm` showed reasonable performance (0.7498), then more than halved after training (0.3176). `truthfulqa_mc1` and `truthfulqa_mc2` show slight improvements.\n",
709
+ "\n",
710
+ "There are various reasons this could be:\n",
711
+ "- We used a quantised (4bit) model (quantisation reduces model weight precision, which introduces approximation error)\n",
712
+ "- and a very small number of training samples (not enough to learn from)\n",
713
+ "- might be issues with the training setup e.g., \n",
714
+ " - overfitting: The model might have memorized the training data too well and is now performing poorly on unseen data (the validation set used for `lm-eval`).\n",
715
+ " - data preparation: There could be problems with the training data, such as noise, inconsistencies, or biases that are negatively impacting the model's learning\n",
716
+ " - hyperparameters: The learning rate, batch size, weight decay, etc might not be optimal for this specific task and model, and can be remedied with hyper parameter search techniques.\n",
717
+ "\n",
718
+ "I generally used quantisation, small batch sizes, and a small sample size to complete this task in good time. I would have also liked to show a [Gradio leaderboard](https://huggingface.co/spaces/freddyaboulton/gradio_leaderboard/tree/main) to compare the bench results, but enough can be gleaned from just looking at the numbers."
719
+ ]
720
+ }
721
+ ],
722
+ "metadata": {
723
+ "kernelspec": {
724
+ "display_name": ".venv",
725
+ "language": "python",
726
+ "name": "python3"
727
+ },
728
+ "language_info": {
729
+ "codemirror_mode": {
730
+ "name": "ipython",
731
+ "version": 3
732
+ },
733
+ "file_extension": ".py",
734
+ "mimetype": "text/x-python",
735
+ "name": "python",
736
+ "nbconvert_exporter": "python",
737
+ "pygments_lexer": "ipython3",
738
+ "version": "3.12.3"
739
+ }
740
+ },
741
+ "nbformat": 4,
742
+ "nbformat_minor": 2
743
+ }