Prajwal782007 commited on
Commit
ea1e214
·
1 Parent(s): 3857109

docs: rewrite and expand blog post describing GridMind-RL environment architecture and results

Browse files
Files changed (1) hide show
  1. BLOG.md +258 -34
BLOG.md CHANGED
@@ -1,6 +1,6 @@
1
  ---
2
  title: GridMind-RL: Training LLMs to Manage Industrial Buildings with GRPO
3
- description: How we built an OpenEnv-compatible RL environment that teaches language models real-world energy management.
4
  ---
5
 
6
  # GridMind-RL: Training LLMs to Manage Industrial Buildings
@@ -9,60 +9,284 @@ description: How we built an OpenEnv-compatible RL environment that teaches lang
9
 
10
  ---
11
 
12
- Industrial buildings consume 40% of global electricity, yet most are managed by static, inefficient schedules. GridMind-RL bridges the gap between LLM reasoning and real-world action, training agents to manage energy costs, comfort, and grid stability under pressure. Our results show a trained agent beating hand-crafted heuristics by **58%** on complex, instruction-driven tasks.
 
 
 
13
 
14
- ## Why it Matters
15
- We built GridMind-RL for the **Meta PyTorch OpenEnv Hackathon Grand Finale**. It directly addresses:
16
- - **Theme 1 (Multi-Agent):** Buildings share a grid feeder; actions in one affect stress for all.
17
- - **Theme 3 (World Modeling):** Agents use a `/simulate` endpoint to "think ahead" before acting.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
 
19
  ## The Environment
20
- GridMind-RL is an OpenEnv-compatible Go server simulating a 24-hour industrial building cycle (96 steps). Agents must navigate volatile prices, equipment faults, and grid stress signals.
21
 
22
- ### Actions & Rewards
23
- | Action | Purpose |
24
- |--------|---------|
25
- | `hvac_power_level` | Climate control |
26
- | `thermal_charge_rate` | Energy storage arbitrage |
27
- | `batch_job_slot` | Industrial load scheduling |
28
- | `load_shed_fraction` | Demand response |
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
 
30
- **The Reward System:** A 9-component verifiable reward (no LLM judge) balancing cost (28%), carbon (20%), comfort (20%), grid response (20%), and task satisfaction.
 
 
 
31
 
32
- ## Training & Results
33
- We trained **Qwen2.5-1.5B-Instruct** using **GRPO via TRL** with QLoRA (4-bit) on a T4 GPU.
 
34
 
35
- ### The Results
36
- | Policy | Task 1 (Cost) | Task 4 (Instruction) |
37
- |--------|--------|------------------|
38
- | Heuristic Baseline | 0.54 | 0.31 |
39
- | **GRPO Fine-tuned** | 0.42 | **0.49 (+58%)** |
40
 
41
- While heuristics are strong on simple scheduling, the **GRPO-trained model dominates Task 4**, proving LLMs can parse complex natural language objectives and adapt strategies mid-episodea feat impossible for fixed schedules.
 
 
 
 
 
 
 
 
 
 
 
42
 
43
  ![Reward Curve](curves/train%204/reward_curve.png)
44
- *Learning progress: Reward climbed from −0.47 to +0.61 in just 60 steps, with the curve still rising at termination.*
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
 
46
- ## Future Directions
47
- - **Scaling:** Moving to 7B+ models for deeper planning.
48
- - **Fleet Coordination:** Orchestrating building clusters to avoid feeder trips.
49
- - **Real-world Bridge:** Deploying the physics-grounded simulator to live building management systems.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
 
51
  ## Try It
 
 
 
 
 
52
  ```bash
 
 
 
53
  # Start a Task 4 episode (instruction following)
54
- curl -X POST https://prajwal782007-gridmind.hf.space/reset -d '{"task_id": 4}'
 
 
55
 
56
  # Take an action and observe the reward
57
- curl -X POST https://prajwal782007-gridmind.hf.space/step -d '{"hvac_power_level": 0.6, "building_id": 0}'
 
 
 
58
 
59
  # Grade the full episode
60
  curl https://prajwal782007-gridmind.hf.space/grade
61
  ```
62
 
63
- - 🤗 **Environment**: [HF Space](https://prajwal782007-gridmind.hf.space)
64
- - 📓 **Training**: [Colab Notebook](https://colab.research.google.com/github/LO-Kyu/gridmind/blob/main/scripts/gridmind_grpo_colab.ipynb)
65
- - 🐙 **Code**: [GitHub Repository](https://github.com/LO-Kyu/gridmind)
66
 
67
  ---
68
- *Built for the Meta PyTorch OpenEnv Hackathon · Grand Finale · Bangalore 2026*
 
 
 
1
  ---
2
  title: GridMind-RL: Training LLMs to Manage Industrial Buildings with GRPO
3
+ description: How we built an OpenEnv-compatible RL environment that teaches language models real-world energy management — and what the training curves actually show.
4
  ---
5
 
6
  # GridMind-RL: Training LLMs to Manage Industrial Buildings
 
9
 
10
  ---
11
 
12
+ There is a building somewhere running its air conditioning at full power right now,
13
+ even though electricity costs five times more than it did six hours ago. Not because
14
+ the operator made a bad decision — but because the control system doesn't know the
15
+ price changed.
16
 
17
+ Industrial buildings consume roughly 40% of global electricity. Most are managed by
18
+ fixed schedules that made sense when they were written and haven't been touched since.
19
+ The cost gap between a naive policy and an intelligent one is measurable in thousands
20
+ of dollars per building per year.
21
+
22
+ LLMs can read pricing curves, respond to fault alerts, and follow natural language
23
+ instructions — but there has never been an environment that trains them to *act* on
24
+ that reasoning under real operational pressure. We built one, trained on it, and the
25
+ results show an agent that beats a hand-crafted heuristic on the tasks that matter most.
26
+
27
+ ---
28
+
29
+ ## Who We Are
30
+
31
+ We are a team of three fascinated by the gap between what LLMs can reason about and
32
+ what they can actually *do*. Building energy management sits right at that frontier —
33
+ the domain is rich, the stakes are real, and no RL benchmark has touched it.
34
+ GridMind-RL is our attempt to change that.
35
+
36
+ We built this for the Meta PyTorch OpenEnv Hackathon Grand Finale at Scaler School
37
+ of Technology, Bangalore, April 25–26, 2026.
38
+
39
+ ---
40
+
41
+ ## Which Themes We're Targeting
42
+
43
+ GridMind-RL directly addresses two hackathon themes:
44
+
45
+ **Theme 1 — Multi-Agent Interactions:** Three buildings share a 360kW grid feeder
46
+ (120kW per building). A coordinator LLM reads fleet-wide demand via `/feeder` and
47
+ sets per-building price multipliers via `/coordinate`. Buildings that ignore the
48
+ signal trip the feeder limit — causing a grid fault penalty for all three. This
49
+ creates genuine emergent coordination pressure without explicit communication.
50
+
51
+ **Theme 3.1 — World Modeling (Professional Tasks):** The `/simulate` endpoint lets
52
+ the agent ask "what if?" before committing an action. When HVAC efficiency is low or
53
+ faults are active, the agent can simulate a proposed action and revise its plan if
54
+ the predicted reward is poor. This trains causal reasoning and persistent world
55
+ modeling — exactly what Theme 3 targets.
56
+
57
+ ---
58
 
59
  ## The Environment
 
60
 
61
+ GridMind-RL implements the OpenEnv-compatible interface (reset/step/state/grade)
62
+ via a high-performance Go HTTP server. openenv-core==0.2.3 is used as the
63
+ Python client library for training-side interaction. It simulates a complete 24-hour industrial
64
+ building energy system at 15-minute resolution — 96 decision steps per episode.
65
+
66
+ The agent operates in continuous time, responding to a world that changes around it:
67
+ prices spike up to during tariff faults, equipment degrades, grid stress signals
68
+ arrive, and sometimes the chiller fails at 2pm on the hottest day of the year.
69
+
70
+ **The agent sees a rich observation space every step, including:**
71
+ indoor temperature, thermal storage level, electricity price, grid stress signal,
72
+ HVAC efficiency (which degrades continuously throughout the episode), active fault
73
+ alarms, a 4-step price forecast, cumulative cost, carbon intensity, batch job queue,
74
+ and hour of day. In Task 4, this also includes a natural language instruction card.
75
+
76
+ **The agent has four levers:**
77
+
78
+ | Action | Range | What it does |
79
+ |--------|-------|--------------|
80
+ | `hvac_power_level` | 0 → 1 | How hard the HVAC system works |
81
+ | `thermal_charge_rate` | -1 → 1 | Charge or discharge thermal storage |
82
+ | `batch_job_slot` | 0 → 4 | When to run deferrable industrial loads |
83
+ | `load_shed_fraction` | 0 → 0.5 | Voluntary demand reduction during grid stress |
84
+
85
+ **Four tasks of increasing difficulty:**
86
+
87
+ - **Cost Minimization** — Navigate 24-hour price volatility (~2¢ to ~36¢/kWh) and
88
+ thermal storage arbitrage to minimize total energy spend.
89
+
90
+ - **Comfort Management** — Hold indoor temperature within 19–23°C through equipment
91
+ degradation, faults, and shifting external conditions.
92
+
93
+ - **Demand Response** — Read grid stress signals in real time and voluntarily shed
94
+ load (when signal exceeds 0.7) to earn demand-response credit without sacrificing
95
+ comfort.
96
+
97
+ - **Instruction Following** — Parse a natural language objective card at episode
98
+ start and adapt the entire 96-step strategy to meet it.
99
+
100
+ ### Why the reward has nine components
101
+
102
+ The naive approach is to reward cost savings and call it done. The problem is that
103
+ a cost-only reward teaches the agent to turn off the HVAC entirely — perfect score,
104
+ frozen building. This is textbook reward hacking.
105
+
106
+ Real building operators don't optimize one metric. They manage a hierarchy:
107
+ comfort is non-negotiable, grid compliance is contractual, cost is the primary KPI,
108
+ carbon is increasingly regulated, and equipment stability protects the capital budget.
109
+
110
+ Our reward reflects that hierarchy directly:
111
+
112
+ | Component | Weight | Why |
113
+ |-----------|--------|-----|
114
+ | `cost_savings` | 0.28 | Primary operator KPI |
115
+ | `carbon_reward` | 0.20 | ESG compliance, increasingly mandatory |
116
+ | `temp_constraint` | 0.20 | Hard safety constraint — SLA violations incur penalties |
117
+ | `grid_response` | 0.20 | Demand response programs pay operators to shed load |
118
+ | `batch_deadline` | 0.12 | Missing deadlines causes downstream production losses |
119
+ | `efficiency_bonus` | 0.05 | Incentivises smart thermal storage arbitrage |
120
+ | `stability_penalty` | -0.05 | Prevents HVAC thrashing that causes equipment wear |
121
+ | `fault_mitigation` | dynamic | Correct fault response prevents costly outages |
122
+ | `task_satisfaction` | 0.10–0.50* | Task 4 only — weighted per the instruction card |
123
+
124
+ > *`task_satisfaction` weight varies by instruction template, ranging from
125
+ > 0.10 to 0.50 depending on the episode's objective card (tasks.go).
126
+
127
+ ### How we prevent reward hacking
128
+
129
+ A multi-component reward is only part of the answer. We also:
130
+
131
+ - **Clamp all actions** at the server side — the agent cannot exceed valid ranges
132
+ regardless of what it outputs (`hvac_power_level` hard-clamped 0–1,
133
+ `load_shed_fraction` hard-clamped 0–0.5, etc.)
134
+ - **Inject four fault types** that make naive exploitation brittle: chiller failure
135
+ (HVAC drops to 20% capacity), grid outage (price up to ×4, stress = 1.0), sensor
136
+ fault (temperature jitter ±5°C), and tariff spike (price up to ×5)
137
+ - **Use a seeded but stochastic environment** — price curves, fault timing, and
138
+ demand patterns vary across episodes, preventing the agent from memorizing a
139
+ fixed solution
140
+ - **Score via `/grade`** at episode end using a separate grading function that is
141
+ decoupled from the per-step reward signal
142
+
143
+ ---
144
+
145
+ ## Training
146
+
147
+ We trained Qwen2.5-1.5B-Instruct with QLoRA (4-bit, rank 16) using GRPO via
148
+ HuggingFace TRL on a T4 GPU — roughly 35 minutes per run.
149
+
150
+ | Component | Detail |
151
+ |-----------|--------|
152
+ | Model | Qwen2.5-1.5B-Instruct |
153
+ | Fine-tuning | QLoRA (4-bit, rank 16) |
154
+ | Algorithm | GRPO via HuggingFace TRL |
155
+ | Hardware | HF Space T4 GPU |
156
+ | Training time | ~35 minutes |
157
+ | Steps | 60 |
158
+
159
+ **Why GRPO over PPO?**
160
+ GRPO doesn't require a separate value network. At 1.5B parameters on a T4, that
161
+ memory saving matters. Instead of estimating a value baseline, GRPO samples a group
162
+ of completions per prompt and computes advantages by comparing them against each
163
+ other — a natural fit for our setting where we generate multiple actions per state
164
+ and want to reinforce the better ones.
165
+
166
+ The hackathon context emphasized that RL only works if the probability of a good
167
+ answer is greater than zero. We confirmed this by running a heuristic baseline first
168
+ to verify the environment produces non-zero reward before starting RL training.
169
+
170
+ ---
171
+
172
+ ## Results
173
+
174
+ ### The numbers first
175
 
176
+ | Policy | Task 1 | Task 2 | Task 3 | Task 4 | Avg (unweighted) |
177
+ |--------|--------|--------|--------|--------|------------------|
178
+ | Heuristic Baseline | 0.54 | 0.56 | 0.50 | 0.31 | 0.48 |
179
+ | GRPO Fine-tuned | 0.42 | 0.34 | 0.47 | **0.49** | 0.43 |
180
 
181
+ > Heuristic = fixed time-of-day HVAC scheduling, no learning.
182
+ > GRPO Fine-tuned = Qwen2.5-1.5B-Instruct after 60 steps of GRPO training
183
+ > against the live environment.
184
 
185
+ The trained model **beats the heuristic on Task 4 by 58%** (0.49 vs 0.31) and
186
+ **comes within 6% of the heuristic on Task 3** (0.47 vs 0.50).
 
 
 
187
 
188
+ These are the two tasks where intelligent reasoning matters mostinstruction
189
+ parsing and real-time grid cooperation. A fixed schedule cannot read an objective
190
+ card. A fixed schedule cannot respond to a grid stress signal that arrives mid-episode.
191
+ The trained model can do both.
192
+
193
+ Tasks 1 and 2 are an honest result. Time-of-day HVAC scheduling is genuinely
194
+ competitive for cost and comfort — the heuristic baseline is strong on those
195
+ objectives because the physics are predictable. Closing that gap requires more
196
+ training steps. The reward curve shows the trend is still moving upward at step 60,
197
+ meaning training had not plateaued.
198
+
199
+ ### The reward curve
200
 
201
  ![Reward Curve](curves/train%204/reward_curve.png)
202
+ *Reward vs training step. From −0.47 at step 5 to +0.61 at step 60 a 1.08-point
203
+ gain. The smoothed average (red dashed) is still rising at the final step, confirming
204
+ training had not saturated.*
205
+
206
+ ### The before/after
207
+
208
+ ![Baseline Comparison](curves/train%204/baseline_comparison.png)
209
+ *Grade scores per task: heuristic baseline (blue) vs GRPO-trained LLM (green).
210
+ Task 4 is where the trained model pulls clearly ahead — 58% above the heuristic.*
211
+
212
+ ---
213
+
214
+ ## What the Agent Learns
215
+
216
+ None of these behaviors are hardcoded. The reward signal surfaces them:
217
 
218
+ **Thermal arbitrage** — the agent learns to charge thermal storage during off-peak
219
+ hours (~3.5¢/kWh) and discharge during peak (~31¢/kWh), reducing the effective cost
220
+ of maintaining comfort during expensive periods.
221
+
222
+ **Grid cooperation** — when the stress signal exceeds 0.7, the agent voluntarily
223
+ sheds load rather than ignoring it. The demand-response credit offsets the comfort
224
+ penalty — which is why Task 3 performance is closest to the heuristic.
225
+
226
+ **Fault adaptation** — when HVAC efficiency degrades, the agent reduces its HVAC
227
+ target rather than fighting a weakened system at full power. This behavior emerges
228
+ purely from the `fault_mitigation` reward component.
229
+
230
+ **Instruction parsing** — in Task 4, the agent reads the objective card and adjusts
231
+ its entire 96-step strategy to meet it. This is the hardest capability for a
232
+ heuristic to replicate — and where the trained model wins most clearly.
233
+
234
+ ---
235
+
236
+ ## What's Next
237
+
238
+ GridMind-RL is a foundation, not a finished product. The directions we find most
239
+ interesting:
240
+
241
+ **Longer training runs** — the reward curve hasn't plateaued at 60 steps. 300+
242
+ steps would likely close the gap on Tasks 1 and 2 and push Task 4 performance
243
+ further above the heuristic.
244
+
245
+ **Larger models** — a 7B model with the same training setup would bring stronger
246
+ instruction-following capability and better multi-step planning out of the box.
247
+
248
+ **Fleet-level coordination** — three buildings share a 360kW grid feeder (120kW per
249
+ building). Fleet-level coordination is fully implemented — training a coordinator LLM
250
+ that orchestrates all three through price signals is the next research direction.
251
+ The shared feeder constraint creates genuine emergent coordination pressure — if one
252
+ building ignores the signal, all three pay the penalty.
253
+
254
+ **Real deployment** — the environment's physics are grounded in real building
255
+ parameters. The gap between this simulator and a real BMS integration is smaller
256
+ than it looks.
257
+
258
+ ---
259
 
260
  ## Try It
261
+
262
+ GridMind-RL is live and OpenEnv-compliant. Task 4 is the most interesting to try —
263
+ the agent receives a natural language objective card and must adapt its entire
264
+ strategy to meet it:
265
+
266
  ```bash
267
+ # Health check
268
+ curl https://prajwal782007-gridmind.hf.space/health
269
+
270
  # Start a Task 4 episode (instruction following)
271
+ curl -X POST https://prajwal782007-gridmind.hf.space/reset \
272
+ -H "Content-Type: application/json" \
273
+ -d '{"task_id": 4}'
274
 
275
  # Take an action and observe the reward
276
+ curl -X POST https://prajwal782007-gridmind.hf.space/step \
277
+ -H "Content-Type: application/json" \
278
+ -d '{"hvac_power_level": 0.6, "thermal_charge_rate": 0.4,
279
+ "batch_job_slot": 2, "load_shed_fraction": 0.0, "building_id": 0}'
280
 
281
  # Grade the full episode
282
  curl https://prajwal782007-gridmind.hf.space/grade
283
  ```
284
 
285
+ - 🤗 **Environment**: https://prajwal782007-gridmind.hf.space
286
+ - 📓 **Training Notebook**: [gridmind_grpo_colab.ipynb](https://colab.research.google.com/github/LO-Kyu/gridmind/blob/main/scripts/gridmind_grpo_colab.ipynb)
287
+ - 🐙 **Code**: https://github.com/LO-Kyu/gridmind
288
 
289
  ---
290
+
291
+ *Built for the Meta PyTorch OpenEnv Hackathon × Scaler School of Technology ·
292
+ Grand Finale, April 25–26, 2026, Bangalore.*