New Language for AI Development: Mojo builds on Python with the Power of C

A new programming language for ML is emerging: Mojo is a Python superset with additional functions. Chris Lattner, the creator of Swift and LLVM, is behind it.

In Pocket speichern vorlesen Druckansicht 6 Kommentare lesen
Monorail,Motion,Blur,In,Dubai,,Uae.,Dubai,Metro,,Abstract.,Fpv

(Bild: Grisha Bruev/Shutterstock.com)

Lesezeit: 8 Min.
Von
  • Silke Hahn
Inhaltsverzeichnis

(Diesen Artikel gibt es auch auf Deutsch.)

A new programming language for machine learning, said to be a Python++? Mojo is intended to combine Python's usability with C's performance. According to the development team's announcement, it aims to enable "unprecedented programmability" in AI hardware and the extension of AI models.

In addition, the project is announcing what it says is the fastest unified inference engine for machine learning under the Modular AI umbrella brand. It is said to defragment and simplify AI deployment and be able to run both PyTorch and TensorFlow workloads. Both cloud and on-premises environments are possible, and numerous frameworks and servers are supported, it said.

The Modular Inference Engine is designed to consolidate the AI toolchain and simplify AI deployment.

(Bild: Modular AI)

No stranger is building the ladder to the moon: Chris Lattner, who created the Swift language at Apple starting in 2010 (at the time with the goal of "fully exploiting the power of LLVM"), is the man in charge behind Project Mojo. Lattner later moved to Google, where he tried to get Swift "out of its Apple comfort zone" to replace Python for AI model development. That's according to a blog post by Australian AI professor Jeremy Howard, founder of fast.ai.

Lattner had severed his last ties with the Swift project in early 2022, and had already left the Core team in the summer of 2021 due to internal differences. In 2017, he had turned his back on Apple and worked for a short time at Tesla. Lattner had not only invented Swift, but had also been instrumental in advancing the compiler infrastructure LLVM and headed the development tools department at Apple. With Swift, he had strived for an alternative to Objective-C in 2010. Apple initially kept the project inside the corporate fence until it entered the open as an open-source project (and for Linux) under the Apache 2.0 license in 2015. Development since then has been more community-driven. There is no consensus about the future of the language, and it has not yet been able to really establish itself.

Mojo: Performance compared to regular Python and other languages when running the Mandelbrot algorithm on an AWS system (r7iz.metal-16xl) – Mojo is said to be "35,000 times faster".

(Bild: Modular AI)

In 2022, Lattner co-founded the developer platform Modular AI with Tim Davis. With Mojo, the two are revisiting some of Swift's original concerns with a new approach. According to another expert, the Australian founder of fast.ai Jeremy Howard, Swift basically failed because support from Apple, and later Google, was too hesitant. Howard's blogpost highlights another project Lattner developed during his time at Google: MLIR, a replacement for Intermediate Representation (IR) in the LLVM compiler collection (MLIR stands for Multi-level IR).

This technique can be used to tap into hardware in multicore computing and AI workloads and to exploit the power of GPUs, TPUs and the vector units added to CPUs. The new Mojo programming language, he said, is to MLIR what Swift was (or could have been) to LLVM. Mojo is not quite ready yet, and is intended to be a "strict superset" of the Python language in the future. Beyond Python, Mojo can write high-performance code that makes use of newer modem accelerators, he said.

Howard's comparison to Swift goes further. For example, he says, Swift was a new, stand-alone language that incorporated features of the research being done at the time to conceptualize programming languages. Mojo, on the other hand, was simply Python, he said. Swift critics believe this is a wiser approach, since Python is already well established and millions of developers have mastered the language. Moreover, Python's capabilities and limitations are well known, they say. There is therefore less speculation involved here than there was back then with Swift, and Python also has a comprehensive ecosystem.

Those working with Mojo can optionally select a faster developer mode when creating functions by using fn instead of def, according to the blog entry. In this mode, developers must specify the exact type of each variable. Mojo can then create optimized machine code to implement the function. Instead of class, struct can be used to write the attributes into memory. That way, they can be used in data structures "without chasing pointers," according to Howard.

Empfohlener redaktioneller Inhalt

Mit Ihrer Zustimmmung wird hier ein externes YouTube-Video (Google Ireland Limited) geladen.

Ich bin damit einverstanden, dass mir externe Inhalte angezeigt werden. Damit können personenbezogene Daten an Drittplattformen (Google Ireland Limited) übermittelt werden. Mehr dazu in unserer Datenschutzerklärung.

The features he describes are known from C and make this programming language particularly fast. Through Mojo, they are now also accessible to Python programmers, through the addition of a manageable amount of new syntax.

Mojo is not yet released regularly. There is an online playground with a waiting list to try it out. Building the syntax of a new programming language is buggy, complicated, and often controversial – Project Mojo elegantly sidesteps some of the known shoals by relying on the existing, particularly widely used Python language and "outsourcing" the syntax problem that way. As a compiled language, Mojo's deployment is comparable to C, according to an entry in the developer forum at Slashdot.org: The program can be downloaded directly, is relatively small with a 100 kilobyte binary file, and can be made to run quickly.

With the Python superset, fast, small and easily implementable applications can be written that use all available cores and accelerators. Mojo's potential therefore goes beyond that of a pure language for AI and ML models, according to initial assessments, although the project's main target audience is, in its own words, "all AI developers." The language's developers advertise that Mojo can be used to write "everything in one language" - from scalable Python code to hardware programming, without the need for C++ or CUDA.

Mojo lets you scale Python down to the hardware level - the code example is about SIMD instructions.

(Bild: Modular AI)

A first overview also about the programming language can be found in the blog entry about the release of the Modular Inference Engine. If you are curious, you can read about the language in the documentation on the Mojo project page and sign up for the waiting list. Particularly informative to get started is the interactive Jupyter notebook collection on Mojo, in which the team introduces the language, its design and syntax. The notebooks are executable and provide an introduction to such things as creating extensions, compile-time parameterization and meta-programming, and advanced features. There is also a Mojo library and a roadmap for planned further development. The team around Chris Lattner and Tim Davis dedicated a product keynote to the launch (YouTube video).

Further technical information can be found in the documentation on the Modular Inference Engine, which goes into detail on the programming interfaces to Python and C. According to the entry in the navigation, an interface to C++ is apparently already being planned. The documentation does not start from scratch: Prior knowledge of Python is assumed, as well as familiarity with general programming basics.

Like the programming language, the Inference Engine is initially only available to a limited number of Early Access partners, for whom there is also a waiting list (when registering, you can select which area you are interested in: Inference Engine, Mojo, Hardware Integration or the Modular Platform). If you want to keep up with the development of Mojo, you can check out the roadmap to see what is planned for the language in the near future.

(sih)