What language is 35000 times faster than Python?
7 min readWhat language is 35000 times faster than Python?
- Huawei Mate 60 Pro Makes Satellite Calls: Only US$0.18/minute
- Huawei Mate60 Pro: First Smart Phone Supports Satellite Calls
- 14000 cores + 450W: RTX 4080 graphics card perfectly replaces the RTX 3080
- Big upgrade: The difference between Bluetooth 5.0 and 5.2
- Geeks Disappointed that RTX 4080/4090 doesn’t come with PCIe 5.0
- What are advantages and disadvantages of different load balancing?
What language is 35000 times faster than Python?
35000 times faster than Python! The father of LLVM&Swift announced the new programming language Mojo: programming is subverted
“Mojo is probably the greatest programming language advancement in decades.”
Recently, Modular AI, a new company founded by Chris Lattner, the co-founder of LLVM and the Swift programming language, released a new programming language called Mojo.
Mojo combines everyone’s favorite Python features with the systems programming capabilities of C, C++, and CUDA, and differentiates itself from other Python speed enhancements by what it calls “extreme acceleration.” Thanks to hardware acceleration, it runs numerical algorithms like Mandelbrot up to 35,000 times faster than raw Python!
More importantly, as the creator of LLVM, Chris Lattner’s good background laid the foundation for Mojo’s success. Jeremy Howard, data scientist and founding researcher of fast.ai, commented on Mojo as “Mojo may be the greatest programming language advancement in recent decades.”
Why Mojo?
For developers around the world, we should all be familiar with the name Chris Lattner.
Chris Lattner has worked at companies like Apple, Google, and Tesla, helping to create many of the projects we rely on today: developing the LLVM compiler toolchain, co-creating the MLIR compiler, and spearheading the development of the Swift programming language.
Initially, he started the development of LLVM as part of his PhD thesis. LLVM ended up fundamentally changing the way compilers were created, forming the basis of many of the most widely used language ecosystems in the world today. He then went on to launch Clang, a C and C++ compiler that sits on top of LLVM.
Chris found that C and C++ didn’t really take full advantage of the power of LLVM, so while working at Apple, he designed a new language called “Swift”, which he described as “LLVM’s syntactic sugar”. Swift has become one of the most widely used programming languages in the world, especially as the primary way to create iOS applications for iPhone, iPad, MacOS, and Apple TV today.
Unfortunately, Apple’s grip on Swift means it hasn’t really caught on outside of Apple. Chris worked at Google for a while trying to bring Swift out of Apple’s comfort zone, hoping it would become a replacement for Python in AI model development, but unfortunately he didn’t get the support he needed from Apple or Google, and ultimately didn’t succeed .
Having said that, Chris also developed another hugely successful project during his time at Google: MLIR. MLIR is a replacement for LLVM IR for modern multicore computing and AI workloads. This is essential to take full advantage of the power of hardware such as GPUs, TPUs, and vector units that are increasingly being added to server-class CPUs.
In January 2022, Chris Lattner officially announced his venture, and co-founded “Modular AI” with Tim Davis, hoping to rebuild the global ML infrastructure from the bottom up. Tim Davis was in charge of Google’s machine learning project, responsible for managing Google’s machine learning API, compiler and runtime infrastructure.
As they built their platform to unify the world’s ML/AI infrastructure, they realized that programming across the entire stack was too complex. “These systems are heavily fragmented, with a wide variety of hardware, each with custom tools.”
“What we want is an innovative, scalable programming model that can target accelerators and other heterogeneous systems that are prevalent in machine learning. This means a programming language with powerful compile-time metaprogramming, incorporating adaptive Compilation techniques, caching throughout the compilation pipeline, and other things that existing languages don’t support.”
So in this case, the startup announced two related projects in one go: Mojo, a programming language based on Python that claims to have a speed advantage comparable to C; and the portable, high-performance Modular A recommendation engine that can run AI models in production at a lower cost (the so-called reasoning is the process of using the trained model in actual scenarios).
“Mojo combines the features of Python that researchers love with the systems programming capabilities of C, C++, and CUDA,” the company said.
“Mojo is built on next-generation compiler technology that dramatically improves performance as you add types to your program, helps you define zero-cost abstractions, benefits from Rust-level memory safety, and supports unique auto-tuning optimization and compile-time metaprogramming capabilities.”
“Mojo has learned a lot from Rust and Swift and made it a step further.”
Mojo: A programming language 35,000 times faster than Python
Mojo is a member of the Python family, but has lofty goals – to be fully compatible with the Python ecosystem, so developers can continue to use the tools they are familiar with. Mojo aims to gradually become a superset of Python by preserving Python’s dynamic nature, while adding new primitives for systems programming.
These new systems programming primitives will allow Mojo developers to build high-performance libraries that currently require C, C++, Rust, CUDA, and other accelerator systems.
On MLIR, Mojo code can access various AI-tuned hardware capabilities, such as TensorCores and AMX extensions. As a result, it is significantly faster than raw Python for certain algorithm types – it runs Mandelbrot’s algorithm in just 0.03 seconds on AWS r7iz.metal-16xl, compared to 1027 seconds (about 17 minutes) on Python 3.10.9 ).
Chris Lattner on Hacker News: “Our goal is not to make dynamic Python magically fast.
While we are much faster at dynamic code (since we have compilers rather than interpreters), it’s not about being ‘smart enough’.” ‘ compiler to remove dynamism”.
The reason Mojo is so much faster than Python, he says, is that it gives programmers control over static behavior and can be phased in where it makes sense.
The key payoff of this is that the compilation process is very simple, doesn’t require a JIT, and you get predictable and controllable performance.
Mojo is still under development, but a Jupyter notebook is currently available for trial.
When fully completed, it promises to be a superset of Python — a Python ecosystem with a systems programming toolkit. At that point, it should be able to run any Python program.
But at present, Mojo only supports the core functions of Python, including async/await, error handling and variable parameters, and there is still a long way to go before full compatibility.
“It feels like programming has been subverted”
In an announcement Thursday, Fast.ai co-founder and data scientist Jeremy Howard said, “Mojo may be the biggest programming language advancement in decades.”
“There’s a new programming language in ‘town’: Mojo! I’m really excited about it. It’s like Python, but without any of Python’s problems. You can write code as fast as C and deploy small standalone application.”
“It feels like programming has been subverted.” In Jeremy Howard’s memory, the last time he felt this way was the first time he got started with Visual Basic v1.0.
Jeremy Howard is a heavy user of Python, Python can and does do everything, but it has a downside: performance, which is thousands of times slower than languages like C++. Developing in Python requires avoiding performance-critical parts in Python and adopting Python wrappers to cover C, FORTRAN, Rust, etc. code.
Therefore, with the richness of the ecosystem, Python does have an advantage in the field of AI model development, but because of limited performance, Python programmers often end up pointing their code to other languages that run faster (such as C/C++ and Rust) module. This “bilingual” reality makes analyzing, debugging, learning, and deploying machine learning applications increasingly difficult. Howard explained that Mojo is trying to address this fragmented reality within AI.
“One of the great things about Mojo is that developers can always choose a faster ‘mode’ to create their own functions using ‘fn’ instead of ‘def’. In this mode, developers must declare the type of each variable exactly, This allows Mojo to create optimized machine code to implement the desired function.”
“Furthermore, if you use ‘struct’ instead of ‘class’, the attributes are packed tightly into memory and can even be used directly within the data structure without having to hunt around for pointers. These features give it a level comparable to that of the C language. It also allows Python programmers to master this performance treasure after learning a little new syntax.”
Another benefit of Mojo is the ability to compile code into self-contained and fast-starting binaries, making it easy to deploy by taking advantage of available cores and accelerated hardware.
As a compiled language, Mojo’s deployment process is basically the same as C. For example, a sample program that includes a version of matmul written from scratch is around 100k.
“This completely subverts the traditional rules of the game.”
Of course, the current Mojo still has some missing things, such as package management and build system-this is also a need that the Python community has been working hard to solve for a long time. In addition, the Mojo language has not yet specified an open source license, but I believe it is only a matter of time.
Howard concluded in a tweet, “Mojo isn’t finished yet – but it’s exciting to see what it’s been built in such a short amount of time by a very small team.” , LLVM, and Swift development experience gave us another well-built language cornerstone.”
Reference link:
https://www.modular.com/blog/the-future-of-ai-depends-on-modularity
https://news.ycombinator.com/item?id=35811380
https://docs.modular.com/mojo/programming-manual.html#argument-passing-control-and-memory-ownership
https://www.theregister.com/2023/05/05/modular_struts_its_mojo_a/
What language is 35000 times faster than Python?
- DIY a PBX (Phone System) on Raspberry Pi
- How to host multiple websites on Raspberry Pi 3/4?
- A Free Intercom/Paging system with Raspberry pi and old Android phones
- DIY project: How to use Raspberry Pi to build DNS server?
- Raspberry Pi project : How to use Raspberry Pi to build git server?