Mojo 🔥— NEW Language for AI (FIRST Look)

Chris Lattner, creator of Swift, just announced Mojo, a new programming language built on Python that's designed for AI. It claims 35,000× speedups over Python, with one example running a fractal in 0.03 seconds instead of 17 minutes. You can try it now in a Jupyter-like playground.
Chapters
Over the last few months we have seen tremendous advancements in large language models as well as AI generated images and videos. But this could be one of the biggest advancements in AI and machine learning. Yesterday, Chris Letner, the inventor of Swift programming language, announced the creation of a new programming language called Mojo, which is built on top of Python. And if you know Python is the basis of all machine learning applications right now. However, one of the biggest problem with Python is it's considered to be pretty slow compared to other languages such as C or C. But according to Chris, this new language mojo is about 35,000 times faster than Python. Now if this can hold true, this literally changes everything. But wait, this is not it. There's one more feature which all the developers would love. So according to Chris, Mojo combines the usability of Python with the performance of C, unlocking unparalleled programmability of AI hardware and extensibility of AI models. If you have worked with Python, you are probably familiar it is very slow. Now if you have ever worked on any AI application in Python, you probably know that Python is extremely slow and it has very poor speed. But that is one of the reasons that a lot of time Python is simply using a wrapper around C application. So for example, if you have worked with NumPy, TensorFlow or PyTorch, they are basically written in C, but they provide a wrapper that you can use in Python. Now, specifically for AI applications, you actually need to go one step deeper and you really need to work with on the hardware level. So for example, a lot of time you will see the dependencies in cuda, right? That is essentially the lowest level programming that you need. And if you have ever tried to set up CUDA on Windows or Linux machine, it can be a nightmare. That is yet another motivation for Mojo, because you can write everything in one language now. So in this case the programs with multitude of low level AI hardware, so you don't really need any C or cuda. This alone is literally a game changer for developers. Now great thing about Mojo is that it is a superset of Python, which means that Python code will work in Mojo. That is great news for developers because you don't really need to learn a completely new language, but you can rather use your Python knowledge and implement things in Mojo. Now let's look at some of the features before we look at more of the syntax and how you can use it. So it lets you utilize the power of hardware, including multiple cores, vector units and exotic accelerator units. With the world's most Advanced compilers and heterogeneous runtime. Basically you will be able to utilize the full potential of your hardware. So for example, Python is a single thread execution, so it's a simple sequential execution. But Mojo will enable parallel processing across multiple cores. That in itself will give you a huge performance boost. Now here is a simple comparison of how much speed improvement you can expect. For example, to run a fractal algorithm, Python can take up to 17 minutes, but the module will take only 0.03 seconds to run the same algorithm. This is going to be insane and it will give you a huge performance boost. Now they claim to have full compatibility with Python ecosystem. That means that when it's completely ready, you will be able to use Python code inside Mojo. So for example, here they have provided an example of how you can create a plot using matplot matplotlib package from Python in Mojo. So you will simply import it like Python import module and then you simply import the matplotlib package and the rest is very similar to what you would see in normal Python. So as I said before, Mojo is designed to become a superset of Python over time. So that means that it will have all the features of Python. But right now it seems like some of the Python features are actually missing over time. They will include all the Python features, so we'll see how that goes. Now, there are definitely some intentional differences from Python. We will talk about this in a minute. Now let's look at a few more programming features of Mojo before talking about how can you access it. So for example, here's an implementation of a softmax function in Python. Now the Mojo implementation is very similar. This struct seems to be something close to a class in Python. So here are some more features. For example, it has progressive types, so leverage types for better performance and error tracking. It seems to be similar to type hinting in Python. Next they talk about zero cost abstraction. So take control of storage by inline allocating values into structures. So I think that you can define the data types in line. For example, if you see here you have a variable first and second and the corresponding data types of integer and float32. The next feature is ownership plus borrow checkers to take advantage of memory safety without rough edges. I think I heard somebody saying that it's as safe as rust, but we'll have to wait and see. Now there's another one. Portable parametric algorithms leverage compile time metaprogramming to write hardware agnostic algorithms and reduce boilerplate. This is going to be significant, but I am more interested in the last one language, integrated auto tuning. So automatically find the best values for your parameters to take advantage of your target hardware. This is going to be significant because right now spend a lot of time on compiling your packages for different hardware. If this holds true, it will save a lot of time. So why Python? Why they have modeled Mojo on top of Python? Well, the answer is very simple. Python is the language of AI and machine learning. Right now all of the most famous machine learning packages are actually implemented in Python or they have a wrapper for C or C implementation and that makes it a very great candidate to design a language around it. Now if you are a programmer, I would really encourage you to actually go and start looking at the documentation because this could potentially be the next big thing in AI and machine learning. I personally have started looking at some of the documentation and there are some very interesting things. For example, you have this Mojo programming manual. So overall it seems to be very similar to Python. And then there are some other differences. For example this basic system programming extensions. So now they have this let and war declaration that you can use with your variables. Now the last part that I want to talk about is how you can actually try this. So unfortunately this is not yet openly available to everybody. You actually need to go and sign up to get an early access to the Moto playground. From what I understand it takes a couple of days to get the access. I have already applied for early access, so hopefully we'll be getting that soon. Now from their description, this looks to be very similar to jupyterprinter notebook and you can play around with even the extension actually of the file is IPython Notebooks. So it will be a very familiar interface. As I said in the stand, if they can actually deliver on their promises, this is going to be a significant step and it's actually great to get started early because this will give you an extra advantage in the cutting edge field of machine learning and artificial intelligence. So this was a quick update on this amazing new programming language. I am excited about it and we'll be learning more about it. If you like the video, please share and subscribe to the channel. There are any questions, don't forget to leave a comment. Thanks for watching, See you in the next one.










