Spaces:
Running
Running
Merge branch 'main' of https://github.com/LO-Kyu/gridmind
Browse files20 unmodified lines2122232425262710 unmodified lines38394041424344454647484950515253545556575859606112 unmodified lines74757677787980813 unmodified lines85868788899091929394956 unmodified lines10210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114243 unmodified lines18618718818919019119219319419519619719819920020120220326 unmodified lines2302312322332342352362372382392405 unmodified lines2462472482492502514 unmodified lines2562572582592602612622632642653 unmodified lines26927027127227327427527627720 unmodified lines## Why This Environment Is NovelMost RL environments for LLMs are grid-worlds or toy games. GridMind-RL simulates a **real industrial problem** — building energy management — where agents must juggle stochastic electricity prices, multi-objective constraints, equipment faults, and natural language operating objectives. An LLM that learns to manage a building under these conditions has a genuinely useful skill, not just a high game score.## Live Demo10 unmodified lines---## ProblemIndustrial buildings consume ~40% of global electricity, yet most still use naive "always-on" HVAC policies. The capability gap is clear: **LLMs can understand complex pricing curves, natural language instructions, and fault alerts—but no environment exists to train them to manage buildings.**GridMind-RL closes this gap by simulating a complete building energy system where agents must:- Navigate 24-hour price volatility (off-peak vs peak: 4¢ to 32¢/kWh)- Maintain comfort (19-23°C) while minimizing cost- Respond to grid stress emergencies- Handle equipment faults (chiller failure, sensor malfunction, grid outages)- Parse and follow natural language objective cards---## Environment| | Description ||---|-------------|| **Observation** | 11 fields: temperature, storage, price, stress, carbon, faults, HVAC efficiency || **Actions** | HVAC level (0-1), thermal charge (-1 to 1), batch slot (0-4), load shed (0-0.5) || **Reward** | 9-component weighted sum: cost, temperature, grid, deadline, efficiency, stability, carbon, instruction, fault_mitigation || **Episode** | 96 steps = 24 simulated hours @ 15-min resolution |12 unmodified lines| `batch_deadline` | 0.12 | Production continuity — missing batch deadlines causes downstream losses || `efficiency_bonus` | 0.05 | Storage arbitrage — incentivises smart charge/discharge timing || `stability_penalty` | -0.05 | Anti-cycling — prevents HVAC thrashing that causes equipment wear || `fault_mitigation` | 0.05 | Emergency response — correct fault handling prevents costly outages || `instruction_reward` | 0.50* | Task 4 only — weighted per the episode's instruction card |> *Task 4 instruction reward weight comes from the sampled instruction card, not a fixed value.3 unmodified lines|-------|------|-------------|| indoor_temperature | float | °C || thermal_storage_level | float | 0-1 (0=empty, 1=full) || current_price | float | $/kWh || grid_stress_signal | float | 0-1 (>0.7 = critical) || hvac_efficiency | float | 1.0 → degrades to 0.5 over episode || active_faults | string[] | Active fault alarm strings || instruction_card | object | Task 4 objective only |### Action Fields6 unmodified lines---## Five Tracks### Track 1: Multi-Agent InteractionsA single oversight LLM coordinates multiple buildings through price signals. The coordinator reads `/feeder` to see fleet-wide demand, then sets per-building price multipliers via `/coordinate` to orchestrate behavior.### Track 2: Long-Horizon Planning & Instruction FollowingTask 4 presents a natural language objective card like "Keep total energy cost under $2.50 while maintaining 19-23°C". Agents must plan across all 96 steps—not greedy per-step control.### Track 3: World ModelingThe `/simulate` endpoint lets agents ask "what if?" before acting. When HVAC efficiency is low or faults are active, the agent simulates the proposed action and revises if the predicted reward is poor.### Track 4: Fault Handling (Wild Card)Four fault types inject unpredictability:- **Chiller failure**: HVAC drops to 20% capacity- **Grid outage**: Price ×3, stress = 1.0- **Sensor fault**: Temperature readings jitter ±5°C- **Tariff spike**: Emergency 4× price surge### Track 5: HVAC DegradationReal HVAC systems degrade over time. Efficiency starts at 1.0 and drops ~0.1% per step. The agent must account for declining capacity—a hidden state requiring inference.---## Results*Episode grade scores vs training step. Heuristic baseline (red) vs GRPO fine-tuned LLM (teal). Higher = better energy management.*| Policy | Task 1 | Task 2 | Task 3 | Task 4 ||--------|--------|--------|--------|--------|| Heuristic Baseline | 0.506 | 0.459 | 0.600 | 0.492 || Zero-shot LLM | 0.715 | 0.645 | 0.610 | 0.582 || GRPO Fine-tuned LLM | TBD | TBD | TBD | TBD |> Scores are episode grade scores (0.0–1.0, clamped open interval). Heuristic = fixed policy with no learning. Zero-shot = pretrained Qwen2.5-7B-Instruct. Fine-tuned = GRPO-trained on GridMind-RL environment.---43 unmodified lines---## Self-Improvement: Curriculum LearningThe `--curriculum` flag enables automatic task progression:- Agent starts on Task 1 (easy)- After 5 episodes with average reward ≥ 0.55, advances to Task 2- After 5 episodes with average reward ≥ 0.50, advances to Task 3- After 5 episodes with average reward ≥ 0.45, advances to Task 4This directly targets the Self-Improvement hackathon theme.---## Architecture```26 unmodified lines| GET | /state | Get current state || GET | /grade | Grade episode (0.0-1.0 score) || GET | /tasks | Available tasks || GET | /metrics | System metrics || GET | /replay | Episode history || GET | /feeder | Aggregate fleet state || POST | /coordinate | Set price multipliers || POST | /simulate | World model prediction |---5 unmodified lines├── inference.py # Agent entry point (LLM + heuristic)├── openenv.yaml # OpenEnv spec├── Dockerfile # Container build├── env/│ ├── environment.go # Physics simulation│ ├── models.go # Data models4 unmodified lines│ ├── train_unsloth.py # GRPO training│ ├── plot_results.py # Training curve visualizer│ ├── multi_building_demo.py # Fleet AI demo│ └── run_baseline.sh # Baseline scorer├── dashboard/│ ├── server.py # Web server (port 7861)│ └── static/ # Frontend assets├── results/ # Training outputs (generated)└── README.md```3 unmodified lines## Links- 🤗 HuggingFace Space: [GridMind-RL](https://prajwal782007-gridmind.hf.space)- 📝 Blog: [Read the blog post](./HF_BLOG_POST.md)- 📓 Colab Notebook: [gridmind_grpo_colab.ipynb](https://colab.research.google.com/github/LO-Kyu/gridmind/blob/main/scripts/gridmind_grpo_colab.ipynb)- 🐙 Code Repository: [GitHub](https://github.com/LO-Kyu/gridmind)---20 unmodified lines2122232425262710 unmodified lines383940414243444546474812 unmodified lines61626364656667683 unmodified lines72737475767778798081828384858687886 unmodified lines959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914043 unmodified lines18418518618718818926 unmodified lines2162172182192202212222232242252262272282292305 unmodified lines2362372382392402412422434 unmodified lines2482492502512522532542552562572582592602613 unmodified lines26526626726826927027127227320 unmodified lines## Why This Environment Is NovelIndustrial buildings consume ~40% of global electricity yet rely on naive "always-on" HVAC policies. LLMs can reason about pricing curves, fault alerts, and natural language objectives—but no environment trains them for this. GridMind-RL simulates a full 24-hour building energy system with stochastic electricity prices, equipment faults, and instruction cards, creating a genuinely challenging domain where learned policies translate to real operational value.## Live Demo10 unmodified lines---## Environment| | Description ||---|-------------|| **Observation** | 13 fields: temperature, storage, price, stress, carbon, faults, HVAC efficiency, process demand, batch queue, price forecast || **Actions** | HVAC level (0-1), thermal charge (-1 to 1), batch slot (0-4), load shed (0-0.5) || **Reward** | 9-component weighted sum: cost, temperature, grid, deadline, efficiency, stability, carbon, instruction, fault_mitigation || **Episode** | 96 steps = 24 simulated hours @ 15-min resolution |12 unmodified lines| `batch_deadline` | 0.12 | Production continuity — missing batch deadlines causes downstream losses || `efficiency_bonus` | 0.05 | Storage arbitrage — incentivises smart charge/discharge timing || `stability_penalty` | -0.05 | Anti-cycling — prevents HVAC thrashing that causes equipment wear || `task_satisfaction` | 0.50* | Task 4 only — weighted per the episode's instruction card || `fault_mitigation` | dynamic | Emergency response — computed based on fault type and response |> *Task 4 instruction reward weight comes from the sampled instruction card, not a fixed value.3 unmodified lines|-------|------|-------------|| indoor_temperature | float | °C || thermal_storage_level | float | 0-1 (0=empty, 1=full) || process_demand | float | kW current industrial power demand || current_price | float | $/kWh || grid_stress_signal | float | 0-1 (>0.7 = critical) || carbon_intensity | float | gCO2/kWh || hour_of_day | int | 0-23 || batch_queue | int[] | pending job deadline slots || cumulative_cost | float | $ total incurred this episode || hvac_efficiency | float | 1.0 → degrades to 0.5 over episode || active_faults | string[] | Active fault alarm strings || instruction_card | object | Task 4 objective only || price_forecast | float[] | 4-step upcoming price preview |### Action Fields6 unmodified lines---## Core Capabilities### Multi-Agent CoordinationA single oversight LLM coordinates multiple buildings through price signals. The coordinator reads `/feeder` to see fleet-wide demand, then sets per-building price multipliers via `/coordinate` to orchestrate behavior.### Long-Horizon Instruction FollowingTask 4 presents a natural language objective card like "Keep total energy cost under $2.50 while maintaining 19-23°C". Agents must plan across all 96 steps—not greedy per-step control.These two capabilities map directly to Theme 1 and Theme 3 of the OpenEnv Hackathon.---## Results### What the Agent LearnsA naive heuristic runs HVAC at fixed levels based on time-of-day. After GRPO training on GridMind-RL, the agent learns to charge thermal storage during off-peak hours (4¢/kWh) and discharge during peak (32¢/kWh), voluntarily shed load during grid stress signals above 0.7, and adjust HVAC intensity as efficiency degrades over the episode. None of these behaviors are hardcoded — the agent discovers them through the reward signal alone.| Policy | Task 1 | Task 2 | Task 3 | Task 4 ||--------|--------|--------|--------|--------|| Heuristic Baseline | 0.494 | 0.471 | 0.748 | 0.478 || Zero-shot LLM | 0.715 | 0.645 | 0.610 | 0.582 || GRPO Fine-tuned LLM | — | — | — | — |> *GRPO fine-tuned scores updating after full training run on T4 GPU.> Training plots below show live progress from the actual run.**Reward vs training step. Blue = per-step reward, red dashed = smoothed average.**Training loss decreasing over steps — confirms the model is updating.**Grade scores per task: heuristic baseline vs GRPO-trained LLM.*> Scores are episode grade scores (0.0–1.0, clamped open interval). Heuristic = fixed policy with no learning. Zero-shot = Qwen2.5-1.5B-Instruct prompted with task description, no fine-tuning, evaluated over 1 episode per task. Fine-tuned = GRPO-trained on GridMind-RL environment.> 🔄 **Live update:** GRPO fine-tuned scores will be filled in here immediately> after the final training run completes on the T4 GPU.---43 unmodified lines---## Architecture```26 unmodified lines| GET | /state | Get current state || GET | /grade | Grade episode (0.0-1.0 score) || GET | /tasks | Available tasks || GET | /metrics | Prometheus metrics || GET | /replay | Episode history || GET | /feeder | Aggregate fleet state || POST | /coordinate | Set price multipliers || POST | /simulate | World model prediction || POST | /coordinator/reset | Reset multi-building episode || POST | /coordinator/step | Step with per-building actions || GET | /info | OpenEnv metadata || GET | /ws | WebSocket endpoint |---5 unmodified lines├── inference.py # Agent entry point (LLM + heuristic)├── openenv.yaml # OpenEnv spec├── Dockerfile # Container build├── HF_BLOG_POST.md # Blog write-up├── baseline_scores.json # Heuristic baseline scores├── env/│ ├── environment.go # Physics simulation│ ├── models.go # Data models4 unmodified lines│ ├── train_unsloth.py # GRPO training│ ├── plot_results.py # Training curve visualizer│ ├── multi_building_demo.py # Fleet AI demo│ └── gridmind_grpo_colab.ipynb # Colab training notebook├── server/│ └── app.py # Python fallback server├── dashboard/│ ├── server.py # Web server (port 7861)│ └── static/ # Frontend assets├── curves/ # Training curves (train N/)│ └── train N/ # Per-run plots├── results/ # Training outputs (generated)└── README.md```3 unmodified lines## Links- 🤗 HuggingFace Space: [GridMind-RL](https://prajwal782007-gridmind.hf.space)- 📓 Training Notebook: [gridmind_grpo_colab.ipynb](https://colab.research.google.com/github/LO-Kyu/gridmind/blob/main/scripts/gridmind_grpo_colab.ipynb)- 📝 Blog Post: [Read the write-up](./HF_BLOG_POST.md)- 🐙 GitHub: [Code Repository](https://github.com/LO-Kyu/gridmind)---
README.md+50-54