Section Insights
Introduction to Bug Challenges in AI Models
What types of bugs are difficult to identify in AI models?
The speaker introduces the concept of hard-to-diagnose bugs in AI models, particularly those that do not produce crashes or warnings but still yield poor outputs. They emphasize that these issues are engineering problems rather than quality issues.
- Some bugs in AI models do not crash or produce warnings.
- High confidence in model performance can mask underlying issues.
- Identifying these bugs requires a different approach than optimizing model quality.
Reproducing the Bug
How did the team attempt to reproduce the bug in the AI model?
The team struggled to reproduce the bug initially but found success by adjusting GPU memory utilization settings. By reducing memory allocation and running multiple requests simultaneously, they were able to consistently generate gibberish outputs from the model.
- Reproducing bugs can be challenging and may require specific conditions.
- Adjusting system parameters like GPU memory can help surface hidden issues.
- Using deterministic sampling methods aids in consistent bug reproduction.
Investigating Potential Causes
What steps did the team take to identify the source of the gibberish output?
The team examined various components of the VLM's engine, including the CUDA prefill kernel and memory sanitation tools. They isolated the decode kernels and found that the issue might be related to how the model processed requests.
- Thorough investigation of different components is crucial in debugging.
- Isolating parts of the system can help identify the source of issues.
- Tools like Nvidia's compute sanitizer are valuable for detecting memory issues.
Identifying the Decode Kernel Issue
What was discovered about the decode kernels during the investigation?
The team found that the decode kernels were using stale data, leading to incorrect outputs. They implemented a fix to ensure that requests were properly classified and processed, which initially seemed to resolve the issue.
- Using stale data in processing can lead to significant output errors.
- Proper classification of requests is essential for accurate model performance.
- Initial fixes may not always resolve underlying issues completely.
Understanding Memory Management Issues
What memory management issue did the team uncover, and how was it resolved?
The team discovered that a data type used in the Mamba kernels caused an overflow issue when GPU memory was reduced. By changing the data type from unsigned int to size_t, they prevented the overflow and resolved the problem.
- Memory management issues can lead to silent failures in AI models.
- Changing data types can be a simple yet effective solution to overflow problems.
- Both identified issues were related to memory pressure and had similar symptoms.
Transcript
0:15 So, put your model somewhere. Put your agent. You're hoping for the best. You're waiting for something to crash. Everything looks good. Everything's fine. and you see this and that's the problem right in these type of bugs there is no crash there's no warning no error and there's high confidence that's not a quality issue because right this is something that you don't really know what and how and why welcome to this talk my name is Ival this is aaf and together We're going to take you on a journey of how we ended up fixing those type of bugs. A little bit about us. We work at AI21, which is an AI research lab. We started as a foundation model company, most famously known for Jamba, which is a hybrid architecture between transformers and mamba, which is an SSM state. And while we were doing those, while we were training those models, while we were shipping those models into production and had users and we had a lot of workload, we got into several interesting bugs. And these are the bugs that I think are the hardest to deal with because this is not a quality problem. It's not something you can take your research team and try to optimize or solve or make the model be better at something. This is an engineering problem. This is an issue where that there is high confidence but the output is bad.
2:02 So let's break let's dive deep to the first case what we call the imposter request where just to set up the scene what are we talking about we are talking about how we during the training of our jamba model more specifically we did gpo which is a type of RL training and again this is a hybrid model layers of mamba and attention and just to make sure we're all aligned what is the type of a request So life lives life of a request. So we start with the prompt token tokenization and then in the forward pass we're doing both prefill and then decode. After that we finish the forward pass detoenization to go back to text.
2:51 And the thing about the crime here is that it's bad on so many levels but mainly on these three. This is what we call the one in thousand gibberish. It's not something that will happen in the first 500 or 900 requests, but it will happen in the 10,00 which is rare enough to duplicate it easily but not right. It's too common to ship it. Sorry. H also it only happened in VLM not in other not in any other infra framework and it's something which is laid on set. It's not something that will happen if you have only few requests. You need some sort of workload. So it's rare. It's light on set and it's very engine specific. It's a very very hard task and we had to bring one of our best detectives to handle that. So I'll give it to SF to explain how.
3:47 >> All right. Hey guys, thank you. thanks you. So we're going to start with trying to reproduce something that was very difficult to reproduce. and basically VLM has got a lot of a lot of flags, a lot of the CLI flags and a lot of knobs you guys can turn and tweak. and one of the things that helped us understand how to even reproduce it because when we try to reproduce it on the first time just sending prompts here, prompts there a few batches it didn't really help us manage to get gibberish back from our model. The model responded back just fine. So what we did was is we tried to make it happen in a very very short amount of time. So we'll get a a quick feedback loop when we try to deb debug it. So what we did was is we took one of the one of the most default and most common flag that the VLM allows you to play with which is GPU memory utilization which basically allows you to to choose how much memory how much GPU memory you want to allocate for your for your weight for your activations and for your KV cache and so on. and we reduced it from 90% to 20%. And once we did that and then we started running a lot of requests simultaneously all of a sudden request number let's say 8 854 suddenly returned gibberish and when we did that we we sampled all of the batches with temperature zero. So we'll be able to deterministically and constantly get the same request to get to return to return and respond with gibberish.
5:18 so like Ival said it happened only in VLM and we used in order to another way to reproduce it and to understand where the issue really came from. We used hugging faces transformers as a baseline since transformers is a very had a very vanilla and plain implementation of our mamba kernels as opposed to VLM which all the kernels and all the engine have gone through a lot of changes and modifications to support a lot of cool features that VLM supports. So we use transformers as our baseline to understand whether or not there is an issue with our with our inference or not with the model or not.
5:55 So what we did was we took VLM and we sent all of our prompts through VLM and we generated a response all the responses we got and now in our hands we have the response along with the log props because because in VLM you're you able to get your log props out and inspect them. Then what we did was we took the full sequence the prompt and the generation and we passed it over to to hugging faces forward pass but all we did was run just the prefill and then we samp we took this the logit out of the prefill response we ran it through softmax and then we were able to u to compare the divergence in the distributions of our tokens.
6:38 that's a short pseudo code of how that look like. You can see here that we take up the prompt. We we run it through gen BLM's generate. We get the the response back along with the with the log props. We pass it over to to hugging faces forward pass. We only run it with prefill. we've created some function called compute log log props which runs this is the softmax. then you calculate the difference between them and then you'll be able to tell the divergence between every one of the tokens log props. All right. So now that we have the tools in our hand to understand where the issue could maybe come from we started to look at different suspects in VLM's engine. So the first thing we looked at was the CUDA prefill kernel of Mamba.
7:24 we looked at it we inspected all of the all the math that's being done here that's being done there. and we looked at the tensor in, and the tensor's out before before we called the prefill and after. Everything looks just fine. Second thing we did was running Nvidia's compute sanitizer tool to really see if we have any out of bound memory. any other memory bugs or issues. Looked okay to me. then what we did was we tried to isolate between the decode kernels and the pre-filled kernels. Now, we saw that the pre-filled kernels were working just fine. So we tried to not call the decode kernels because in Mamba you're able to do that.
8:03 so what we did was we moved all of our calls and all of our computations to go through the pre through the pre-fill kernel and there you have it. The gibbish all of a sudden kind of vanished. So we were like okay it's got to be the decode kernels. But you know how it is in software you get excited too quickly and then you figure out it's not what happened. So what we did was we tried to start playing with the with VLM's engine and we kind of needed to go and you know lift the hood up and see what we can do to maybe get a bit better understanding and maybe you know get our hands dirty because BLM didn't really give us more tools to really debug our kernel and our and our forward pass.
8:45 So once so once once a tensor once the request gets all the way to your forward pass and before it goes into your prefill and decode kernels you don't really have any identity. You can't really tell what prompt is currently being processed. It's all just tensors and and numbers and matrices. So what we did was is we added to the request ID to some class called forward context that that we propagated all the way down to to Mamba's forward pass just before the the prefill and the decode kernels were called. And there we just managed to you know have a simple if condition with a request ID, the one that gave us gibberish and put a break point there and then we were able to to to infer and to really inspect all the metadata that comes along with it. And the second we did that, we saw that the request was for the first time when it went through the through the forward pass, it's actually doing decode before prefill.
9:43 the scheduler decided that it's that that this request should be doing decode before prefill and as Uval said earlier in our in the life cycle of a prompt a prompt should first be going through prefill and then decode and what happens was is that when when in Mamba you run a request first with a with decode first after a long a lot of other requests were already computed the state was already kind of overused and we were using the data and the computations of stale requests, requests that came before it. So now we were actually running decode on on previous requests and that kind of generated gibberish for us. So the kernels weren't doing the wrong thing, they were called at the wrong time for the wrong requests. And now and why did it matter only for Mamba? The reason is was is that in in attention when you write the tokens KV you write it you write the tokens cavies before you actually you read it. So even if you have stale data it's being overwritten but for mamba as as I said when when you first go through the decode kernels you first read the state and then you compute over it. So what happens was is you just use over you use stale data when you do the when you do a decode and the fix was relatively simple. Well, we just needed to make sure that what we do is that when a request first when the when theuler first classifies a request, it's got to it's got to make sure that that that it sets that that if a that if that if you sees a request that's whose tokens were never been computed.
11:23 we and and they're zero to mark them as to mark them as as prefill as as prefill. So the so when they get to the forward pass, they'll actually just be used for prefill and not decode and not u and not chunked. You can see that it was merged after some time. and that really leads us to and then we thought everything was fixed, right? We thought everything was fixed and there you have it. No more issues. But that but that was almost the case because after a little bit of time it gets us to case number two which surfaced another issue that we've faced in our in our RL and our inference. so we ran RL and and when while we were running our our trainings our post trainings and we looked at our evaluations and all of our benchmarks we saw that we had some log prop spikes between the rollout and the FSTP step. so and that was before any weight app update. So some weights same inputs and the two log props should be identical. Now they weren't. we saw that every 12 step cons constantly there was a log prop spike and that was kind of weird. Now what would you guys do right? What can what what's the what's the first thing to do here? So we wanted to find some lever that changes how things fail and not just how much they fail. We want to see how much we want to tweak some knobs that that don't just tell us, hey, this error this error is very very bad. This error happens this many times or or and so and so on. We wanted to tweak some knobs that kind of tell us that once we tweak that knob, we understand how it's wired to anything in the in in VLM's engine. And so we'll be able to specifically go and and debug that specific part. that's some some some cool meme that you all wanted to put in.
13:19 so what we did was is we decided to to increase the the the amount of rollouts per prompt. since we saw in our default RL engine we have eight rollouts per prompt and we saw that it happened con deterministically every 12 steps. We decided okay let's try to tweak it up a bit and and increase the amount of rollouts per prompt. So we started doubling it from say eight to 16 to 64 32 and 128. And you can see here that it's almost almost there's a pattern here that that the more we increased it the closer it happened because what we wanted to achieve here we wanted to try to reproduce the issue as fast as possible so we'd have a faster debug debug loop feedback loop. So when we when we when we ran it on 128 rollouts per prompt, it happened immediately on step one and we didn't have to wait for step 12 and step 24 and so on. Now you might think, okay, so you guys played with the with the GPU memory utilization before you you tweaked it, you decreased it. It looks like, you know, when you test on pressure, it really surface things up. So So we we thought that as well.
14:27 And when we reduced the GPU memory from zero from 0.9 to 0.2, two, it actually caused the issue to go away. So, we actually pulled the wrong lever here. and the reason is is because we noticed that Mamba kernels used in 32 unsigned in 32 index pattern pointer. So, once the offset went past some you know 4 billion numbers, it wrapped around instead of throwing an error. so when we shrank the GPU memory, VLM allocated a small state buffer and and the cache index never got large to hit that slot. So we were so we were just not reaching far enough for the buffer to trigger an overflow. So again the fix was rather simple. All we needed to do was just change one word, one one data type variable from u in32 to size t which basically means for most modern architectures hardware architectures size t would mean to it would be now changed to unsigned 64 bit and that's a very large number. We didn't we never reached that number and that overflow now never happened.
15:39 So what we can see here is that we had two scenes and one criminal. both kind of you know they had similar symptoms. Both had silent gibberish and and silent log prop spikes which also kind of pro sometimes generated gibberish. They were both around the mamba state cache. they were both surfaced by memory pressure whether it was for worse or for the best and both found via log props forensics. stateful inference inference systems don't fail loudly they lie to you confidently I mean obviously sometimes you get crash you get out of bounds errors you get other you know exceptions and so on but sometimes there are some errors that don't surface up and you don't get a trace log you don't get anything you have to go and dig and understand why things happen so if there some takeaways to take from this presentation is build a log props comparison script if you need to compare your quality you need to compare it to understand whether you modelize the issues or not. log props comparison script with a baseline of some other inference framework that you have or built is always great. reproducing underression constrain memory. crank the scale up, play with other knobs that the inference framework gives you and really try to understand where the issue comes from. look for what moves the failure shape, the timing, the space and the location. And when things don't really have identity thread identity through and what it also I want you to take from this and don't be afraid to even you know for complex systems like VLM or any other complex framework don't be afraid to go dig in the code get your hands dirty sometimes you know model languages LLMs are they might tell you how things work but you know without you seeing it in your own eyes getting your hands dirty you won't get full understanding of what's going on. thank you. You guys can add us on LinkedIn. Scan the QR code to read the actual blog that we've published with this finding. yeah, that's it.
Summary
- The primary challenge discussed is the occurrence of silent bugs that do not crash the system or provide warnings, making them difficult to diagnose.
- The first case, termed "imposter request," involved gibberish outputs that occurred under specific conditions, necessitating a deep dive into the model's architecture and request handling.
- They utilized various debugging techniques, including adjusting GPU memory allocation and comparing outputs with a baseline model from Hugging Face to identify discrepancies.
- The issue was traced back to the order of operations in the model's forward pass, where the decode operation was incorrectly prioritized over prefill, leading to the use of stale data.
- The second case involved log prop spikes during reinforcement learning evaluations, which were linked to an overflow issue due to data type limitations in the model's indexing.
- Key strategies for debugging included building log prop comparison scripts, manipulating memory constraints, and exploring the model's codebase for a better understanding of its operations.
- They emphasized the need for a hands-on approach to debugging complex systems, encouraging engineers to engage directly with the code to uncover hidden issues.
Questions Answered
What types of bugs are difficult to identify in AI models?
The speaker introduces the concept of hard-to-diagnose bugs in AI models, particularly those that do not produce crashes or warnings but still yield poor outputs. They emphasize that these issues are engineering problems rather than quality issues.
How did the team attempt to reproduce the bug in the AI model?
The team struggled to reproduce the bug initially but found success by adjusting GPU memory utilization settings. By reducing memory allocation and running multiple requests simultaneously, they were able to consistently generate gibberish outputs from the model.
What steps did the team take to identify the source of the gibberish output?
The team examined various components of the VLM's engine, including the CUDA prefill kernel and memory sanitation tools. They isolated the decode kernels and found that the issue might be related to how the model processed requests.
What was discovered about the decode kernels during the investigation?
The team found that the decode kernels were using stale data, leading to incorrect outputs. They implemented a fix to ensure that requests were properly classified and processed, which initially seemed to resolve the issue.
What memory management issue did the team uncover, and how was it resolved?
The team discovered that a data type used in the Mamba kernels caused an overflow issue when GPU memory was reduced. By changing the data type from unsigned int to size_t, they prevented the overflow and resolved the problem.