This article is more than 1 year old
Modular finds its Mojo, a Python superset with C-level speed
LLVM champ Chris Lattner is at the helm, so consider us intrigued
Modular, an AI startup with above-average technical cred, has unveiled a programming language called Mojo that aspires to combine the usability of Python with the speed of C.
There are numerous ongoing projects to make Python faster, such as Jax and more recently a Python compiler called Codon. And that's to say nothing about alternative data science-oriented languages like Julia.
Mojo manages to distinguish itself from other Python enhancement efforts through the extremity of its alleged acceleration – 35,000x faster than Python when running numeric algorithms such as Mandelbrot thanks to hardware acceleration – and the pedigree of CEO Chris Lattner.
Mojo combines the parts of Python that researchers love with the systems programming features that require the use of C, C++ and CUDA
Lattner, a veteran of Apple, Google, and Tesla, co-developed the LLVM compiler tool chain, co-founded the MLIR compiler infrastructure, and spearheaded the development of the Swift programming language. And his Modular co-founder, Tim Davis, also brings considerable experience to the table as the former leader of Google ML, where he oversaw the web goliath's machine-learning APIs, compilers, and runtime infrastructure.
The year-old startup this week announced two related projects: Mojo, a programming language built on top of Python that promises the performance of C; and the purportedly portable, performant Modular Inference Engine to run AI models less expensively in production – inference being the usage of a model after it has been trained.
"Mojo combines the parts of Python that researchers love with the systems programming features that require the use of C, C++ and CUDA," the biz explained.
"Mojo is built on top of next-generation compiler technologies that unlock significant performance gains when you add types to your programs, enables you to define zero-cost abstractions, benefit from Rust-like memory safety, and that powers unique autotuning and compile-time metaprogramming capabilities."
By taking advantage of MLIR, Mojo code can access a variety of AI-tuned hardware features, such as TensorCores and AMX extensions. As a result, for certain kinds of algorithms, it's far faster than vanilla Python – 0.03 seconds running the Mandelbrot algorithm on an AWS r7iz.metal-16xl, compared to 1,027 seconds (about 17 minutes) for Python 3.10.9.
WIP
Mojo is still in development, though there's a Jupyter notebook for trying it out. When it's complete, it's expected to be a superset of Python – the Python ecosystem with a systems programming toolkit. In that form, it should run any Python program. But at the moment, while Mojo supports Python core features including async/await, error handling, and variadics, a lot of work still needs to be done to achieve full compatibility.
In an announcement on Thursday, data scientist Jeremy Howard, co-founder of Fast.ai, said, "Mojo may be the biggest programming language advance in decades."
Mojo, Howard explains, attempts to address the bifurcated reality of AI: while AI models are developed in Python due to the richness of the ecosystem, Python programmers usually end connecting their code to modules in more performant languages, such as C/C++ and Rust. And this "two-language" approach makes it more difficult to profile, debug, learn, and deploy machine learning applications.
"A key trick in Mojo is that you can opt in at any time to a faster 'mode' as a developer, by using 'fn' instead of 'def' to create your function," explains Howard. "In this mode, you have to declare exactly what the type of every variable is, and as a result Mojo can create optimized machine code to implement your function.
"Furthermore, if you use 'struct' instead of 'class', your attributes will be tightly packed into memory, such that they can even be used in data structures without chasing pointers around. These are the kinds of features that allow languages like C to be so fast, and now they’re accessible to Python programmers too – just by learning a tiny bit of new syntax."
- Fed up with Python setup and packaging? Try a shot of Rye
- Python still has the strongest grip on developers
- Python head hisses at looming Euro cybersecurity rules
- Microsoft is busy rewriting core Windows code in memory-safe Rust
Another benefit of Mojo is that code can be compiled into a stand-alone, fast-launching binary, making it easy to deploy while taking advantage of available cores and acceleration.
There are still some missing pieces, like a package management and build system – something the Python community continues to struggle with. And the language is not yet under an open source license though it's expected to be, eventually.
"Mojo isn't finished – but what's there is already mind-blowing, and it has been created by a very small team in a very short time," said Howard via Twitter. "This shows the benefits of using carefully architected foundations, based on [Lattner's] years of experience with Clang, LLVM, and Swift." ®