Workflow
The Workflow class provides the core interface and functionality that all workflows inherit from.
rllm.workflows.workflow
Workflow
Bases: ABC
Source code in rllm/workflows/workflow.py
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 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 | |
__init__
__init__(rollout_engine: RolloutEngine, executor: ThreadPoolExecutor, timeout=1000000.0, gamma=0.0, reward_bonus_coeff=0.0, **kwargs)
Initialize the Workflow.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rollout_engine
|
RolloutEngine
|
The rollout engine to use. |
required |
executor
|
ThreadPoolExecutor
|
The executor to use. |
required |
timeout
|
The timeout for the workflow. |
1000000.0
|
|
gamma
|
The discount factor for the workflow. |
0.0
|
|
reward_bonus_coeff
|
The reward bonus coefficient for the workflow. |
0.0
|
|
**kwargs
|
Additional keyword arguments. |
{}
|
Source code in rllm/workflows/workflow.py
run
abstractmethod
async
Execute the workflow on a single task
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
dict
|
The task to execute. |
required |
uid
|
str
|
The unique identifier for the task. |
required |
**kwargs
|
Additional keyword arguments. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Episode |
Episode | None
|
The episode generated by the workflow. |
Source code in rllm/workflows/workflow.py
run_with_termination_handling
async
Wrapper method around workflow.run that handles termination events, errors, timeouts, and post-processing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
dict
|
The task to execute. |
required |
uid
|
str
|
The unique identifier for the task. |
required |
**kwargs
|
Additional keyword arguments. |
{}
|
Source code in rllm/workflows/workflow.py
commit
commit(name: str | None = None, agent: BaseAgent | None = None, trajectory: Trajectory | None = None, reset: bool = False) -> None
Commit a trajectory for training.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str | None
|
The name of the trajectory. |
None
|
agent
|
BaseAgent | None
|
The agent that generated the trajectory. |
None
|
trajectory
|
Trajectory | None
|
The trajectory to commit. |
None
|
reset
|
bool
|
Whether to reset the agent. |
False
|
Source code in rllm/workflows/workflow.py
collect_trajectories
Collect the trajectories from the workflow
Returns:
| Name | Type | Description |
|---|---|---|
Episode |
Episode
|
The episode generated by the workflow. |
Source code in rllm/workflows/workflow.py
compute_trajectory_reward
Compute the trajectory-level reward. Default: sum the step rewards
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trajectory
|
Trajectory
|
The trajectory to compute the reward for. |
required |
Source code in rllm/workflows/workflow.py
adjust_step_rewards
Adjust the step-level rewards. Supports reward shaping and discounting self.reward_bonus_coeff and self.gamma are 0.0, so no adjustments are made by default.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trajectory
|
Trajectory
|
The trajectory to adjust the rewards for. |
required |
Source code in rllm/workflows/workflow.py
assign_episode_correctness
Assign an episode-level correctness flag. Default: True if the sum of the trajectory rewards is strictly positive.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
episode
|
Episode
|
The episode to assign the correctness flag to. |
required |
Source code in rllm/workflows/workflow.py
collect_metrics
Collect metrics from the episode.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
episode
|
Episode
|
The episode to collect metrics from. |
required |
Source code in rllm/workflows/workflow.py
postprocess_episode
postprocess_episode(episode: Episode, termination_reason: TerminationReason = None, error: dict = None) -> Episode
Collect and process the trajectories
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
episode
|
Episode
|
The episode to postprocess. |
required |
termination_reason
|
TerminationReason
|
The termination reason for the episode. |
None
|
error
|
dict
|
The error details for the episode. |
None
|
Source code in rllm/workflows/workflow.py
reset
Reset the workflow
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
dict | None
|
The task to reset the workflow to. |
None
|
uid
|
str | None
|
The unique identifier for the task. |
None
|
Source code in rllm/workflows/workflow.py
is_multithread_safe
Check if the workflow is multithread safe
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the workflow is multithread safe, False otherwise. |
Source code in rllm/workflows/workflow.py
run_in_executor
async
Run a function in seperate thread pool executor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fn
|
The function to run. |
required | |
*args
|
The arguments to pass to the function. |
()
|
|
**kwargs
|
The keyword arguments to pass to the function. |
{}
|