Skip to content

Commit 78e2188

Browse files
authored
Merge pull request #21 from MIT-Emerging-Talent/gemma
Milestone 3: google-gemma
2 parents 2c6e0f0 + ca52eec commit 78e2188

9 files changed

Lines changed: 2324 additions & 0 deletions

google_gemma/README.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Project: “Green AI Automated RAG Testing with Gemma”
2+
3+
## Overview
4+
5+
We built an interactive retrieval-augmented generation (RAG) pipeline using the
6+
open-weight model *Gemma 2-2b* by Google and applied it to a standardized text
7+
and prompt set derived from the Apollo 11 lunar landing.
8+
9+
**The goal:**
10+
11+
* evaluate summarisation, reasoning, retrieval, paraphrasing, and creative tasks
12+
in a controlled, reproducible way — logging both answer quality and local
13+
sustainability metrics (energy/carbon emissions) via CodeCarbon.
14+
15+
## Model
16+
17+
**Model ID:** `google/gemma-2-2b-it` (Hugging Face)
18+
19+
**Key attributes:**
20+
21+
* Open-weight decoder-only model trained by Google
22+
* Supports text-generation and conversational usage
23+
* Suitable for research, summarisation, reasoning, and retrieval tasks
24+
* Lightweight enough for deployment on modest compute resources
25+
26+
Model link: [https://huggingface.co/google/gemma-2-2b-it](https://huggingface.co/google/gemma-2-2b-it)
27+
28+
## What We Did
29+
30+
1. Created a source document (`source.txt`) using ~1,400 words of selected
31+
Wikipedia excerpts on Apollo 11.
32+
2. Defined a set of 21 standardised prompts spanning five categories:
33+
summarisation, reasoning, RAG (fact retrieval), paraphrasing, and creative
34+
generation.
35+
3. Built a document retrieval component using sentence-transformers to chunk
36+
the document and select top-k relevant chunks per query.
37+
4. Developed an interactive notebook workflow that:
38+
39+
* Accepts a question at runtime
40+
* Runs RAG → Draft → Critic → Refiner cycles using Gemma
41+
* Tracks local CPU/GPU energy usage and CO₂ emissions with CodeCarbon
42+
* Logs each question, answer, timestamp, and emissions to a single
43+
append-only log file
44+
5. Logged runtime latency and emissions per query for performance and
45+
sustainability insights.
46+
47+
## How to Use
48+
49+
1. Clone the repository:
50+
51+
```bash
52+
git clone <YOUR_REPO_URL>
53+
cd your_repo_folder
54+
```
55+
56+
2. Place your `source.txt` into `./data/`.
57+
58+
3. Add your Hugging Face API key in the config cell.
59+
60+
4. Run the notebook setup cells, then use the interactive prompt cell to ask
61+
questions.
62+
63+
## Why This Matters
64+
65+
* **Reproducibility** — fixed source text and prompt set allow consistent
66+
evaluation across models.
67+
* **Efficiency vs. Accuracy** — emissions are logged alongside outputs to
68+
explore trade-offs between model performance and energy cost.
69+
* **Accessibility** — uses an open model and standard Python tools, making
70+
research on small language models feasible even on laptops.

google_gemma/data/source.txt

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
Apollo 11 – Lunar Descent and Moonwalk
2+
3+
As the descent began, Armstrong and Aldrin found themselves passing landmarks on the
4+
surface two or three seconds early, and reported that they were “long”; they would land
5+
miles west of their target point. Eagle was traveling too fast. The problem could have been
6+
mascons—concentrations of high mass in a region or regions of the Moon’s crust that
7+
contains a gravitational anomaly, potentially altering Eagle’s trajectory.
8+
9+
Five minutes into the descent burn, and 6,000 feet (1,800 m) above the surface of the
10+
Moon, the LM guidance computer (LGC) distracted the crew with the first of several
11+
unexpected 1201 and 1202 program alarms. Inside Mission Control Center, computer
12+
engineer Jack Garman told Guidance Officer Steve Bales it was safe to continue the
13+
descent, and this was relayed to the crew. The program alarms indicated “executive
14+
overflows”, meaning the guidance computer could not complete all its tasks in real-time and
15+
had to postpone some of them. Margaret Hamilton, the Director of Apollo Flight Computer
16+
Programming at the MIT Charles Stark Draper Laboratory later recalled: “To blame the
17+
computer for the Apollo 11 problems is like blaming the person who spots a fire and calls
18+
the fire department. Actually, the computer was programmed to do more than recognize
19+
error conditions. A complete set of recovery programs was incorporated into the software.
20+
The software’s action, in this case, was to eliminate lower priority tasks and re-establish
21+
the more important ones. The computer, rather than almost forcing an abort, prevented an
22+
abort. If the computer hadn’t recognized this problem and taken recovery action, I doubt if
23+
Apollo 11 would have been the successful Moon landing it was.”
24+
25+
When Armstrong again looked outside, he saw that the computer’s landing target was in a
26+
boulder-strewn area just north and east of a 300-foot-diameter (91 m) crater, so he took
27+
semi-automatic control. Throughout the descent, Aldrin called out navigation data to
28+
Armstrong, who was busy piloting Eagle. Now 107 feet (33 m) above the surface,
29+
Armstrong knew their propellant supply was dwindling and was determined to land at the
30+
first possible landing site.
31+
32+
Armstrong found a clear patch of ground and maneuvered the spacecraft towards it. They
33+
were now 100 feet (30 m) from the surface, with only 90 seconds of propellant remaining.
34+
Lunar dust kicked up by the LM’s engine began to impair his ability to determine the
35+
spacecraft’s motion.
36+
37+
A light informed Aldrin that at least one of the 67-inch (170 cm) probes hanging from
38+
Eagle’s footpads had touched the surface and he said: “Contact light!” Three seconds later,
39+
Eagle landed and Armstrong shut the engine down. Aldrin immediately said “Okay, engine
40+
stop.”
41+
42+
Eagle landed at 20:17:40 UTC on Sunday July 20 with 216 pounds (98 kg) of usable fuel
43+
remaining. Information available to the crew and mission controllers during the landing
44+
showed the LM had enough fuel for another 25 seconds of powered flight before an abort
45+
without touchdown would have become unsafe, but post-mission analysis showed that the
46+
real figure was probably closer to 50 seconds.
47+
48+
Armstrong acknowledged Aldrin’s completion of the post-landing checklist with “Engine
49+
arm is off”, before responding to the CAPCOM, Charles Duke, with the words, “Houston,
50+
Tranquility Base here. The Eagle has landed.” Duke expressed the relief at Mission Control:
51+
“Roger, Twan—Tranquility, we copy you on the ground. You got a bunch of guys about to
52+
turn blue. We’re breathing again. Thanks a lot.”
53+
54+
Preparations for Neil Armstrong and Buzz Aldrin to walk on the Moon began at 23:43 UTC.
55+
These took longer than expected; three and a half hours instead of two. Six hours and
56+
thirty-nine minutes after landing, Armstrong and Aldrin were ready to go outside, and
57+
Eagle was depressurized.
58+
59+
Eagle’s hatch was opened at 02:39:33. Armstrong initially had some difficulties squeezing
60+
through the hatch with his portable life support system (PLSS). At 02:51 Armstrong began
61+
his descent to the lunar surface. Climbing down the nine-rung ladder, Armstrong pulled a
62+
D-ring to deploy the modular equipment stowage assembly (MESA) folded against Eagle’s
63+
side and activate the TV camera.
64+
65+
Despite some technical and weather difficulties, black and white images of the first lunar
66+
EVA were received and broadcast to at least 600 million people on Earth.
67+
68+
After describing the surface dust as “very fine-grained” and “almost like a powder”, at
69+
02:56:15, six and a half hours after landing, Armstrong stepped off Eagle’s landing pad and
70+
declared: “That’s one small step for [a] man, one giant leap for mankind.”
71+
72+
Armstrong intended to say “That’s one small step for a man”, but the word “a” is not
73+
audible in the transmission, and thus was not initially reported by most observers of the live
74+
broadcast. When later asked about his quote, Armstrong said he believed he said “for a
75+
man”, and subsequent printed versions of the quote included the “a” in square brackets.
76+
77+
About seven minutes after stepping onto the Moon’s surface, Armstrong collected a
78+
contingency soil sample using a sample bag on a stick. Twelve minutes after the sample
79+
was collected, he removed the TV camera from the MESA and made a panoramic sweep,
80+
then mounted it on a tripod. Aldrin joined Armstrong on the surface. He described the view
81+
with the simple phrase: “Magnificent desolation.”
82+
83+
Armstrong said moving in the lunar gravity, one-sixth of Earth’s, was “even perhaps easier
84+
than the simulations … It’s absolutely no trouble to walk around.” Aldrin joined him on the
85+
surface and tested methods for moving around, including two-footed kangaroo hops. The
86+
PLSS backpack created a tendency to tip backward, but neither astronaut had serious
87+
problems maintaining balance. The fine soil was quite slippery.
88+
89+
The astronauts planted the Lunar Flag Assembly containing a flag of the United States on
90+
the lunar surface, in clear view of the TV camera. Aldrin remembered, “Of all the jobs I had
91+
to do on the Moon the one I wanted to go the smoothest was the flag raising.” But the
92+
astronauts struggled with the telescoping rod and could only insert the pole about 2 inches
93+
(5 cm) into the hard lunar surface. Before Aldrin could take a photo of Armstrong with the
94+
flag, President Richard Nixon spoke to them through a telephone-radio transmission, which
95+
Nixon called “the most historic phone call ever made from the White House.”
96+
97+
They deployed the EASEP, which included a Passive Seismic Experiment Package used to
98+
measure moonquakes and a retroreflector array used for the lunar laser ranging
99+
experiment. Then Armstrong walked 196 feet (60 m) from the LM to take photographs at
100+
the rim of Little West Crater while Aldrin collected two core samples. He used the
101+
geologist’s hammer to pound in the tubes—the only time the hammer was used on Apollo
102+
11—but was unable to penetrate more than 6 inches (15 cm) deep.
103+
104+
The astronauts then collected rock samples using scoops and tongs on extension handles.
105+
Many of the surface activities took longer than expected, so they had to stop documenting
106+
sample collection halfway through the allotted 34 minutes. Aldrin shoveled 6 kilograms
107+
(13 lb) of soil into the box of rocks to pack them in tightly. Two types of rocks were found in
108+
the geological samples: basalt and breccia.
109+
110+
While on the surface, Armstrong uncovered a plaque mounted on the LM ladder, bearing
111+
two drawings of Earth, an inscription, and signatures of the astronauts and President Nixon.
112+
The inscription read: “Here men from the planet Earth first set foot upon the Moon July
113+
1969, A. D. We came in peace for all mankind.”
114+
115+
Mission Control used a coded phrase to warn Armstrong his metabolic rates were high, and
116+
that he should slow down. As metabolic rates remained generally lower than expected for
117+
both astronauts throughout the walk, Mission Control granted the astronauts a 15-minute
118+
extension.
119+
120+
Aldrin entered Eagle first. With some difficulty the astronauts lifted film and two sample
121+
boxes containing 21.55 kilograms (47.5 lb) of lunar surface material to the LM hatch using a
122+
flat cable pulley device called the Lunar Equipment Conveyor (LEC). Armstrong then
123+
jumped onto the ladder’s third rung, and climbed into the LM. After transferring to LM life
124+
support, the explorers lightened the ascent stage for the return to lunar orbit by tossing out
125+
their PLSS backpacks, lunar overshoes, an empty Hasselblad camera, and other equipment.
126+
The hatch was closed again at 05:11:13. They then pressurized the LM and settled down to
127+
sleep.

google_gemma/emissions.csv

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
timestamp,project_name,run_id,experiment_id,duration,emissions,emissions_rate,cpu_power,gpu_power,ram_power,cpu_energy,gpu_energy,ram_energy,energy_consumed,water_consumed,country_name,country_iso_code,region,cloud_provider,cloud_region,os,python_version,codecarbon_version,cpu_count,cpu_model,gpu_count,gpu_model,longitude,latitude,ram_total_size,tracking_mode,on_cloud,pue,wue
2+
2025-11-15T15:47:16,codecarbon,27c11b81-b7a7-47c9-ab82-9ae317559fe9,5b0fa12a-3dd7-45bb-9766-cc326314d9f1,45.95574010000564,0.0005071162574599,1.103488391997087e-05,42.5,0.0,10.0,0.0007198499136804,0.0,0.0001693503708332,0.0008892002845137,0.0,Egypt,EGY,,,,Windows-11-10.0.26100-SP0,3.13.5,3.0.8,12,12th Gen Intel(R) Core(TM) i5-1235U,,,,,7.692127227783203,machine,N,1.0,0.0
3+
2025-11-15T15:51:00,codecarbon,7005ea2e-d9a3-40aa-900e-f95b5e5623a2,5b0fa12a-3dd7-45bb-9766-cc326314d9f1,158.46234359999653,0.0013179222183238,8.316942614774643e-06,42.5,0.0,10.0,0.0018707337542361,0.0,0.0004401698980555,0.0023109036522917,0.0,Egypt,EGY,,,,Windows-11-10.0.26100-SP0,3.13.5,3.0.8,12,12th Gen Intel(R) Core(TM) i5-1235U,,,,,7.692127227783203,machine,N,1.0,0.0
4+
2025-11-15T15:52:55,codecarbon,f2cce301-9b4f-4e6a-b97d-5179efd64332,5b0fa12a-3dd7-45bb-9766-cc326314d9f1,47.64462380000623,0.0003962538208029,8.316863251272021e-06,42.5,0.0,10.0,0.0005624669925697,0.0,0.0001323421463889,0.0006948091389586,0.0,Egypt,EGY,,,,Windows-11-10.0.26100-SP0,3.13.5,3.0.8,12,12th Gen Intel(R) Core(TM) i5-1235U,,,,,7.692127227783203,machine,N,1.0,0.0
5+
2025-11-15T16:05:41,codecarbon,685c527f-27ef-47b7-9955-a38ea34424e8,5b0fa12a-3dd7-45bb-9766-cc326314d9f1,23.700261899997713,0.0014245466564409932,6.010678964020776e-05,42.5,0.0,10.0,0.002022092715903293,0.0,0.0004757709861110521,0.002497863702014345,0.0,Egypt,EGY,,,,Windows-11-10.0.26100-SP0,3.13.5,3.0.8,12,12th Gen Intel(R) Core(TM) i5-1235U,,,,,7.692127227783203,machine,N,1.0,0.0
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
task_name,timestamp,project_name,run_id,duration,emissions,emissions_rate,cpu_power,gpu_power,ram_power,cpu_energy,gpu_energy,ram_energy,energy_consumed,water_consumed,country_name,country_iso_code,region,cloud_provider,cloud_region,os,python_version,codecarbon_version,cpu_count,cpu_model,gpu_count,gpu_model,longitude,latitude,ram_total_size,tracking_mode,on_cloud
2+
RAG Query,2025-11-15T15:47:13,codecarbon,27c11b81-b7a7-47c9-ab82-9ae317559fe9,42.43775189999724,0.00035304605540907173,8.316975773721854e-06,42.5,0.0,10.0,0.0005011351056248814,0.0,0.00011791160861111065,0.0006190467142359921,0.0,Egypt,EGY,,,,Windows-11-10.0.26100-SP0,3.13.5,3.0.8,12,12th Gen Intel(R) Core(TM) i5-1235U,,,,,7.692127227783203,machine,N

0 commit comments

Comments
 (0)