惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

量子位
S
Secure Thoughts
S
Schneier on Security
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Cyberwarzone
Cyberwarzone
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
P
Privacy International News Feed
L
Lohrmann on Cybersecurity
Schneier on Security
Schneier on Security
PCI Perspectives
PCI Perspectives
Google DeepMind News
Google DeepMind News
C
Cybersecurity and Infrastructure Security Agency CISA
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Latest news
Latest news
H
Hacker News: Front Page
月光博客
月光博客
Forbes - Security
Forbes - Security
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
S
Security @ Cisco Blogs
WordPress大学
WordPress大学
Recent Commits to openclaw:main
Recent Commits to openclaw:main
aimingoo的专栏
aimingoo的专栏
宝玉的分享
宝玉的分享
D
Docker
U
Unit 42
Recorded Future
Recorded Future
Spread Privacy
Spread Privacy
Microsoft Security Blog
Microsoft Security Blog
Recent Announcements
Recent Announcements
云风的 BLOG
云风的 BLOG
Application and Cybersecurity Blog
Application and Cybersecurity Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
H
Heimdal Security Blog
Microsoft Azure Blog
Microsoft Azure Blog
V
Vulnerabilities – Threatpost
Vercel News
Vercel News
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
爱范儿
爱范儿
博客园 - 聂微东
Hugging Face - Blog
Hugging Face - Blog
L
LangChain Blog
G
GRAHAM CLULEY
Apple Machine Learning Research
Apple Machine Learning Research
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Blog — PlanetScale
Blog — PlanetScale
博客园 - 三生石上(FineUI控件)
罗磊的独立博客
Help Net Security
Help Net Security
Google Online Security Blog
Google Online Security Blog
S
SegmentFault 最新的问题

Modular Blog

Qualcomm to Acquire Modular Modular 26.4: SOTA MoE Serving, Model Bringup via Agent Skills, Mojo 1.0 Beta 2 and More ModCon 2026: Modular’s Developer Conference Day Zero: MiniMax M3 Open Weights on Modular Cloud Modverse #55: Mojo 1.0 Beta, Community Mojo Libraries, and Real-Time Patient Conversations Powered by MAX What about OpenCL and CUDA C++ alternatives? (Democratizing AI Compute, Part 5) Why LLM Inference Needs a New Kind of Router - Part 3 Three trends from MLSys 2026 Why LLM Inference Needs a New Kind of Router - Part 2 How I built a pure Mojo app (and 10 libraries) with AI agents Hippocratic AI partners with Modular to power flexible, high-quality inference for real-time patient conversations Translating to Mojo via AI Agents Inkwell: Why Your Inference Platform Matters As Much As Your Model Why LLM Inference Needs a New Kind of Router - Part 1 Modular 26.3: Mojo 1.0 Beta, MAX Video Gen, and more Modverse #54: AMD AI DevDay, New Modular Offices, and a Community That Keeps Shipping How Frontier Coding Agents Built a Video Diffusion Pipeline on MAX TileTensor Part 1 - Safer, More Efficient GPU Kernels Modular Opens Edinburgh & San Francisco Offices Structured Mojo Kernels Part 4 - Portability and the Road Ahead Day Zero Launch: Fastest Performance for Gemma 4 on NVIDIA and AMD Modverse #54: From GTC to Edinburgh, a Community Building Momentum Software Pipelining for GPU Kernels: Part 1 - The Pipeline Problem Structured Mojo Kernels Part 3 - Composition in Practice Modular 26.2: State-of-the-Art Image Generation and Upgraded AI Coding with Mojo Modular at NVIDIA GTC 2026: MAX on Blackwell, Mojo Kernel Porting, and DeepSeek V3 on B200 Structured Mojo Kernels Part 2 - The Three Pillars Modverse #53: Community Builds, Research Milestones, and a Growing Ecosystem Structured Mojo Kernels Part 1 - Peak Performance, Half the Code The Claude C Compiler: What It Reveals About the Future of Software BentoML Joins Modular The Five Eras of KVCache Modular 26.1: A Big Step Towards More Programmable and Portable AI Infrastructure How to Beat Unsloth's CUDA Kernel Using Mojo—With Zero GPU Experience 🔥 Modular 2025 Year in Review The path to Mojo 1.0 Modverse #52: Advancing AI Together — Community Projects & Platform Milestones Modular 25.7: Faster Inference, Safer GPU Programming, and a More Unified Developer Experience "TTS 1 Max" (powered by Modular Platform) Ranked #1 Speech Model on Artificial Analysis PyTorch and LLVM in 2025 — Keeping up With AI Innovation Achieving State-of-the-Art Performance on AMD MI355 — in Just 14 Days Modular Raises $250M to scale AI's Unified Compute Layer Modular 25.6: Unifying the latest GPUs from NVIDIA, AMD, and Apple Matrix Multiplication on Blackwell: Part 4 - Breaking SOTA Modverse #51: Modular x Inworld x Oracle, Modular Meetup Recap and Community Projects Matrix Multiplication on Blackwell: Part 3 - The Optimizations Behind 85% of SOTA Performance Matrix Multiplication on Blackwell: Part 2 - Using Hardware Features to Optimize Matmul Matrix Multiplication on Blackwell: Part 1 - Introduction Modverse #50: Modular Platform 25.5, Community Meetups, and Mojo's Debut in the Stack Overflow Developer Survey Modular Platform 25.5: Introducing Large Scale Batch Inference SF Compute and Modular Partner to Revolutionize AI Inference Economics AI Agents for AWS Marketplace Modverse #49: Modular Platform 25.4, Modular 🤝 AMD, and Modular Hack Weekend Inside Modular Hack Weekend: Top Projects and Community Highlights How is Modular Democratizing AI Compute? (Democratizing AI Compute, Part 11) Modular 25.4: One Container, AMD and NVIDIA GPUs, No Lock-In Introducing Mammoth: Enterprise-Scale GenAI Deployments Made Simple Modular + AMD: Unleashing AI performance on AMD GPUs Modverse #48: Modular Platform 25.3, MAX AI Kernels, and the Modular GPU Kernel Hackathon Exploring Metaprogramming in Mojo Modular GPU Kernel Hackathon Highlights: Innovation, Community, & Mojo🔥 Modular’s bet to break out of the Matrix (Democratizing AI Compute, Part 10) Modular Platform 25.3: 450K+ Lines of Open Source Code and pip Packaging A New, Simpler License for MAX and Mojo Why do HW companies struggle to build AI software? (Democratizing AI Compute, Part 9) Modverse #47: MAX 25.2 and an evening of GPU programming at Modular HQ What about the MLIR compiler infrastructure? (Democratizing AI Compute, Part 8) What about Triton and Python eDSLs? (Democratizing AI Compute, Part 7) MAX 25.2: Unleash the power of your H200's–without CUDA! What about TVM, XLA, and AI compilers? (Democratizing AI Compute, Part 6) Modverse #46: MAX 25.1, MAX Builds, and Democratizing AI Compute CUDA is the incumbent, but is it any good? (Democratizing AI Compute, Part 4) MAX 25.1 - Introducing MAX Builds How did CUDA succeed? (Democratizing AI Compute, Part 3) Paged Attention & Prefix Caching Now Available in MAX Serve What exactly is “CUDA”? (Democratizing AI Compute, Part 2) Modular DeepSeek's Impact on AI (Democratizing AI Compute, Part 1) Modular Hands-on with Mojo 24.6 Evaluating Llama Guard with MAX 24.6 and Hugging Face Modular Introducing MAX 24.6: A GPU Native Generative AI Platform MAX GPU: State of the Art Throughput on a New GenAI platform Understanding SIMD: Infinite Complexity of Trivial Problems Community Spotlight: Writing Mojo with Cursor Hands-on with Mojo 24.5 MAX 24.5 - With SOTA CPU Performance for Llama 3.1 Announcing stack-pr: an open source tool for managing stacked PRs on GitHub Debugging in Mojo🔥 Write hardware-agnostic custom ops for PyTorch | Modular Take control of your AI Develop locally, deploy globally A brief guide to the Mojo n-body example What's new in MAX 24.4? MAX on macOS, fast local Llama3, native quantization and GGUF support MAX 24.4 - Introducing quantization APIs and MAX on macOS Deep dive into ownership in Mojo What ownership is really about: a mental model approach Fast⚡k-means clustering in Mojo🔥: a guide to porting Python to Mojo🔥 for accelerated k-means clustering
What’s new in Mojo 24.4? Improved collections, new traits, os module features and core language enhancements
No items found. · 2024-06-17 · via Modular Blog

June 17, 2024

Shashank Prasanna

Mojo 24.4 is now available for download, and this release includes several core language and standard library enhancements. In this blog post, we’ll dive deep into many of these features using code examples. One of the biggest highlights of this release is that we received 214 pull requests from 18 community contributors for new product features, bug fixes, documentation enhancements, and code refactoring. These contributions resulted in 30 net new features in the standard library, accounting for 11% of all improvements in this release. We’re incredibly proud of the momentum we’re seeing with community contributions, and it goes without saying – you are the real star of this release. On behalf of the entire Mojo team, we’d like to thank you for all your contributions to making Mojo awesome!

__wf_reserved_inherit

Throughout the rest of the blog post, we’ll discuss many of the new features in this release with code examples that you can find in a Jupyter Notebook on GitHub. As always, the official changelog has an exhaustive list of new features, what’s changed, what’s removed, and what’s fixed. Before we continue, don’t forget to upgrade your Mojo🔥. Let’s dive into the new features.

Improved Collections: New List and Dict features

In Mojo 24.4 List and Dict introduce several new features to make them even more Pythonic. Many of these features have come directly from our community:

  • List has new index(), count(), __contains__() and conforms to Stringable trait, thanks to contributions by @gabrieldemarmiesse, and @rd4com 
  • Dict has new clear(), reversed(), get(key), items(), values() and conforms to Stringable trait, thanks to contributions by @jayzhan211, @gabrieldemarmiesse, and @martinvuyk

Let’s take a look at how to use these through code examples.

Enhancements to List

In this example, we’ll calculate word frequency from the contents of a webpage and plot the results as a word cloud. In the code below, we use Mojo's Python interoperability feature to preprocess the text, tokenize it, and remove stop words. We also use the Python interoperability features to plot the results. For the purpose of demonstration, we’ll use the url = "https://docs.modular.com/mojo/manual/basics" to generate the word cloud from the Mojo manual. Feel free to experiment with different URLs. Now, let’s take a look at the code.

Mojo

from python import Python Python.add_to_path(".") utils = Python.import_module("utils") # Sample URL (you can replace this with any URL of your choice) url = "https://docs.modular.com/mojo/manual/basics" # Fetch and preprocess the text filtered_words = utils.fetch_and_preprocess_text(url) var mojo_word_list = List[String]() for fw in filtered_words:    mojo_word_list.append(fw) var unique_words = List[String]() var word_frequencies = List[Int]() for word in mojo_word_list:    if word[] not in unique_words:        unique_words.append(word[])        word_frequencies.append(mojo_word_list.count(word[]))    else:        var index = unique_words.index(word[])        word_frequencies[index] = mojo_word_list.count(word[]) py_unique_words = Python.list() py_word_frequencies = Python.list() for i in range(len(unique_words)):    py_unique_words.append(unique_words[i])    py_word_frequencies.append(word_frequencies[i]) utils.plot_word_cloud(py_unique_words, py_word_frequencies)

Output:

In the example above, first we fetch a list of filtered words from the webpage in url using utils.fetch_and_preprocess_text(url). After that we’re ready to calculate word frequencies. 

We highlight the use of __contains__() in the code word[] not in unique_words: where the condition checks whether the current word is already in the unique_words list. If the word is not in unique_words, it means this is the first time we are encountering this word. If the word is not already in unique_words, we append it to the unique_words list. We then count how many times this word appears in the original words list using the count() method. mojo_word_list.count(word) counts the number of occurrences of word[] in mojo_word_list. The frequency count of the word is appended to the word_frequencies list at the same index as the word in unique_words. This means that unique_words and word_frequencies will have corresponding elements. 

To plot the word cloud, each word is plotted at a random position with a size proportional to its frequency, and random colors are used for the words. We use the Python interoperability features to call the plotting function in utils.plot_word_cloud()

Enhancements to Dict

In this example we’ll use the Monte Carlo method for approximating the approximate value of Pi using new Dict features. The Monte Carlo method approximates pi by randomly generating points within a unit square and counting the number of points that fall within the unit circle inscribed within the square. The ratio of the points inside the circle to the total points can be used to approximate. We’ve written about this in more detail in an earlier blog post. Be sure to read that for more details on the math behind why this works. In this demo below we use Dict to methods exclusively instead of Arrays to implement the solution.

Mojo

from python import Python from random import random_float64 Python.add_to_path(".") utils = Python.import_module("utils") # Function to approximate pi using Monte Carlo method def approximate_pi(num_points: Int) -> (Float64, Dict[String, List[List[Float64]]]):    var inside_circle: Int = 0    points = Dict[String, List[List[Float64]]]()    keys = List[String]("inside", "outside")    points = Dict.fromkeys(keys, List[List[Float64]]())  # Using fromkeys to initialize dictionary        for _ in range(num_points):        x = random_float64(-1, 1)        y = random_float64(-1, 1)        if x**2 + y**2 <= 1.0:            inside_circle += 1            points["inside"].append(List(x, y))        else:            points["outside"].append(List(x, y))        pi_approx = 4 * inside_circle / num_points    return pi_approx, points # Number of points to generate num_points = 10000 # Approximate pi and get points data pi_approximation, points_data = approximate_pi(num_points) # Display the dictionary items print("Points inside and outside the circle:") for kv in points_data.items():    print(kv[].key,":",len(kv[].value)," points") # Use the get method to retrieve points data for "inside" points inside_points = points_data.get("inside") if inside_points:    print("\nNumber of points inside the circle:", len(inside_points.take())) # Reverse the order of the dictionary keys and print them print("\nReversed keys of points data:") for key in reversed(points_data):    print(key[]) py_points_data = Python.dict() py_val_list = Python.list() py_xy_list = Python.list() for kv in points_data.items():    for kv_val in kv[].value:        for kv_xy in kv_val[]:            py_xy_list.append(kv_xy[])        py_val_list.append(py_xy_list)        py_xy_list=[]    py_points_data[kv[].key] = py_val_list    py_val_list=[] utils.plot_points(py_points_data, pi_approximation) # Clear the dictionary points_data.clear() print("\nPoints data dictionary after clearing:") for key in points_data:    print(key[])

Output:

In the example above, we first create a Points dictionary, from new fromkeys static method to initialize Dict with keys from the List variable keys and set values to be empty lists. We use points_data.items() to print each items’ key and value. We also use reversed() to print the reversed order of keys. We also use get(key) to retrieve the points data for a specific key ("inside" in this case) and since the output of get() is an Optional type we use the take() function to retrieve the value. Finally we also demonstrate the use of clear to clear the dictionary. To plot the image above we made use of a utility function in Python using Python interoperability, called utils.plot_points()

New traits: Absable, Powable, Representable, Indexer

Mojo 24.4 also includes new traits to make writing Math equations simpler, print string representation of objects and define containers that can be indexed using integral values.

  • Structs that conform to Absable and Powable traits will work with built in abs() and pow() functions. Absable types must implement __abs__() dunder method and Powable type must implement the __pow__() dunder method. Powable types can also be used with operator ** in addition to the pow() function.
  • Objects of structs that conform to the Representable trait must implement a __repr__() dunder method, which enables the repr() to be called on objects to provide a string that can, if possible, be used to recreate the object and can be very useful for debugging. Thanks to @gabrieldemarmiesse for contributing this feature.
  • Structs that conform to the Indexer trait allow their objects to be used as index variables that can be passed to __getitem__() and __setitem__(). Types conforming to the Indexer trait implement __index__() dunder method and are implicitly convertible to Int or by calling the built in function index().

In the example below I’ve implemented a struct called MojoArray that conforms to Absable, Powable, and Representable traits, therefore it implements __abs__(), __pow__() and __repr__() dunder methods. Here is the skeleton of our struct, the full implementation is available on GitHub.

Mojo

struct MojoArray[dtype: DType = DType.float64](Absable, Powable, Representable): ...    fn __abs__(self)->Self: ...    fn __pow__(self, exp: Self)->Self: ...    fn __repr__(self)->String:

In the code example above, we compute vectorized __abs__() and __pow__() as follows:

Mojo

fn __abs__(self)->Self:    var new_array = Self(self.numel)    @parameter    fn wrapper[simd_width:Int,rank:Int=1](idx: StaticIntTuple[rank]):        new_array._ptr.store[width=simd_width](idx[0], abs(self._ptr.load[width=simd_width](idx[0])))    elementwise[wrapper, simdwidthof[dtype](), 1](self.numel)    return new_array fn __pow__(self, exp: Self)->Self:    var new_array = Self(self.numel)    @parameter    fn wrapper[simd_width:Int,rank:Int=1](idx: StaticIntTuple[rank]):        new_array._ptr.store[width=simd_width](idx[0], self._ptr.load[width=simd_width](idx[0])**exp[0])    elementwise[wrapper, simdwidthof[dtype](), 1](self.numel)    return new_array

And __repr__() as follows:

Mojo

fn __repr__(self)->String:    var s:String = "MojoArray("    for i in range(self.numel):        s+=str(self[i])        if i != self.numel-1:            s+=","    return  s + ")"

Now, let’s create an object of the MojoArray struct to see these methods in action.

Mojo

v1 = MojoArray.randn(5) v2 = MojoArray.randn(5) exp = MojoArray(2,2,2,2,2) print("__repr__ output:") print(repr(v1)) print("\nDifference array:") print(v1-v2) print("\nabs of difference array") print(abs(v1-v2)) print("\nabs of difference array raised to exp") print(abs(v1-v2)**exp)

Output:

Output

__repr__ output: MojoArray(6.7687160540239288,11.124524422703082,-1.9429505117095691,7.5089635577024039,4.3696328963036475) Difference array: [-1.6371641143074642 14.349008521304423 -3.5144861431982495 10.003881958131833 1.9896616488954946] abs of difference array [1.6371641143074642 14.349008521304423 3.5144861431982495 10.003881958131833 1.9896616488954946] abs of difference array raised to exp [2.6803063371761437 205.89404554446696 12.351612850732506 100.0776542322356 3.9587534770855384]

As you can see writing abs(v1-v2)**exp is a very expressive way to write math equations with these new traits vs. something like (v1-v2).abs().pow(exp) which is what we’d have done previously.

Mojo 24.4 also includes a few other math specific traits math.Ceilable, math.CeilDivable, math.CeilDivableRaising, math.Floorable, and Truncable. See the changelog for more details.

os module enhancements

Mojo 24.4 also includes several file IO enhancements that makes Mojo standard library’s os module more Pythonic. Particularly, this release introduces the following functions: mkdir(), rmdir(), os.path.getsize(), os.path.join() and a new tempfile module that implements gettempdir() and mkdtemp() functions, thanks to contributions from @artemiogr97. Let’s take a look at an example to see how to use these methods in your own projects.

Mojo

import os import tempfile # Create a directory dir_name = "example_dir" os.mkdir(dir_name) print("Directory", dir_name, "created.") # Create a temporary directory temp_dir = tempfile.mkdtemp() print("Temporary directory created at", temp_dir) # Create a file in the temporary directory temp_file_path = os.path.join(temp_dir, "temp_file.txt") with open(temp_file_path, "w") as temp_file:    temp_file.write(str("This is a temporary file.")) print("File created at", temp_file_path) # Get the size of the file file_size = os.path.getsize(temp_file_path) print("Size of the file", temp_file_path, "is", file_size, "bytes.") # Get the system temporary directory system_temp_dir = tempfile.gettempdir() print("System temporary directory is", system_temp_dir.take()) # Remove the temporary directory and its contents os.remove(temp_file_path) os.rmdir(temp_dir) print("Temporary directory", temp_dir, "and its contents removed.") # Remove the created directory os.rmdir(dir_name) print("Directory", dir_name, "removed.")

Output:

Output

Directory example_dir created. Temporary directory created at /var/folders/4v/pt9r67795239mt40l5kzlkr40000gn/T/tmpmcoo96dw File created at /var/folders/4v/pt9r67795239mt40l5kzlkr40000gn/T/tmpmcoo96dw/temp_file.txt Size of the file /var/folders/4v/pt9r67795239mt40l5kzlkr40000gn/T/tmpmcoo96dw/temp_file.txt is 25 bytes. System temporary directory is /var/folders/4v/pt9r67795239mt40l5kzlkr40000gn/T/ Temporary directory /var/folders/4v/pt9r67795239mt40l5kzlkr40000gn/T/tmpmcoo96dw and its contents removed. Directory example_dir removed.

base64 package enhancements

This release also includes a new base64 package that offers encoding and decoding support for both the Base64 and Base16 encoding schemes. Base64 encoding is often used in tokenizers for large language models (LLMs) and we use it in our implementations of bpe and tiktoken tokenizer utilities for Llama3. Check out our Llama3 example in this repository. Let’s take a look at an example that show you how to use this new package in the Mojo standard library.

Mojo

import base64 from python import Python Python.add_to_path(".") utils = Python.import_module("utils") original_image = "mojo_fire.png" decoded_image = "decoded_mojo_fire.jpg" # Read the image file in binary mode with open(original_image, 'rb') as image_file:    # Encode the image to Base64    encoded_string = base64.b64encode(image_file.read()) # Print the Base64 string print(encoded_string) # Decode the Base64 string back to binary data decoded_image_data = base64.b64decode(encoded_string) # Write the binary data to a new image file with open(decoded_image, 'wb') as image_file:    image_file.write(decoded_image_data) print("Image decoded and saved as decoded_example.jpg") utils.plot_original_decoded_images(original_image, decoded_image)

Output:

You can see that the original and decoded images plotted side by side are the same. We use the utils.plot_original_decoded_images() helper function written in Python and called from Mojo using the Python interoperability feature.

Core language features

Mojo 24.4 also includes several core language features that are a bit harder to demonstrate with code examples. Most notably, this release Mojo has updated how def function arguments are handled. Previously, arguments were copied by default (owned convention), making them mutable but potentially causing performance issues due to unnecessary copies. Now, arguments use borrowed convention by default and only copied if mutated within the function. 

In this release you can also return multiple values from a function as a Tuple that can be unpacked into individual variables. For example in the earlier Enhancements to Dict section we define a method: def approximate_pi(num_points: Int) -> (Float64, Dict[String, List[List[Float64]]]). We call this method in this way to get the values of the Tuple into separate variables: pi_approximation, points_data = approximate_pi(num_points), where as previously we had to get the value as a Tuple variable and index into it to extract the values.

This release also introduces the new @parameter loop decorator which can be used with for loops where the loop variable is a compile time constant. This allows the Mojo compiler to perform a full unroll of the loop to improve performance. With the introduction of @parameter decorator for loops, the previously recommended @unroll decorator has now been deprecated.

There are many more core language enhancements in this release, see the changelog for a complete list.

New documentation pages

We also updated our documentation to include dedicated pages that dive deeper into the following topics:

But wait, there’s more!

Mojo 24.4 includes many more features that we didn’t cover in this blog post. Check out the changelog for a detailed list of what’s new, changed, moved, renamed, and fixed in this release. 

MAX 24.4 is also available for download today and for the first time we’re making it available on Mac OS. This release of MAX also includes several enhancements including New Quantization API for MAX Graphs, and full implementation of Llama 2 and Llama 3 models using Graph API with quantization. Read more in the MAX 24.4 announcement blog post.

All the examples I used in this blog post are available in a Jupyter Notebook on GitHub, check it out!

Until next time! 🔥

  • Person with blonde hair using a laptop with an Apple logo.

    Sign up today

    Signup to our Cloud Platform today to get started easily.

    Sign Up

  • Magnifying glass emoji with black handle and round clear lens.

    Browse open models

    Browse our model catalog, or deploy your own custom model

    Browse models

Sign up for our newsletter

Get all our latest news, announcements and updates delivered directly to your inbox. Unsubscribe at anytime.

Thanks for signing up to our newsletter! 🚀

Thank you,

Modular Sales Team

Oops! Something went wrong while submitting the form.