File size: 4,486 Bytes
5283cf1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# 🚀 QUICK START - 5 EASY STEPS

## ✅ SERVER IS ALREADY RUNNING!

Your FastAPI server is **currently active** at:
```
http://localhost:8000
```

---

## 📋 STEP-BY-STEP RUN GUIDE

### STEP 1: Open Terminal
```powershell
# Open PowerShell or Command Prompt
# Navigate to project directory
cd "d:\Projects\Pytorch x hugging face\he_demo"
```

### STEP 2: Start Virtual Environment (Optional)
```powershell
# Activate Python virtual environment
.venv\Scripts\Activate.ps1
```

### STEP 3: Run the Server
```powershell
# Start FastAPI server with uv
uv run server
```

**Expected Output:**
```
INFO:     Started server process [pid]
INFO:     Application startup complete.
INFO:     Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)
```

### STEP 4: Verify Server is Running (New Terminal)
```powershell
# In a new terminal, test the API
curl http://localhost:8000/graders

# Or with PowerShell
Invoke-WebRequest -Uri "http://localhost:8000/graders" -UseBasicParsing
```

**Expected Response:**
```json
{
  "graders": {...},
  "total_graders": 5,
  "grader_names": [...]
}
```

### STEP 5: Run Validation Tests
```powershell
# Test environment and graders
python validate.py

# Or comprehensive tests
python validate_comprehensive.py
```

**Expected Output:**
```
✅ Grader count requirement met (>= 3)
✅ All validation tests passed
✅ 5 graders WORKING
```

---

## 🧪 TEST COMMANDS (While Server Running)

### Test 1: Check All Graders
```powershell
curl http://localhost:8000/graders
```

### Test 2: Get Specific Grader
```powershell
curl "http://localhost:8000/graders/balanced_optimization"
```

### Test 3: Get Grader Info
```powershell
curl http://localhost:8000/graders/info
```

### Test 4: Reset Environment
```powershell
curl -X POST http://localhost:8000/reset `
  -H "Content-Type: application/json" `
  -d '{}'
```

### Test 5: Execute Action
```powershell
curl -X POST http://localhost:8000/step `
  -H "Content-Type: application/json" `
  -d '{"action_type": "reduce_ram", "intensity": 0.8}'
```

---

## 🎓 TRAINING & INFERENCE

### Run Training Script
```powershell
python train_agent.py
```
- Trains RL agent on environment
- Evaluates with graders
- Saves model as `energy_optimization_ppo.zip`

### Run Inference Script
```powershell
# Set environment variables first
$env:ENERGY_TASK = "balanced_optimization"
$env:HF_TOKEN = "your_token"
$env:MODEL_NAME = "Qwen/Qwen2.5-72B-Instruct"

# Then run
python -m he_demo.inference
```

---

## 🐳 RUN WITH DOCKER (Alternative)

### Build Docker Image
```powershell
docker build -t energy-optimization-env .
```

### Run Docker Container
```powershell
# Port 8000 on your machine maps to 8000 in container
docker run -p 8000:8000 he_demo:latest

# Or with interactive terminal
docker run -it -p 8000:8000 he_demo:latest
```

---

## ⏹️ STOP THE SERVER

```powershell
# In the terminal running the server:
Press CTRL+C

# Or if running Docker:
docker stop <container_id>
```

---

## 📊 VERIFY EVERYTHING WORKS

Run this quick verification:
```powershell
# 1. Check server status
curl http://localhost:8000/graders

# 2. Run validation
python validate.py

# 3. Check all graders
python validate_comprehensive.py
```

All three should ✅ PASS

---

## 🎯 WHAT'S RUNNING

| Component | Status | Port | Command |
|-----------|--------|------|---------|
| **FastAPI Server** | ✅ RUNNING | 8000 | `uv run server` |
| **5 Graders** | ✅ ACTIVE | 8000/graders | Built-in |
| **WebSocket** | ✅ READY | 8000/ws | Real-time updates |
| **Validation** | ✅ READY | N/A | `python validate.py` |

---

## 🔗 IMPORTANT LINKS

- **Local Server**: http://localhost:8000
- **GitHub Repo**: https://github.com/Sushruth-21/Energy-and-Memory-Ram-Optimization
- **HF Space**: https://sushruth21-energy-optimization-space.hf.space
- **Complete Guide**: See RUN_INSTRUCTIONS.md

---

## ✅ TROUBLESHOOTING

### Port 8000 already in use?
```powershell
# Find process using port
netstat -ano | findstr :8000
# Kill process
taskkill /PID <pid> /F
```

### Module not found error?
```powershell
# Reinstall dependencies
uv sync
```

### Docker image not building?
```powershell
# Use pre-built image
docker run -p 8000:8000 he_demo:latest
```

---

## 🎉 YOU'RE READY!

1. ✅ Server is running
2. ✅ 5 Graders are working
3. ✅ API is responding
4. ✅ Ready to submit to hackathon

**Next: Run validation tests and submit!**

---

**Current Server Status**: 🟢 **RUNNING ON http://localhost:8000**