Phi-1: A 'Textbook' Model

Microsoft's Phi-1 is a 1.3 billion parameter model trained on filtered Python code and synthetic textbooks that achieves over 50% pass rates on coding tasks, rivaling much larger models like GPT-4. The breakthrough came from data quality and repeated training epochs rather than scale, though the model struggles outside its narrow domain.
Chapters
The importance of the new Phi 1 model isn't just that it's small enough to be on a smartphone set, to be open sourced and capable of interview level Python coding tasks. Its significance is also in what the model tells us about the future of language models and the timelines of our march to human level intelligence. I spoke in depth with one of the authors of the paper, Ronan Eldan, to get you more insights and I'm only going to cover the best bits, so let's start. First thing to notice is how small this model is at 1.3 billion parameters. But what does that number mean? Well, for reference, that's about 1% the size of GPT3, which was behind the original ChatGPT phenomenon. And if recent rumors are to be believed, it's about a thousand times smaller than the combined parameter count of GPT4. So we're talking a tiny model here that could fit on my Samsung S23. We read that despite this small scale, PHI1 attains a pass at 1 accuracy. That means pass first time of 50% on huge human eval testing Python coding challenges Andrej Karpathy of OpenAI and Tesla fame said that we're probably going to see a lot more of this creative scaling down work prioritizing data quality and diversity over quantity, using synthetic data to create small but highly capable expert models. And the author I spoke to actually retweeted that and said for skeptics the model will be available on Hugging face soon. Give it a try. Back to the paper which says everyone knows about scaling laws, adding more compute, adding more data, but following the footsteps of Eldan and Lee in tiny stories, which I'll get to in a second, we explore the improvement that can be obtained along a different axis, the quality of the data. Of course anyone familiar with my ORCA video will know that data quality is super important, but let's get to this paper they mentioned and I'm going to give you the 32nd version of the paper co authored by Ronan. They created a diverse and synthetic data set of short stories using GPT 3.5 and GPT 4 and then they trained tiny 28 million parameter models and smaller actually, which as they say are two orders of magnitude smaller than GPT2, which was only 1.5 billion parameters. And by curating the synthetic data carefully, look at the difference in results. The ending of this story was so much better on the tiny model trained on this synthetic data set, especially compared to GPT2 which is so much bigger, but it says the soup is too old It's a terrible ending to the story. So what did they do for Phi 1? Well, here is the short version. They filtered the stack and stack overflow to only get the most teachable bits of code consisting of about 6 billion tokens. They then created a synthetic textbook consisting of about 1 billion tokens of GPT 3.5. Generated Python textbooks. That's not even GPT 4. Then quite crucially, they created a small synthetic exercises dataset consisting of only 180 million tokens of exercises and solutions. Now of course other people have used the stack before, but as Ronan says, I do think that from the data we do have, we are not even close close to extracting everything from it. And look at the results of this tiny 1.3 billion parameter model. Trained in this way. There have been only two models that have scored more than 50% on human eval passup. One that's Wizard Coder and of course GPT4. But of course those models are massively bigger and therefore much more expensive to train. And actually I find this chart perhaps the most interesting one of all in the entire paper. You can see so many trends in one diagram. Let me try to pick a few of these out. And remember, the scores are the percentage accuracy on human eval. Think moderate level coding challenges. First, look at the consistent increase from when you just train on the filtered stack versus on the synthetic code textbook from 11 to 1612 to 2017 to 29. This could be the synthetic data event horizon that Sam Altman talked about. And that code textbook was generated using GPT 3.5, not even GPT 4. Next, compare the parameter counts of the models. 350 million on the left and in the center and 1.3 billion on the right. This one isn't as big a surprise. We knew that increasing the parameters yields better performance, but nevertheless you can see it vividly in action. Third, and I think this one is really fascinating, look at the difference between the left and the center charts. The only thing that really changed was the number of GPU hours. And of course the number of tokens went from 26 billion to 76 billion. But wait, I thought the data set size was fixed at 7 billion. What gives? Well, of course what's happening is that they're passing over the data multiple times. This is called training for more, so called epochs or passes over the data. So these aren't new tokens, they're the same tokens being trained on more times. As Ronan said to me, my personal impression is that many people in the community thought that we would never want to do more than like one or two epochs because we'll start overfitting and just for 20 seconds. I can't resist bringing in this paper that they referenced in the textbooks paper. It's essentially talking about how you can still scale language models even if you run out of data. And take a look at these two diagrams. They say training for up to four epochs or passes is almost as good as new data. And it's only when you get to around 40 epochs that repeating is worthless. Obviously we don't know about GPT4, but GPT3 seems to be trained on far less than that. But there was one final trend from this amazing set of charts that I wanted to point out and it's probably the most obvious one. Look at the huge jump to the dark green bars. That's when they train the model on those additional synthetic exercises with solutions. The authors note that one can only imagine how frustrating and inefficient it would be for a human learner to try to acquire coding skills from such data sets like the unfiltered stack, as they would have to deal with a lot of noise, ambiguity and incompleteness in the data. We hypothesize that these issues also affect the performance of language models as they reduce the quality and quantity of the signal that maps natural language to code. Let me quickly give you a bit more detail about how how they filtered the stack. They got about 100,000 samples of the stack and stack overflow and then prompted GPT4 to determine its educational value for a student whose goal is to learn basic coding concepts. They then use those annotations to train a random forest classifier that predicts the quality of a file using its output embedding, essentially a basic searching mechanism to find out which parts of the stack are the most educational. But at this point I want to pause and imagine if they'd used a different prom. Imagine a future paper looking across a different data set. That paper could prompt GPT4 to annotate the educational value for a student whose goal is to learn French. Then you could have an amazing French speaking model. Or maybe they could get it to annotate which examples would be most educational for learning to predict the stock market and then maybe train it on a small synthetic textbook of successful previous examples of predicting the stock market. I'm just saying this seems to be a model that could be applied elsewhere. And these annotations here were the only times they GPT4. The rest was GPT 3.5 and as Ronan says, GPT4 is not only great as something we can use directly for better productivity, but it's also a way to get much better other models. And that's one thing I want OpenAI, Anthropic and Google to address the capability of their models to train smaller models. Here, by the way, is an example of the kind of exercises and solutions that the model was then fine tuned on, created of course by GPT 3.5. And the authors note that quite remarkably, the model, after fine tuning on Those fewer than 200 million tokens of exercises and solutions, also exhibits a substantial improvement in executing tasks that are not featured in the fine tuning dataset. For example, fine tuning on code exercises unexpectedly improves the model's ability to use external libraries such as pygame, even though our exercises do not contain these libraries. This suggests that fine tuning not only improves the tasks we targeted, but also makes unrelated tasks easier to distinguish. Still, it's this unexpectedness that I find really interesting. For example, before training GPT4, did they expect the emergent ability to do self repair or reflection? According to this new paper, that ability is not found in GPT 3.5. Going back to the Phione paper, the authors admit that there remain a number of limitations of our model compared to larger models for code. Firstly, Phione is specialized in Python coding, which restricts its versatility compared to multi language models. Secondly, Phione lacks the domain specific knowledge of larger models such as programming with specific APIs or using less common packages. It's a bit like the more classical narrow AI, good at only a few things. Furthermore, due to the structured nature of the datasets and the lack of diversity in terms of language and style, it's less robust to stylistic variations or errors in the prompt. It's quite funny if you make a grammatical mistake in your prompt, it does a lot worse. But what about this? This? We also believe that significant gains could be achieved by using GPT4 to generate the synthetic data instead of GPT 3.5, as we notice that GPT 3.5 data has a high error rate. I asked Ronan about that, speculating that it's because GPT4 costs more, and he said yeah, it costs more, but also GPT4 is much slower. But another reason is we wanted to demonstrate something here that you don't even need a smart model like GPT4. Even GPT 3.5, which isn't that great at coding, is enough. So there you go. You could get even better results on this using GPT4, but at the moment. GPT4 is a bit too slow. Before I get to timelines, some of you might have noticed the Wizard Coder results and wondered how that model did so well despite only being 16 billion parameters, which of course is 10 times bigger than PHI1. Well, of course I read that paper too, as well as almost every paper referenced in the textbooks paper. The secret of Wizard Coder seems to have been increasing the difficulty of the training data. Fine tune the model with more difficult examples. For example, if the original problem can be solved with only a few logical steps, please add more reasoning steps, maybe complicate the input or deepen the question or increase the reasoning involved. You can start to see the shared themes of Orca, Wizard Coder and Phi one. This could be what Sarah Constantin was pointing to in the Asterisk magazine that I read yesterday. I'm not sponsored by them, but it was a great issue so do check it out. She said Rather than a refutation of scaling laws or an acceleration of their slope, I think this is more like a move in a different direction altogether, towards a Cambrian explosion on of little AIs used for different purposes where getting good performance on a task depends on the quality of your task specific dataset like Phi1 for Python. That could be consistent with the state of the art continuing to progress steadily along scaling law lines for quite some time. But it could also mean the economic incentive towards ever bigger models would diminish and would enter an entirely new era where AI progress would not be driven primarily by semiconductor scaling or Moore's Law. This relates directly to a tweet from the co founder of Anthropic, Jack Clark. He said a world where we can push a button and stop larger compute things being built and all focus on safety for a while is good. That is really interesting to hear from someone at the top of an AGI lab, but I do have some questions for this policy. If we freeze compute, wouldn't that incentivize every company just to use algorithmic progress to get more out of the compute we do have? And so on the safety front, I think it's far more effective public messaging to focus on concrete things that everyone can understand. For example, in this paper from Oxford this week, LLMs will in particular lower barriers to biological misuse. Biological design tools will expand the capabilities of sophisticated actors. Concretely, BDTs may enable the creation of pandemic pathogens substantially worse than anything seen to date, and could enable forms of more predictable and targeted biological weapons. I think this is something that everyone can get behind and as the paper says says it's been hypothesized that for evolutionary reasons, naturally emerging pathogens feature a trade off between transmissibility, that's how much they spread and virulence, that's how deadly they are. AI based BDTs might generate design capabilities that are able to overcome this trade off. Thus, for the first time, humanity might face a security threat from pathogens substantially worse than anything nature might create, including pathogens capable of posing an existential threat. That, to be honest, is my main safety concern. But back to the paper and timelines. Here is an another snippet of my conversation with Ronan. I said I just feel like we are much closer to something really transformative than the public has quite realized. And people like OpenAI put out that in 10 years we will have something as powerful as a corporation. I say three to five years. Ronan replied, that depends on how much resources are actually spent into training bigger and bigger models. I have no idea what OpenAI and Google are doing right, definitely. If this is our main goal, I think it can easily be five years. I said. Or less, Ronan replied. Or less. I feel like the bottleneck is maybe the production of GPUs. And I mean it's not just to produce the GPUs, you also have to build the data centers and connect them to electricity, etc. Etc. I think if you have all that, then yeah, I don't see the barrier with more data, higher quality data, synthetic data, better and better algorithms and more and better GPUs and GPUs. That's what we mean when we say we don't see a barrier. Of course everyone has slightly different definitions of AGI, but almost everyone agrees that the next five to ten years are going to be the most critical in seeing whether more data, better data, better algorithms or just more and more compute will lead to AGI or superintelligence. I loved how Carl Schulman put it on the Dwarkesh Patel podcast.
If you can generate like close to $10 million a year out of the future version H100 that costs tens of thousands of dollars with a huge profit margin now, now and profit margin could be reduced with large production. That is a big difference. That chip pays for itself almost instantly and so you could support paying 10 times as much to have these fabs constructed more rapidly. If AI is starting to be able to contribute, you could have AI contributing more of the skill technical work that makes it hard for say Nvidia to suddenly find thousands upon thousands of top quality engine. If AI can provide that. Now if AI hasn't reached that level of performance, then this is how you can have things stall out. And a world where AI progress stalls out is one where you go to the 100 billion and then over succeeding years, trillion dollar things software progress turns out to stall. You lose the gains that you are getting from moving researchers from other fields, lots of of physicists and people from other areas of computer science have been going into AI. But you sort of tap out those resources as AI becomes a larger proportion of the research field. And like okay, you've put in all of these inputs, but they just haven't yielded AGI yet. I think that set of inputs probably would yield the kind of AI capabilities needed for intelligence explosion. But if it doesn't, after we've exhausted this current scale up of increasing the share of our economy that is trying to make AI, if that's not enough, then after that you have to wait for the slow grind of things like general economic growth, population growth and such. And so things slow and that results in my credences and this kind of advanced AI happening to be relatively concentrated over the next 10 years compared to the rest of the century because we can't keep going with this rapid redirection of resources into AI. That's a one time thing. Something.
Thank you so much for learning about Phi 1 with me and as always, thank you so much for staying all the way to the end. Do try to have a wonderful day.










