What About Rust? GenAI, Game AI & In General
Archived from occybyte.com/resources · 2024-08-22
With the increasing integration of intensive AI technologies, it’s crucial to recognize that we’ve been utilizing general AI for a variety of purposes over the past two decades. The arrival of Generative AI has introduced new challenges, making the choice of programming languages more critical than ever. I believe the best mix of languages includes Python, Rust, and C#. The key lies in finding the right combination to gracefully tackle both current and novel issues.
Let’s think objectively first: Rust is an extremely operant language. I’m using operant to describe a language that’s efficient and continuously effective across various use cases, such as Embedded systems, Networking, and WebAssembly. It’s a low-resource language, with its ownership system being a primary reason to choose it. Under the guidance of an efficient engineer, Rust can be as good as C/C++.
Rust is still a young language, nearly a decade old, which means its ecosystem isn’t fully mature yet. People want to solve problems now, and while some are already utilizing Rust, many hobbyists and professionals will need training to harness its potential fully. Despite this, I’ve dipped into Rust myself and found it preferable to something like C++, even though C/C++ is more commonly used in gaming and robotics.
Rust will be a deciding language when it comes to newer statistical algorithms, Machine Learning, and AI, especially as companies and individuals push these technologies further. When it comes to web apps, I’d wager that Rust combined with WebAssembly could get the job done.
Now, let’s talk about Generative AI””it’s a resource hog. The best we can do is use the process of Quantization to reduce the “computational and memory costs of running an inference” (source: Quantization, Huggingface). Training a model requires substantial computational power. The data science and engineering behind this is still overwhelmingly dominated by Python. Stanford even created DSPY (Data Science Python, I assume).
Given this, web applications that want to incorporate AI, especially those with aggressive GPU rendering, should look toward Rust and WebAssembly. It’s important to remember that most people’s personal””and sometimes even professional””systems can’t handle the RAM, GPU, and CPU demands that come with AI. Unity has also utilized WebAssembly as a choice of binary executable for their web builds,
Many companies touting AI products to businesses are effectively offering wrappers that require us to pay them for storage space and GPUs on their servers to compute and store outputs. But outside of AI, I suspect that future hardware and robotics will shift toward using Rust. There’s also the matter of how Rust’s Ownership system prevents memory leaks, which I believe will be important in Quantum computing. One article suggests that quantum superpositioning can be somewhat fixed, or at least mitigated, by using WebAssembly, which is built using Rust to create an algorithmic decoder for quantum error corrections.
Then, there’s the borrowing feature. The solutions Rust offers make it worth the cost to invest in and shift critical performance engineers and programmers from languages like C/C++. A single mistake with pointers in C/C++ can be costly and lead to memory leak issues. The longer compile times of Rust, compared to other languages, are worth it.
The problems these technologies solve are often performance-critical and security-based, which also makes them optimal for government usage. I’d wager that Rust could become a critical language for space and, eventually, deep space tech. What future problems can Rust solve, and how can we work towards it?
Let’s shift a bit more towards Game AI.
Game Artificial Intelligence has been evolving for a long time. One of the most significant innovations in recent decades was the GOAP (Goal-Oriented Action Planning) enemy AI introduced in F.E.A.R. (First Encounter Assault Recon). As someone who has invested in books from Routledge and CRC Press to dive deeper into Game Design & Development AI””areas I’m looking to specialize in””this innovation is particularly interesting.
So, why Rust? As I was reading Game AI Uncovered, both volumes, I came across chapters that delve into the process of selecting an architecture and a “brain” for an NPC. In Chapter 5, “Building A Buddy: Choosing the Right Brain,” Dale Green introduces the concept of “Buddy AI,” a collective term for systems designed to create an AI agent””a buddy, or companion””whose behaviors are tailored to aid and accompany the player throughout their journey. In Chapter 6, Tobias Karlsson discusses how “The decision-making architecture is the framework within which your AI decides what behavior to execute and then executes that behavior at any given moment.”
If we look at this chart:
Here’s what the chart tells us:
- Prioritized List and Hierarchical Prioritized List architectures are very CPU-efficient. * Behavior Trees, FSM (Finite-State Machines), and hFSM (Hierarchical FSM) require moderate CPU usage. * Utility-Based, Hierarchical Utility-Based, Planners, and Hierarchical Planners architectures are more CPU-intensive.
Why Rust for Game AI?
Rust, a modern systems programming language, is increasingly recognized for its performance and safety, making it an excellent choice for developing robust AI systems. When selecting a decision-making architecture for a game AI, Rust’s strengths in memory safety, concurrency, and efficient resource management can help mitigate many of the challenges associated with complex AI behaviors. Let’s explore how Rust aligns with some of the key architectures mentioned:
- Prioritized Behavior Lists: Simple and CPU-efficient, but can result in monolithic, hard-to-maintain code. Rust’s safety features help avoid common pitfalls like memory leaks. * Hierarchical Prioritized Behavior Lists: Adds complexity with nested behaviors, but Rust excels in managing hierarchical data, simplifying debugging and maintenance. * Behavior Trees: Rust’s ownership system and pattern matching support modularity and stable state transitions, making Behavior Trees ideal for complex AI tasks. * Finite-State Machines (FSM): Effective for clear state transitions, with Rust’s compile-time checks aiding in managing scalability challenges. * High CPU Draw Considerations: While Prioritized Lists and FSMs can be CPU-intensive, Rust’s optimization and resource management ensure smooth performance, even in constrained environments.
As AI continues to evolve, especially in the realm of gaming, the need for efficient, robust, and scalable architectures becomes ever more critical. Rust’s unique blend of safety, performance, and modularity positions it as a powerful tool for the future of Game AI development. Whether you’re building a simple decision-making system or a complex, hierarchical AI, Rust offers the tools and features needed to create cutting-edge, efficient, and reliable AI systems that can keep up with the demands of modern gaming.
Moving a little more back to Chapter 5, “Battle Buddies”:
Buddy AI, or companion AI, is among the most complex types of artificial intelligence in video games. Unlike standard AI agents, buddies are designed to accompany and assist the player throughout the game, often being in the spotlight due to their continuous presence. This makes their behavior critical to the player’s experience. A single misstep, such as a buddy making a poor decision during a crucial moment, can break immersion and disrupt the gameplay.
The intricacies of Buddy AI lie in its need to be both intelligent and responsive without overshadowing the player. Buddies must make decisions in real-time, manage resources like ammo and health efficiently, and position themselves strategically to support the player without becoming a hindrance. These requirements introduce a level of complexity that demands robust, efficient systems to avoid bugs and performance issues.
Why Rust for Buddy AI?
Buddy AI, are one of the most intricate forms of artificial intelligence in games, stands apart due to its constant presence and essential role in enhancing the player’s experience. Unlike typical AI agents, buddies must be sharp, resourceful, and always a step ahead without overshadowing the player. A single poor decision during a critical moment can shatter immersion and disrupt the gameplay flow.
Buddy AI’s complexity demands systems that are both intelligent and efficient, ensuring they can make real-time decisions, manage resources like ammo and health, and position themselves strategically””all without becoming a burden to the player. This intricate balance requires robust architecture to prevent bugs and maintain performance.
Why Rust?
Given these challenges, Rust’s performance, safety, and concurrency are perfect for developing Buddy AI systems:
- Robustness and Reliability: Rust’s memory safety and strict compile-time checks prevent common issues like memory leaks, ensuring Buddy AI remains reliable throughout the game. * Efficient Real-Time Decision-Making: Rust’s optimizations support the real-time processes crucial for Buddy AI, making it ideal for implementing decision-making architectures like Behavior Trees or FSMs. * Managing Complexity: Rust’s ownership system and type safety help manage the complexities of resource management, ensuring the buddy remains effective without performance bottlenecks. * Generative AI Integration: Rust efficiently handles the added computational load from Generative AI, ensuring that additional content like dialogue or behaviors doesn’t compromise performance. Its seamless integration with WebAssembly allows offloading tasks for smoother in-game experiences. * Continuous Interaction: With Rust’s concurrency model, Buddy AI can stay responsive and adaptive, even during the most resource-intensive gameplay scenarios.
But this is all just research, guesses and why nots based on what I’ve been learning thus far. I’m also all out of steam there right in the middle. I’m just putting all my thoughts about this stuff here to ponder later.