Hands-On AI 9 Transcript
Please be advised that this transcript is AI-generated and may not be word-for-word. Time codes refer to the approximate times in the ad-free version of the show.
Mikah Sargent [00:00:00]:
Remember in the first episode when we were working with a local model on a little MacBook Air? Well, we're taking a look at that again today. So as you can see on screen, I have 2 terminal windows and in those windows I have Ollama running Quen locally. This is the Quen 3.59B model. Now we're going to talk about the exact command prompt that we typed in. But the point is what I did was I told it to give me an answer without doing the thinking part. Remember, the thinking part is where it was typing out all of that stuff. And then it came to an answer at the end. This time I said, just give it to me immediately.
Mikah Sargent [00:00:36]:
So it's the same model, it's the same prompt, thinking is off, but it's on 2 different devices. My M2 MacBook Air, the one from episode 1, and the— well, that had 16 gigs of memory, and the M5 Max Mac Studio that I'm also using with 48 gigs. So what I did was I typed in the prompt in 3 sentences, explain why bread dough needs time to rise. And each of them provided an answer. Which With the results of how much, how long it took to actually do what I needed to do or how fast it was able to do so. So the same model, the same question. And on the MacBook Air, the eval rate, which we'll talk about shortly, it was 12.79 tokens per second. Whereas on the Mac Studio, it was 81.81 tokens per second.
Mikah Sargent [00:01:25]:
And that matters because that tells you how fast it was. A listener named Carl wrote in with a question that I absolutely loved about this. Carl has a 16GB M3 Air and is considering a 32GB M5 Air. Now he wants to stay with the Air and he wants to know the practical limits and whether he should go even bigger. He also asked when I'd follow up on episode 1, where my Air was still thinking about a schedule. What was it, 30 minutes? Yeah, 30 minutes after I asked. Well, today, Carl, we are doing both. I'm Mikah Sargent and this
TWiT.tv [00:02:05]:
Podcasts you love. From people you trust. This is TWiT.
Mikah Sargent [00:02:17]:
To test this out and to understand the differences, we're going to use the same air and the same model as episode 1, but this time we're actually taking measurements that we can read. That was what I showed you at the start of this episode. So, We can take a look at how these models perform by way of a tag called verbose. So we run Ollama. This is in your terminal. Ollama run quen 3.5:9b --verbose. And then it prints those stats after each answer so you can see how well it's performing. And there are 2 lines within this prompt that matter.
Mikah Sargent [00:02:59]:
The— well, for our sake, the prompt eval rate and the eval rate. The eval rate is how fast it generated the answer with thinking included, if you have thinking turned on. And prompt eval rate is how fast it was able to read the thing that I gave it, my prompt. Now remember, these are both in tokens per second. And tokens, say it with me now, are chunks of text. They are not necessarily full words. words. So let's go ahead and try by asking the torque wrench question from episode 1 and see how long it takes.
Mikah Sargent [00:03:34]:
Because remember, in episode 1, that question thought for 89.6 seconds before it actually answered. And the schedule question— remember the schedule question, the one that was supposed to kind of trip it up? Yeah, it was still generating its reasoning when I stopped watching, like 30 minutes later, I think it was. It took a long time. So As you know, the model is going to generate that reasoning before the answer. And when you have something as complicated as that schedule with all these little bits and bops that can kind of trip it up, that takes time. So we're going to do the same question of the torque wrench, but without thinking included. And this is a choice that you can make depending on what you think of the answer that you get out of the prompt. So that will help you to kind of determine.
Mikah Sargent [00:04:22]:
And the way that you do it with Quen Is, and with Ollama, is you use a little command called nothink. So let's head over to the Mac and take a look at how that is set up. So here on the MacBook Air, we're going to start by clearing things out. And then what we'll do is we'll type slash, and then we will type nothink. Now, because we all— whoops, I slash and you need to type set and then nothink. There we go. So now it does not have thinking turned on. We'll do the same on the Mac Studio.
Mikah Sargent [00:05:05]:
Now remember that when I first started this, I had already set it to thinking equals false. So it was prepared for this. But if you're starting fresh in a fresh session, in order to turn off thinking and without having to do it beforehand, you just type slash set nothink. Don't forget the set. That means change the setting. Now with this, we're going to see what the answer is to my earlier question. I'm about to use a torque wrench for the first time. What do I need to know? And we'll do that again.
Mikah Sargent [00:05:48]:
To use a torque wrench for the first time, what do I need to know? And we will let it process that as it comes up with an answer for us. And over on the Mac Studio, let's take a look at both token count and total time. You can see that the total duration on the Mac Studio, 15.51 seconds in order to do the prompt eval, remember that is reading my prompt and processing my prompt. That was 38 point— there it is, sorry, 835.45 tokens per second. That's pretty incredible. And it took 80— it was 82.48 tokens per second to answer my prompt afterward. Now the MacBook Air still running as it's typing out the answer, so we won't be able to see the stats until that completes. So we'll let that run.
Mikah Sargent [00:06:48]:
Do do do do do. And we'll take a look at it in a moment. Okay, let's take a look at the MacBook Air in comparison. We have the prompt eval rate, again, reading the prompt, 116.15 tokens per second compared to 835 on the, on the Mac Studio. And the eval rate was 12.67 tokens per second in comparison to 82.48. On the Mac Studio. So obviously quite a bit of difference. And the fact that we had to speed up the MacBook Air's answer on screen and we already had the Mac Studio's answer done and ready tells you what, what you can get when you've got a little bit more room to spread out, so to speak.
Mikah Sargent [00:07:42]:
So ultimately you have to understand that memory and overall performance do have quite the impact. When you are trying to make the decision between a, uh, between a laptop or a desktop with more power and what you should do with your model, thinking is one of the kind of settings that you can adjust so that you can speed things up or slow things down to get a better answer. Because thinking, it's useful for hard problems like the schedule that have all of those little gotchas, but on a laptop, it's kind of expensive performance-wise. So if you don't need it, Try turning it off and seeing if that helps. So back to the original question of hardware and the way that we have to look at AI, local AI especially, and its, its performance is a split between memory and bandwidth. So let's start with memory because memory is the thing that decides what Fits. It decides, frankly, what you can run at all. On a Mac, the cool thing is memory is unified on modern Macs.
Mikah Sargent [00:08:52]:
The processor and the graphics both share this one pool of memory, whereas typically on a PC that has a graphics card, you start with the card's video memory, its graphics, and you get full GPU speed. But this is why I say typically. There are some software overlays or software systems in place that can help to split the work with actual system memory. So for those of you with a PC who are watching this, it's okay. I understand that there are some ways of kind of getting around the lack of unified memory. So for good GPU speed, what you need to do when you're running these local systems is leave enough memory so that it can hold everything that the local AI is doing. That means it needs to be able to hold the model. It needs to be able to hold the specific conversation, the context, and it needs a little bit of extra breathing room or working space.
Mikah Sargent [00:09:50]:
And if it doesn't fit your local memory, then it slows way the heck down. Your Mac also will tell specific apps how much GPU work it expects to hold efficiently. So it'll kind of whisper and say, hey, this is what I think you're going to be able to do. And that figure actually varies depending on the Mac that you have. I know because lots of research has been done for these Mac Studios in particular, that my 48 gig Studio, it's about 37.5 gigs that macOS says is able to be used with a local model. And again, bear in mind that the conversation itself with the context takes memory. So the longer you go, then the more memory you actually need to hold all of that context, and that does make a difference. So let's kind of talk about what we do know about fit.
Mikah Sargent [00:10:48]:
What actually fits? Well, with a 16GB Air, as we have, it ran the 9 billion parameter model. 24 gigs. Well, for the 27 billion parameter version, the particular build, and then of course how long your conversations are, all play a role. Ollama itself lists 27B builds from— and when I say this, 27 billion parameter builds— from 16 to 20 gigs needed. 32 gigs. Well, that's a 27 billion parameter model. Also, a 35 billion parameter model can work and they can run on a 32 gig M5 Air. Okay, so going back to the original question of whether they can run on an M5 Air, they can, but you have to bear in mind that everything needs to fit.
Mikah Sargent [00:11:45]:
It's not just the models running itself, but all of the other stuff as well. You gotta leave room for the context and the apps. In episode 1, we established a rule of thumb, so go back and watch it if you haven't. Yeah. Look for a model that's about half of the memory you have available. If you keep it at half, then you've got a lot more room to expand. It leaves room for the conversation, it leaves room for your other apps, and that's very important. But as I said, memory is only one part of it.
Mikah Sargent [00:12:19]:
Bandwidth is the other part. And where memory decides what fits, Bandwidth is in charge of, or it decides how fast it's going to actually do what you're asking it to do. So memory bandwidth is essentially how many gigabytes per second the chip itself is able to read from what's in the memory. To write each token, that little chunk, the model reads most of its weights, most from memory. So There's a bit of math we can do, and look, this is gonna get hairy. It's, for me, math, not my favorite, but peak bandwidth divided by the bytes read per token kind of gives you that speed limit sign of what you can expect. So let's do some of that math. First, to estimate, you take your bandwidth and you divide it by download size.
Mikah Sargent [00:13:23]:
So download size is going to be the stand-in for the bytes, right? The, the, uh, how many gigabytes per second the chip can read from memory. And that means that for an Air, an M2 Air, it has about 100 gigabytes per second of bandwidth. And then the model download itself is 7.2 gigs. So we do 100 divided by 7.2. 1.2, and that gives us about 14 tokens a second. And that was roundabout what we got when we ran the model earlier in verbose. As for the Studio's M5, 614 gigabytes per second. And so if we do that math as well, that's about 85 tokens a second.
Mikah Sargent [00:14:11]:
Little bit under that whenever we saw the ratings, and that makes sense. Because cache traffic, software overhead, so other things that you're running can pull that result down. You have to bear that in mind when you're doing this. So the bigger the model, the longer the conversation, the more impact it's going to have. That's why we set that rule of thumb at about half of whatever your machine has. Some parts of this download, specifically its vision encoder, actually don't have to be read for every text token. And so that can bring it back up. So again, it depends on the model.
Mikah Sargent [00:14:49]:
If you watched Windows Weekly when Leo was out and I was subbing in, and actually since then, Paul has talked a lot about running local models and the trouble that he's had as he's exploring and learning about it. And we talked about how it can seem so different depending on what you're doing. This is just one of those tiny little things that make a difference. If the model has a vision encoder, but it doesn't need to use the vision encoder for text, well, then it doesn't have to call on that. And so technically, the specs for that model don't actually pertain to what's being used. It's all different and it all can make a difference. Lastly, it's important to understand that you check your measured speed. So that's where that dash dash Verbose gives you exactly what you're looking for.
Mikah Sargent [00:15:42]:
So if you get a result that beats the estimate, well, then that's great, because it means that maybe the vision encoder wasn't being used. The, the, the part of the model that can take something that is visual as opposed to just text tokens and properly convert it and make it into something that the model is able to work with. So that specifically is kind of the gap that we saw at the beginning. The Studio has about 6 times the rated memory bandwidth of the M2 Air. And so it is much faster. I mean, yes, it's what we would expect, but now you can understand how much of a difference it makes when we're using that same model on both devices. Let's continue on to talk about the tuning of your Mac to get what you're after. Because frankly, there are really 2 speeds that are involved and that verbose readout that we talked about before will show you the difference between those 2 speeds because we have to look at the different parts of a model.
Mikah Sargent [00:16:57]:
And it starts with prefill. So reading your prompt, the part where it's actually taking what you're saying and reading it into the system so that the model can do its work, that's called prefill. And so it processes the part of your prompt in chunks, and it does it all at once. And well, it can be limited by compute. Long prefills, so Ones that are taking longer than you'd expect often depend heavily on how much math the chip can do at once. Now, writing the answer, that's called decode. So prefill versus decode. It is decoding one token after another.
Mikah Sargent [00:17:42]:
Tokens per second still. And it is limited by bandwidth. So it relies heavily on memory bandwidth. If you have heard Leo talking about using a Mac versus using his DGX Sparks and how he doesn't like using a Mac. That's because a Mac can write tokens very quickly with decode, but it can still leave you waiting on a long prompt because prefill takes longer on a Mac and the DGX Sparks really good at the prefill part. So you still have to wait for it to be able to take in the answer that you're giving it. Even if it can write out the answer very quickly. NVIDIA's DGX Sparks, the reason why this works is because they have 128 gigs of memory.
Mikah Sargent [00:18:37]:
And what are we talking about in terms of speed? 273 gigabytes per second. So that's less than half the bandwidth that the Studio has, but it is much better at the prefill. A lot of AI-specific hardware to do that math. It's, you know, whereas my Mac Studio is designed to do a lot more than just AI, those can be focused directly on AI. There's one group that does single-stream tests, and in doing so, the Spark Red prompts quickly, but dense model generation was much slower. So it can be. A trade-off. So ha, Leo.
Mikah Sargent [00:19:20]:
No, my Mac Studio can again get the answer in the end out to me quickly. But the part where it's pulling it in, that can take a little bit more time and leave you waiting. So that's where I like to use smaller models, even on more powerful Macs like the Mac Studio. What can you try to help to tune things on your Mac specifically? Well, there are 4 things to try on your Mac. The first thing that you want to look for is using a supported MLX build. MLX is Apple's machine learning framework specific to Apple Silicon. So the good news is if you're using Ollama like I've suggested you do so, Ollama now uses it automatically when a specific model supports it. So you don't have to worry about that in the background.
Mikah Sargent [00:20:16]:
As far as if you're using LM Studio instead of Ollama, you do need to choose an MLX build. Reusing an identical prompt prefix is another thing that you can do to tune your max. So this is, this is important to understand when it comes to how a model takes in what you're saying, actually understands what you're saying. Reusing an identical prompt prefix means that if the beginning of your prompt stays the same throughout, then Ollama can reuse the work it already did as long as it's still in the cache. So by default, it actually keeps the model loaded for 5 minutes after a request. What does all that mean? It means that It only needs to process new information that you're adding to it. So you may find that the first time you prompt the system, if you've got something that is kind of laying the foundation of the model, you're telling it, I want you to work this way, I want you to do this, I want you to understand this. That is something that can stick between because it's already done that processing.
Mikah Sargent [00:21:33]:
It's already figured it out. And it's only going, okay, now this is what the person wants afterward. And another thing that you can do to improve speeds on your Mac, and you'll hear this a lot, a mixture of experts model. What is that? Well, Quen 3.5's 35B-A3B. Yes, I love all of these terms. I'm sure you do too. It has 35 billion parameters, but the A3B means that About 3 billion are active per token at a given time. So that means that it can actually generate faster than a similarly sized model because each individual token doesn't need to use all of those weights.
Mikah Sargent [00:22:18]:
But just make sure that you still budget memory for all of the experts at once. And again, this specific episode is looking at answering the question of local hardware. We've still got so much— it's, it's, we've got so much more work to do when it comes to kind of digging into the different terms. And I always encourage you to, to check them out yourself. And in fact, you know, I might end up putting together a glossary of terms that you can access to learn a little bit about these things so you can sort of understand it outside of this. You can— I have a glossary that I studied and researched and built before starting this show to make sure that I understood what each of the terms meant and so that I could explain them for people who are new to this. And I'm realizing that's probably something that could be available to you wonderful listeners. So here's what I'll say.
Mikah Sargent [00:23:21]:
If 5 people If you email me, hoai@twit.tv, and ask me to publish that glossary, I'll do it. Otherwise, I'll assume that many of you who are watching the show or listening to the show already know these terms and don't need it, or you're waiting for future episodes where I explain in more depth things like mixture of experts models. Heck, if they continue to be important, they may very well not be. As it stands, an important way to help speed up your output or your decode. Excuse me, your— no, your prefill. All right, let's continue on. The other thing that you can do is trim uncached input. So every new token in your prompt has to be read in order for the model to be able to provide an answer.
Mikah Sargent [00:24:20]:
So shorter instructions, fewer pasted bits of information means less to take in. Remember that in episode 8, we talked about Anything LLM, and it retrieved out of the manual 4 excerpts. That's the benefit of having RAG, of not needing to pull in every single thing that you are doing, but instead being able to just, uh, pull in the parts of the information that you need. It helps to speed things up. And of course, newer chips can also have an impact. Apple added neural accelerators to the M5's GPU, and in Apple's tests of an M5 MacBook Pro against an M4 MacBook Pro with long prompts, The wait for the first token was up to about 4 times shorter, and writing was able to get 19 to 27% faster. How do you judge your own setup? Well, if you find yourself pasting long documents, then go ahead and time the wait for the first token. Okay? Because that is the prefill.
Mikah Sargent [00:25:36]:
That's where you're, you're pulling in all of that information. But if you ask short questions and you're hoping that you'll get longer answers afterward, then generation speed is the thing that makes more of a difference. Continuing on with Carl's question, he asked about fans because of course MacBook Air, a fanless device. I'm glad he's a fan of the show though. Ha! So Carl knows that the Air Has no fan, and a fanless Air will slow down during sustained work as it gets hotter. And so it can make a difference. I have my M2 Air, it's currently plugged in, and what I'm going to do is ask the model for long answers back to back for 10 minutes. Then, This script will log the elapsed time and the speed of each answer.
Mikah Sargent [00:26:38]:
We're going to do this and see what happens over time as this fanless MacBook Air gets warmer, in theory, as it continues to do this over and over again. So we'll pause and we'll come back and we'll look at the answer. And we are back. We've skipped ahead 10 minutes and ran the log on the MacBook Air so that we could figure out if thermals slow it down. Uh, the first answer in response to the prompt came in at about 13.3 tokens a second, and then it actually climbed from there to a peak of 15.7 in the first couple of minutes. So it did get better, which makes sense if it was doing any sort of caching and, and saving in between. Around the 3-minute mark, it fell to 8.1, which is about half of its full peak. Halfway through, it was about 10.9, so it actually climbed back up a little bit.
Mikah Sargent [00:27:46]:
And then by the end, it had settled at 12.6 and held that for the last 4 minutes. So that's only about 5% below the first answer, but still it's about 20% below its best response. So it did make a difference there. The Air slowed down during sustained load, but then it seemed to find a pace and it held on, uh, to that price. So With that, it's important to understand that pauses can help to give the Air time to shed heat. And that is something that I did was pause to let it cool down before we started that test. And if, Carl, you're running your, your local models on a MacBook Air, keep in mind that active cooling can help during that sustained work. So if you wanted to, cool the MacBook Air through some means.
Mikah Sargent [00:28:48]:
There are lots of laptop coolers that can help. Now, Carl, when Carl wrote in, Carl asked a couple of questions as part of this. He says, I'm wondering when you're going to follow up on your first episode where you were trying to run an LLM on your MBA MacBook Air and 30 minutes had passed and the model was still grinding away. So that's this, of course. He says, I also have an M3 MacBook Air with 16 gigs of RAM, Debating upgrading. I understand the fanless throttling limitations, but I don't want to upgrade to a MacBook Pro. Can you help us understand the practical limits of running an LLM on an MBA? And this is the important part for this next question. Carl says, I was going to go with the M5 and 32GB.
Mikah Sargent [00:29:31]:
Should I go bigger? Well, let's talk about the upgrade. First and foremost, understand that I don't have an M5 Air to test, so it could be different for you. This is just working with Apple's specs, it's working with our estimates, and it's working with tests that other people have done because we're all nerds, we're all running tests, and many of us choose to publish them. Thank you to those of you who have done so. So as far as Carl's upgrade, let's see, the M3 Air and my M2 Air both have 100 gigabytes per second of bandwidth. Uh, so my M2 gives us about the same starting number for the estimate. That said, Carl's M3 can still measure differently and Carl's M3 Air Tops out at 24 gigs. As for M5, it has 153 gigs per second and goes up to 32 gigs of memory.
Mikah Sargent [00:30:28]:
So if we look at that, the rated bandwidth is higher, 53% more rated bandwidth than you get with the M2 that I have. On the same 7.2 gig model of QN, the estimate rises From about 14 tokens per second to about 21. And of course, it has those GPU neural accelerators, which can have a— make a difference as well. If you have software that makes use of those, it can speed up long prompts. Apple's roughly fourfold result came from an M5 MacBook Pro, so do bear that in mind. And so an M3 to M5 Air improvement isn't something that we have Measurable, but it could still make quite a difference. And of course, memory. It's the bigger change because that's for the context, the beforehand, and not the output, or as much with the output.
Mikah Sargent [00:31:28]:
32 gigs is double your current amount, Carl, of 16. So that's larger builds, builds, that's longer conversations. A 32-gig M5 Air has and can run a dense 27B model. Bigger models, they do write slower though. The 17GB, 27 billion parameter build, which again, with the bandwidth 153GB per second, if we do our measurements, that's about 9 tokens a second. Not very fast. Testers have also run the 35B mixture of experts model, which remember doesn't have to make use of all of those at once, on a 32GB M5 Air, The build, the conversation length, and your other apps will decide how much headroom you actually have. So on the question of should I go bigger, well, on a MacBook Air, 32 gigs is as big as it gets.
Mikah Sargent [00:32:24]:
And anything bigger than that would mean a MacBook Pro. Carl, you didn't want that. And anything bigger than that would be a desktop, and it sounds like, Carl, you don't want that. So that is going to determine whether you want to make the upgrade past the 32 gigs. You'd have to go for a MacBook Pro at that point. And depending on what you're doing and which models you're using, clearly you've seen that you may not need to, which is nice. Start with the 16-gig M3 that you own and try tuning it first with what we talked about today. A 9B model on the questions that you actually ask and have it not have thinking So turn off thinking.
Mikah Sargent [00:33:06]:
Then you judge the answers, you see if you like what it says, and you judge the wait before it actually starts responding. And of course, you judge the pace of the response. And if you want to carry a larger model with you, you know, it can sit there and be ready for you when you want it. The 32GB M5 Air, that's gonna be a meaningful upgrade, 53%. If you mainly need the heavier model at home, Frankly, a desktop is what you're going to need to hold it. And if you want it offline while you travel, well, then the laptop is the one that makes sense. Carl asked about also running a local model on a more powerful machine and just using your laptop to connect to it. That's going to be something that we talk about in future episodes.
Mikah Sargent [00:33:55]:
So, Carl, memory, Remember, decides what fits. Bandwidth sets how fast it can write, and thinking decides how much it writes. So you can turn off thinking to get to what you're looking for faster. If you'd like some homework, mine for you is this: run your favorite model with that little flag that we talked about, --verbose, and then read your own tokens per second. Then try it with --thinking. Think equals false, which will turn off thinking. If you have a question like Carl's, well, send it to handsonaiai@twit.tv. Hit subscribe or follow wherever you're watching or listening, or head to twit.tv/HOI.
Mikah Sargent [00:34:37]:
And if you want it ad-free, that's Club Twit, twit.tv/clubtwit. I'm Mikah Sargent. Don't just wonder about AI, get your hands on it. I'll see you next time. Thanks, Mikah.