What is Nano-vLLM?
Deepseek is so popular that even when one of their employees releases a hobby project, it becomes an instant hit. One of their employee released this Nano VLM which is a lightweight VLM implementation which performs even better than actual VLM.
This is Fad Miza and I welcome you to the channel. In this video, I'm going to show you how to get this thing installed and we will test it out with one of the model. Now, if you don't know what VLM is, VLLM is also pronounced by some people as VO. It is an open-source library designed for fast and memory efficient serving of LLMs. I already have covered this VLM a lot on the channel. So if you just go to my channel search with VLLM you will find heaps of videos around it as I have used it in most of my model installation videos.
VLM not only allows you to have optimized inference but also it offers you techniques like paged attention which manages memory more efficiently by storing attention key value tensors in non-contiguous memory blocks. Just similar to how operating systems manage a virtual memory and that is where I want to check out if Nano VLM also does the same.
The primary promise of this new project is that it offers you comparable or even better infant speed than VLLM. Also, it has a very very clean implementation. Just 1,200 lines of Python code, which is quite interesting. And as I said earlier, I want to see if it offers those memory optimization techniques or not. As you can see in its optimization suite. So, let's get started and we will get it installed.
Installation on Ubuntu with GPU
Now I'm using this Ubuntu system and I have one GPU card Nvidia RTX A6000 with 48 GB of VRAM. I'm going to create a virtual environment with KOD. And if you're also looking to rent a GPU or VM on very affordable prices, you can find the link to their website in video's description with a discount coupon code of 50% for range of GPU. So please do check them out.
And that is done. Next up, let's install this NanovLLM from its GitHub repo and I will drop the link to it in video's description. Okay, so it is also asking me to install the torch. I thought it will be part of it. So, let me actually install it from the source. So, in this case, I'm just going to install all the torch and transformer stuff by myself and then we will install it again from the pip. And while it gets installed, let me also introduce you to the sponsors of the video who are Camel AI.
Kamel is an open-source community focused on building multi-agent infrastructures for finding the scaling laws with applications in data generation, task automation, and world simulation. And you will find the link to their website in video's description.
Okay, so all the prerequisites are done. Now let's install it again. This should be fine now. And it is installed now and it was fairly quick.
Downloading a Test Model
Now let's download the model and which we are going to use with this NanovLLM. For that let's log into the hugging face and you would need your free read token and you can grab this read token from huggingface.co from your profile.
Okay. So my login is now successful. Let's download the model and I'm just going to use hugging face CLI to download this model and as I said earlier you can use any model which is compatible with VLLM which means most of the models are. So I'm just going to go with this 3.6 billion model which is one of the best small model at the moment I would say. So but you can of course select any model of your choice. So let me download it to the local checkpoints directory.
And the model is downloaded. It's a very small model as you can see here. Okay. So the model is downloaded. Our NanovLLM is installed. Let's see how exactly this works.
Running the First Test & Code Explained
Now in order to use it, all you need to do is to use a code which is something like this where you would need to first import this nanovll and then some of its function. You just need to initialize and instantiate that model which we have just downloaded. All I am doing I'm providing the path to where I have downloaded the model and then I am setting some of the hyperparameters. I'm giving it a prompt. Model is generating the output and then we are printing it out. That is all there is to it.
Now one important thing which you need to see here is that I'm using tensor parallel size is equal to one. This is primarily specifying that the model should run on a single GPU without any tensor parallelism. So if you have multiple GPUs like 2, four or eight, you can then specify that number here and then it is going to split the models tensors across multiple GPUs to handle larger models or even increase throughput and that obviously improves the speed depending upon what sort of interconnect you are using. So if you are using by the way VLM for your huge production environment that is where this is mostly used.
One thing I'm very curious to see is that they have turned this enforce eager to true. Now I'll be very honest. I'm still not sure why exactly they have provided this because what enforce eager does it disables CUDA graph optimization and then sorry model uses eager execution mode. Now normally this can be useful for debugging or when CUDA graphs cause issues but it does reduce performance in my real world experience. So I don't normally set it with VLM like true. So I'm very curious to see why exactly they have done it. But anyway I'm just going to run the example same as from here from my terminal. So let's go back and run this Python app.py. It is going to load and run this. So it is generating the output and then it has recorded the tokens and there are 38 tokens per second which is not really bad I would say.
Explaining Prefill and Decode Speed
So speed definitely looks good. And now let's try out another prompt and I will actually also explain what exactly is that prompt doing. So let me put the prompt here. So all I am asking it to write me a short essay around 300 words on the impact of climate change on global food system. So this is just a sample prompt to generate some longer text.
Let me clear the screen and then let me run this in front of you. Let's wait for it to start generating and then I'm also going to tell you what these hyperparameters mean. Keep an eye on it. So if you see here, prefill measures how fast the model processes the input prompt token to build the initial context. This is typically slower since all input tokens must be processed simultaneously to generate the key value cache and decode measure the speed of generating new output tokens one by one after the initial context is established. This is usually faster since it generates tokens sequentially and can reuse the cache attention states from previous tokens.
And you can see that we have prefill phase. This happens once at the beginning while decode happens for each new token generated. So decode speed is more important for overall generation throughput. And here you can see that decode speed is around 37 token per second which is quite decent given the specs of this system.
Final Test and Conclusion
And now finally I'm just trying it out with a longer reasoning prompt just to see how exactly it works with that. Let me run this. And if you're wondering what should be a decent or really hi-fi decode speed. So for production grid applications, it should be higher than 100 or you know I have seen going it get up to 300 to 500 tokens per second and in some setup thousands per second but here you can see that it is quite reasonable and decent for even this simple local setup.
So that's it. I hope that you enjoyed it. It is really really performant. No doubt about that. And it is really comparable to the VLM. I have seen the same or similar performance from the actual VLM project which is quite mature and established. That's it. Let me know what do you think. If you enjoyed the content, please like the video and share it. If you haven't already subscribed, please do so as it helps a lot. Thank you for watching.