Technology
Green code in the age of AI: Can AI-generated code be energy-efficient?
Tiia Ohtokallio
This blog post explores the concept of “green code” in the context of generative AI and considers whether AI-generated code can truly be environmentally responsible.
The software industry is at the heart of modern technological development, but its growing environmental footprint is a cause for concern. Mark Zuckerberg from Meta has noted that energy production is a limiting factor in the use and development of AI. At the same time, tech giants have stated (Yle, Guardian) that the increased energy consumption of data centers due to AI use threatens their carbon neutrality goals.
The rapid progress of digitalization brings with it a critical question: Can we design and develop code that not only functions efficiently but also minimizes environmental impact? This consideration becomes increasingly important in the age of generative AI, as technologies such as large language models (LLMs) can fundamentally change the way software is developed.
The Environmental Impact of Software
Although the digital world appears intangible, it relies on a massive physical infrastructure: data centers, devices, and networks that consume vast amounts of energy and produce carbon emissions. Discussions often focus on the environmental impact of hardware, but the role of software is frequently overlooked. Nevertheless, software plays a significant part in increasing energy consumption and environmental burden.
In the context of websites, energy consumption is particularly affected by:
- Large and poorly optimized media files and images
- Excess, unused source code, such as unnecessary dependencies and other JavaScript code
- Inefficient caching and CDN solutions
The above factors impact energy consumption both on the server and the end-user’s device. Simply put, the shorter the loading times of a website, the more energy-efficient it is. As the demand for digital services increases, so does their environmental impact. This makes programming practices aimed at energy efficiency essential for a sustainable digital future.
Opportunities and risks of generative AI from the perspective of green code
Generative AI offers unprecedented opportunities for software development. There is even talk that software developers may soon become unnecessary, as AI takes over this work. The internet is full of online courses that teach coding with AI assistance without any technical expertise. With the help of AI, code can be created quickly using natural language, which increases developer productivity and shortens development cycles. Additionally, AI can improve code quality by identifying errors and suggesting corrections.
Despite these benefits, generative AI also faces challenges in creating environmentally responsible code. According to recent studies, such as Sikand et al. (2024), popular AI tools (ChatGPT, BARD now Gemini, Copilot) do not by default produce environmentally sustainable code. The study examined the generation of Java code based on specific criteria for environmental sustainability. The findings are intriguing, as they raise many questions about whether AI can be effectively leveraged to develop source code for environmentally responsible digital services.
Why does AI fail to create green code?
The shortcomings of generative AI in producing green code can be attributed to several factors, and there is currently no clear-cut answer. These reasons may include:
- Bias in training data: AI models are trained on existing code, which may not adhere to energy efficiency principles. If the code is not optimized from the start, the AI replicates these inefficiencies. Models have been trained using code from sources such as Stack Overflow and GitHub.
- Lack of sustainability goals: Current AI tools are primarily optimized for functionality and efficiency (e.g., the number of code lines or syntax), but energy efficiency is not a central priority for them.
- The black box nature of AI: The decision-making process of AI models is opaque, making it difficult to assess why a particular code structure is generated and how energy-efficient it ultimately is. This same challenge also applies to evaluating the ethics of AI.
Is a Green AI Revolution Needed?
To build a sustainable digital future, we need change – a “green AI revolution.” This requires a multifaceted approach focused on the following key actions:
Incorporating Green Coding Practices into Training Data
AI models must be trained with energy-efficient source code. This calls for collaboration among software developers to create and share environmentally responsible training data. Open-source initiatives could be a valuable avenue for this effort.
Developing Sustainability-Conscious AI Tools
Future AI tools must consider energy consumption as one of the key optimization targets.
Increasing Transparency
Explaining the decision-making processes of AI tools would help developers better guide the AI and optimize the code for energy efficiency.
Raising Awareness and Education
Software developers must understand the environmental impact of their work and adopt green coding practices. This requires integrating sustainability into training and professional development. Read more about minimizing the digital carbon footprint in our guide.
Sustainable Digital Future
Generative AI is revolutionizing software development, but its potential must be harnessed responsibly. Integrating energy efficiency and sustainability into AI is a critical step towards a digital future that not only innovates but does so in an environmentally responsible way.
Learn more about the research:
S. Sikand, R. Mehra, V. S. Sharma, V. Kaulgud, S. Podder and A. P. Burden, “Do Generative AI Tools Ensure Green Code? An Investigative Study,” 2024 IEEE/ACM International Workshop on Responsible AI Engineering (RAIE), Lisbon, Portugal, 2024, pp. 52-55.