PPO
Proximal Policy Optimization (PPO) training algorithm for MLIR RL.
This module implements the core PPO training loop including trajectory collection, policy updates, value function updates, and benchmark evaluation. It manages the interaction between the RL environment and the neural network models.
collect_trajectory(data, model, step)
Collect a trajectory using the model and the environment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Benchmarks
|
The benchmarks dataset. |
required |
model
|
HiearchyModel
|
The model to use. |
required |
step
|
int
|
The current step of the main loop. |
required |
Returns:
| Type | Description |
|---|---|
TrajectoryData
|
The collected trajectory. |
Source code in mlir_rl_artifact/ppo.py
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 | |
ppo_update(trajectory, model, optimizer)
Update the policy and value models using PPO algorithm.
Performs PPO training on the collected trajectory data by computing policy loss, value loss, and entropy bonus, then updating model parameters via backpropagation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trajectory
|
TrajectoryData
|
The trajectory data collected from environment. |
required |
model
|
HiearchyModel
|
The model to update. |
required |
optimizer
|
Optimizer
|
The optimizer for model parameters. |
required |
Source code in mlir_rl_artifact/ppo.py
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 | |
value_update(trajectory, model, optimizer)
Update the value function model using trajectory data.
Trains the value model to predict state values by minimizing MSE loss between predicted and computed returns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trajectory
|
TrajectoryData
|
The trajectory data with returns computed. |
required |
model
|
HiearchyModel
|
The hierarchical model to update. |
required |
optimizer
|
Optimizer
|
The optimizer for value model parameters. |
required |
Source code in mlir_rl_artifact/ppo.py
evaluate_benchmarks(model, data)
Evaluate the model on all benchmarks and measure optimization results.
Runs the trained model in greedy mode on all benchmarks, applies optimizations, and measures the resulting execution times and speedups.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
HiearchyModel
|
The trained model to evaluate. |
required |
data
|
Benchmarks
|
The benchmark dataset to evaluate on. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, int]
|
Dictionary mapping benchmark names to execution times (in nanoseconds). |
dict[str, float]
|
Dictionary mapping benchmark names to speedup factors. |
Source code in mlir_rl_artifact/ppo.py
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 | |
__execute_states(state, exec_data_file, benchs, main_exec_data)
Execute a benchmark with the transformation sequence stored in state.
Worker function for parallel execution. Initializes environment, applies transformations, and measures execution results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
OperationState
|
The operation state containing transformation history. |
required |
exec_data_file
|
str
|
Path to the execution cache file. |
required |
benchs
|
Benchmarks
|
The benchmark dataset. |
required |
main_exec_data
|
dict[str, dict[str, int]] | None
|
Pre-computed execution data. |
required |
Returns:
| Type | Description |
|---|---|
list[float]
|
List of rewards for each action in the sequence. |
float
|
Speedup factor (ratio of original to optimized time). |
int | None
|
Execution time in nanoseconds (None if execution failed). |
bool
|
Cache miss flag (False if result was cached). |
float
|
Worker execution time in seconds. |