Micrograd-rs: An analysis of Rust’s memory allocation in neural networks
2025 (English)Independent thesis Basic level (degree of Bachelor), 10 credits / 15 HE credits
Student thesis
Abstract [en]
As machine learning frameworks grow, it becomes more important to balance the computational power and memory efficiency of these systems. This paper explores Rust’s memory allocation in neural networks by rewriting Micrograd, a minimalist autograd engine, into Micrograd-rs. We show that the over utilization of vectors, which are optimized by the Python backend, negatively affects Rust’s performance and memory efficiency effectively allocating the program to the heap. This paper serves as a guide for future software and hardware engineers who want to have a better understanding of the Rust borrow checker and discusses how Micrograd-rs and other machine learning frameworks could be improved in Rust allowing the program to allocate more bytes to the stack safely.
Abstract [sv]
I takt med att ramverk för maskininlärning växer blir det viktigare att balansera beräkningskraften och minneseffektiviteten hos dessa system. Denna uppsats utforskar Rusts minnesallokering i neurala nätverk genom att skriva om Micrograd, en minimalistisk autogradmotor, till Micrograd-rs. Vi visar att överanvändning av vektorer, som är optimerade av Python-backenden, negativt påverkar Rusts prestanda och minneseffektivitet som i praktiken allokerar programmet till heapen. Denna uppsats fungerar som en guide för framtida mjukvaru- och hårdvaruingenjörer som vill ha en bättre förståelse av Rusts borrow checker och diskuterar hur Micrograd-rs och andra ramverk för maskininlärning kan förbättras i Rust, vilket gör att programmet kan allokera fler byte till stacken på ett säkert sätt.
Place, publisher, year, edition, pages
2025. , p. 37
Series
TRITA-EECS-EX ; 2025:363
Keywords [en]
Rust, Machine Learning, Memory Allocation, Memory Safety, Neural Network, Micrograd
National Category
Computer and Information Sciences
Identifiers
URN: urn:nbn:se:kth:diva-367696OAI: oai:DiVA.org:kth-367696DiVA, id: diva2:1985858
Supervisors
Examiners
2025-08-062025-07-282025-08-06Bibliographically approved