1 AI and LLMs

The term Artificial intelligence (AI) refers to the capacity of a computer to perform tasks typically associated with human intelligence (Wikipedia 2025a). The field of AI has several non-mutually-exclusive foci. These include:

A number of recent developments, including transformers –a neural network framework that weighs the importance of text components and creates responses through a word embedding table (Wikipedia 2025d)– and Large Language Models (LLMs) –machine learning entities trained on a vast amount of text, for the purpose of language processing and language generation (Wikipedia 2025c)– have resulted in dramatic improvements in NLP performance. The most sophisticated LLMs are Generative Pre-trained Transformer (GPT) models. By 2023 GPT models were able to achieve human-level scores on the bar exam and the SAT test, among other applications (Bushwick 2023).

GPT models may generate biased reports –largely as a result of biased training data (Zack et al. 2024), and hallucinations (plausible-sounding random falsehoods)(Wikipedia 2025b). Despite these drawbacks, however, the capacity of GPT and other AI approaches to emulate (and potentially improve on) processes previously under human proprietorship is clear (and unnerving). Indeed, because of this potential, massive investments (mostly from entrenched software giants, e.g., Microsoft, Oracle, Meta, Google) have been made into AI-associated infrastructure. This includes the ongoing construction of new data centers and server farms (Van Der Vlist, Helmond, and Ferrari (2024), Fig 1.1). Business Insider reported last week that data center construction costs in the US could total more than $1 trillion by 2028.


A > $3.3 billion Microsoft data center under construction in Mt Pleasant Wisconsin. The first phase of the center will consume enough energy annually to power several hundred thousand homes.

Figure 1.1: A > $3.3 billion Microsoft data center under construction in Mt Pleasant Wisconsin. The first phase of the center will consume enough energy annually to power several hundred thousand homes.


As a result of these efforts, and the high energy use of GPT processes, energy demands of data centers are excepted to double globally by 2030 (Kolbert 2024). (De Vries 2023) estimated that if Google were to integrate generative AI into every search thread, its electricity usage would rise to approximately \(29 \times 10^9\) kilowatt-hours per year, exceeding the annual energy demand of many countries, including Kenya, Guatemala, and Croatia.

Today we will briefly explore GPT energy use and CO2 production in a lab using the Python programming language. This lab does not consider other environment impacts, including water use of data centers, a serious concern in the arid intermountain west.

2 Python

Python is a popular open source (free) programming language and computational environment. We will use Python today to help quantify the energy and carbon footprint of generative AI LLMs. We will run Python using Spyder, an Integrated Development Environment (IDE) for Python. There are a couple of preliminary steps.


The Spyder Preferences interface.

Figure 2.1: The Spyder Preferences interface.


Now we can explore Python a bit. To start with, we can use Python as a calculator. Type 2 + 2 and click in the text editor component of Sypder (by default, the left hand side) .

2 + 2
4

Like R –a language we will learn about later in the semester– Python is an Object Oriented Programming (OOP) language. Type:

obj1 = 2 + 2 

The result, 4, can be accessed by typing the object name: obj1 (or whatever I named the object).

obj1
4

Here I create a Python numerical array of the numbers, 1, 5, and 7, with help from the Python numpy package:

import numpy as np
obj2 = np.array([1,5,7])

The line import numpy as np imports numpy, and allows me to call the package using the name np. The code np.array calls the function array in the numpy package.

I can use Python objects in various ways. For instance, here I add obj1 and obj2, and take the log of the sum.

np.log(obj1 + obj2)
array([1.60943791, 2.19722458, 2.39789527])

3 Computation of LLM Energy and Carbon Consumption

The EcoLogits Python library tracks the energy consumption and environmental impacts of generative AI models.

The Python code below allows evaluation of energy consumption under the OpenAI generative AI framework.

from ecologits import EcoLogits
from openai import OpenAI
import time

# Initialize EcoLogits
EcoLogits.init(providers=["openai"])

client = OpenAI(api_key="key")

# Make a generative AI query
response = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[
        {"role": "user", "content": "Tell me a funny joke!"}
    ]
)


The script above is contained in the file codeecologits.py. Open the file or simply paste the code from the chunk above into the Spyder text editor. You will have to obtain a secret key from OpenAI here and insert it in the place of "key" on line 8 above.


Running the code I get:

The model architecture has not been released, expect lower precision. For further information visit https://ecologits.ai/tutorial/warnings_and_errors/#model-arch-not-released
The model architecture is multimodal, expect lower precision. For further information visit https://ecologits.ai/tutorial/warnings_and_errors/#model-arch-multimodal

We are told that our energy consumption results may be somewhat imprecise due to a lack of specific knowledge concerning the OpenAI model architecture, and multimodality in the predictions.

3.1 Response from query

The entity response, created on Line 10-14 above, is a complex Python object with many attributes. To get the AI reply to my query: "Tell me a funny joke!", I can use:

response.choices[0].message.content
'Sure! Why did the scarecrow win an award?\n\nBecause he was outstanding in his field!'

3.2 Primary energy

To get “primary energy” usage (the amount of energy consumed from natural sources such as raw fuels and other forms of energy, including waste), as the result of my query, I can use:

response.impacts.pe
PE(type='PE', name='Primary Energy', value=RangeValue(min=0.0005060237451478457, max=0.0015149204675266547), unit='MJ')

Units above are MegaJoules = \(10^6\) Joules. Recall that there are 4.184 Joules in a Calorie (cal), and 1 cal is the amount of energy required to raise 1 gram of H2O 1 degree C.

3.3 Energy used

To get the minimum and maximum energy used in terms of direct electricity consumption of GPUs, servers and other equipment from data centers, as a result of my query, I can use:

response.impacts.energy
Energy(type='energy', name='Energy', value=RangeValue(min=4.838540633333333e-05, max=0.000148121207), unit='kWh')

Note that energy units here are kilowatt hours.

response.impacts.usage.energy.unit
'kWh'

A watt (W) is a rate of energy use. Specifically 1W = 1J/s. There are 1000 watts in a kilowatt (kW), and the energy consumption of a process requiring 1000 W, over an hour, is a kilowatt-hour (kWh).

3.4 CO2 produced

To get the CO2 production equivalent resulting from the query we can use:

response.impacts.gwp
GWP(type='GWP', name='Global Warming Potential', value=RangeValue(min=3.036204408824052e-05, max=9.025673050682423e-05), unit='kgCO2eq')

Note that the units are kilograms of equivalent CO2.

Questions

  1. In Python, create a numerical object with your name and perform some simple math with it.
  2. To have fun with ChatGPT, create a simple OpenAI query by modifying the fourth item in the message argument on Line 13 in the Python code above.
    1. Show the AI reply by running: response.choices[0].message.content.
    2. Run response.impacts.pe. How many MegaJoules of primary energy were used?
  3. According to WebMD, a moderately active female between the ages of 19-24 should consume 2,000-2,200 kcal (kilocalories) per day.
    1. Compute, using Python or some other software, the number of MegaJoules in 2000 kcal. Mathematically, you could use an approach like: \[\frac{2000 \text{ kcal}}{1} \times \frac{1000 \text{ cal}}{1 \text{ kcal}} \times \frac{4.184 \text{ J}}{1 \text{ cal}} \times \frac{1 \text{ MJ}}{10^6 \text{ J}}\] Show your work using screen snips.
    2. Your computation in Question 1 probably around a second. To get the approximate amount of energy you consumed in 1 second, divide your result in (3a) by \(86400\). That is, \(24\) hrs \(\times 60\) minutes \(\times 60\) seconds.
    3. Compare your answers in (2b) and (3b). What are your conclusions?
  4. We now consider the moderately difficult (AI-generated) query: “Explain the most likely reason why a friend would unexpectedly bring a freshly baked loaf of bread to a dinner party. Your explanation should take into account the social context, the act of baking, and the expectations of a host. Furthermore, provide a potential, but less likely, alternative reason and contrast the two.”
    1. Place the query above into the place where "Tell me a funny joke!" is on line 14. Also, insert the code: x = time.time() to a line above where the response object is created in the main OpenAI Python script. For instance, you could insert the code on Line 9. Also, add the script y = time.time() to a new line, below the current last line of the script (below Line 16). Show a screenshot of your work so far.
    2. Run the entire Python script (including the newly inserted code). Get the response from OpenAI using response.choices[0].message.content, and paste it into your document.
    3. Get the system time required for the query by typing: y - x.
    4. Get the energy used by the query by typing: response.impacts.energy.
    5. To consider the energy required for a server to handle a constant daily stream of moderate (and silly) threads like these, calculate the kilowatt hours required if the query thread above took an entire day. To do this, let \(s\) be the number of seconds required by your query thread (your answer in 4c), and let \(k\) be the energy used (your answer in 4d). Calculate: \[\frac{k}{s} \times 86,400\] Note that a single commercial server can have hundreds of cores and be capable of handling thousands of threads in parallel. Server farms can contain millions of servers, with the potential for processing billions of threads simultaneously.
    6. Comment on your result in (4e) given that an average US household uses 37.5 kWh/day, and households in East Africa use about 3.7 kWh/day.

References

Bushwick, Sophie. 2023. “What the New GPT-4 AI Can Do.” Scientific American 16.
De Vries, Alex. 2023. “The Growing Energy Footprint of Artificial Intelligence.” Joule 7 (10): 2191–94.
Kolbert, Elizabeth. 2024. “The Obscene Energy Demands of AI.” The New Yorker 9.
Russell, Stuart J, and Peter Norvig. 2021. “Artificial Intelligence: A Modern Approach, Global Edition 4e.”
Van Der Vlist, Fernando, Anne Helmond, and Fabian Ferrari. 2024. “Big AI: Cloud Infrastructure Dependence and the Industrialisation of Artificial Intelligence.” Big Data & Society 11 (1): 20539517241232630.
Wikipedia. 2025a. “Artificial Intelligence.” https://en.wikipedia.org/wiki/Artificial_intelligence.
———. 2025b. “Hallucination (Artificial Intelligence).” https://en.wikipedia.org/wiki/Hallucination_(artificial_intelligence).
———. 2025c. “Large Language Model.” https://en.wikipedia.org/wiki/Large_language_model.
———. 2025d. “Transformer (Deep Learning Architecture).” https://en.wikipedia.org/wiki/Transformer_(deep_learning_architecture).
Zack, Travis, Eric Lehman, Mirac Suzgun, Jorge A Rodriguez, Leo Anthony Celi, Judy Gichoya, Dan Jurafsky, et al. 2024. “Assessing the Potential of GPT-4 to Perpetuate Racial and Gender Biases in Health Care: A Model Evaluation Study.” The Lancet Digital Health 6 (1): e12–22.

  1. API stands for Application Programming Interface. An API provides glue code that allows one software framework (e.g., Python) to work directly with a foreign software system (e.g., OpenAI).↩︎