Python API¶
The command-line interface is HarborRL's primary user surface. harborrl.config
explicitly declares its public exports. The additional symbols below are curated,
CPU-testable integration contracts used by adapters and tests; they may evolve with
the native contract version.
Configuration¶
MATH registry¶
harborrl.math_registry ¶
Explicit MATH component contracts and startup compatibility checks.
ModelSpec
dataclass
¶
Source code in harborrl/math_registry.py
AlgorithmSpec
dataclass
¶
Source code in harborrl/math_registry.py
TaskProviderSpec
dataclass
¶
HarnessSpec
dataclass
¶
Source code in harborrl/math_registry.py
MATHSelection
dataclass
¶
Source code in harborrl/math_registry.py
select_math ¶
Source code in harborrl/math_registry.py
validate_combination ¶
Source code in harborrl/math_registry.py
list_components ¶
Source code in harborrl/math_registry.py
Task providers¶
harborrl.tasks.provider.NativeTaskProvider ¶
Source code in harborrl/tasks/provider.py
harborrl.tasks.jsonl_provider.JsonlTaskProvider ¶
Source code in harborrl/tasks/jsonl_provider.py
Native trajectory contracts¶
harborrl.trajectories.native ¶
Strict, runtime-independent contracts for native trajectories (IR v2).
Identity
dataclass
¶
Source code in harborrl/trajectories/native.py
RewardProfile
dataclass
¶
Source code in harborrl/trajectories/native.py
digest ¶
read_json ¶
Source code in harborrl/trajectories/native.py
publish ¶
Publish once, idempotently; concurrent conflicting writers never overwrite.
Source code in harborrl/trajectories/native.py
validate_v2 ¶
Recompute eligibility; never trust a caller-supplied readiness flag.
Source code in harborrl/trajectories/native.py
assemble ¶
assemble(
identity,
trial_id,
turns,
seal,
receipt,
*,
termination="completed",
termination_evidence=None,
)
Source code in harborrl/trajectories/native.py
require_ready ¶
Source code in harborrl/trajectories/native.py
Training export contracts¶
harborrl.export.contract ¶
Backend-neutral schemas for Native IR v2 training export.
The schemas are immutable and dependency free on purpose: Slime, Torch, and Megatron types must stay inside a backend adapter so the same CPU-testable contract can serve future training backends.
TokenSpan
dataclass
¶
One policy turn expanded from a Native trajectory.
Source code in harborrl/export/contract.py
TrajectoryTrainingUnit
dataclass
¶
A complete trajectory with its group-normalized training semantics.
Source code in harborrl/export/contract.py
TrainingGroup
dataclass
¶
A complete prompt group of exactly group_size trajectories.
Source code in harborrl/export/contract.py
TrainingBatch
dataclass
¶
The only object a training backend adapter is allowed to consume.
Source code in harborrl/export/contract.py
harborrl.export.native ¶
Native IR v2 to backend-neutral TrainingBatch export (pure Python).
group_statistics ¶
Population mean/std and GRPO advantages for one complete group.
Source code in harborrl/export/native.py
export_training_batch ¶
export_training_batch(
ir_groups,
*,
group_size=None,
rollout_ids=None,
rollout_id_base=0,
epsilon=1e-06,
allow_synthetic=False,
) -> TrainingBatch
Validate complete Native IR groups and export immutable training units.
Source code in harborrl/export/native.py
harborrl.export.validate ¶
Fail-closed validation for backend-neutral training batches.
validate_token_span ¶
validate_token_span(span: TokenSpan)
Source code in harborrl/export/validate.py
validate_trajectory ¶
validate_trajectory(unit: TrajectoryTrainingUnit)
Source code in harborrl/export/validate.py
validate_group ¶
validate_group(group: TrainingGroup, *, epsilon=1e-06)
Source code in harborrl/export/validate.py
validate_batch ¶
validate_batch(batch: TrainingBatch, *, epsilon=1e-06)
Source code in harborrl/export/validate.py
batch_weight_sum ¶
batch_weight_sum(batch: TrainingBatch)
Sum of trajectory weights; each complete group contributes exactly one.
Source code in harborrl/export/validate.py
Rollout runtime¶
harborrl.rollout.runtime ¶
Extracted rollout core (P2): gateway, traces and complete groups.
This module owns rollout execution and must not import Slime or Ray: training
frameworks live in harborrl.backends.* adapters that build a
RolloutRuntimeConfig and hand over a tokenizer. Group semantics, worker
scheduling, retries and the RL_READY contract stay exactly as the embedded
pipeline enforced them.
RuntimeLifecycleError ¶
CleanupRequiredError ¶
CleanupAdmission ¶
Source code in harborrl/rollout/runtime.py
RolloutRuntimeConfig
dataclass
¶
Deployment-independent description of one run's rollout machinery.
Source code in harborrl/rollout/runtime.py
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 | |
environment ¶
Render the environment mapping this config was built from.
Source code in harborrl/rollout/runtime.py
RolloutRuntime ¶
One gateway, one trace registry and one rollout root per run.
Source code in harborrl/rollout/runtime.py
manifest_path ¶
Deterministic shared-storage path of one trajectory manifest.
Source code in harborrl/rollout/runtime.py
tokenizer_fingerprint ¶
Source code in harborrl/rollout/runtime.py
runtime
async
¶
Process-wide runtime cache for the embedded GPU-side rollout path.
Source code in harborrl/rollout/runtime.py
run_embedded ¶
Run successive synchronous rollout calls on one Python 3.10-compatible loop.
Source code in harborrl/rollout/runtime.py
publish_native_version ¶
Open the next admission epoch only after the complete pool is healthy.
Source code in harborrl/rollout/runtime.py
current_policy_version ¶
Publish and lock the version currently served by the rollout pool.
Source code in harborrl/rollout/runtime.py
close_runtime ¶
Drain embedded tasks, close the gateway, then release the owning loop.
Source code in harborrl/rollout/runtime.py
Deployment¶
harborrl.deployment.schema ¶
Deployment schema v1: machine roles and access, never training semantics.
A deployment config describes WHERE the manager, GPU trainer and rollout workers live and HOW they reach each other. It deliberately excludes every training-side field (learning rate, sampling, task catalog) and never stores secrets: SSH targets must resolve through the invoking user's SSH config, agent or a restricted identity file.
DeploymentError ¶
destination ¶
validate ¶
Strictly validate and normalize a deployment mapping.
Source code in harborrl/deployment/schema.py
embedded_local ¶
Default same-machine deployment; behavior matches the legacy pipeline.
Source code in harborrl/deployment/schema.py
load_deployment ¶
Load an explicit, default-discovered or embedded-local deployment config.
Returns (config, source) where source describes where the config came
from; absent any file the embedded-local topology keeps legacy behavior.
Source code in harborrl/deployment/schema.py
summary ¶
Plan-embedded deployment digest; the full config travels with it.
Source code in harborrl/deployment/schema.py
harborrl.deployment.training_target ¶
TrainingTarget (P1): launch, query and cancel one Slime training job.
local keeps the legacy in-process launcher byte-for-byte. ssh runs the
same launcher script on the GPU machine through shared storage: the run
directory is written by the manager, executed by the GPU target, and polled
without holding an interactive session open.
TrainingTargetError ¶
LocalTrainingTarget ¶
Legacy target: the Slime job runs as a child of this process.
Source code in harborrl/deployment/training_target.py
SshTrainingTarget ¶
Remote target over shared storage; the launcher script is the contract.
Source code in harborrl/deployment/training_target.py
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 | |
write_launcher ¶
Materialize the launcher; env values and paths are quoted, never interpolated.
Source code in harborrl/deployment/training_target.py
wait ¶
Poll the shared exit-code record; never resubmit or restart.
Source code in harborrl/deployment/training_target.py
local_target ¶
Build the legacy in-process target from a resolved plan.
Source code in harborrl/deployment/training_target.py
Consistency configuration and metrics¶
harborrl.consistency.config ¶
Explicit deployment-specific tolerances; no universal numeric threshold.
validate ¶
Source code in harborrl/consistency/config.py
require_raw_sampling ¶
Source code in harborrl/consistency/config.py
violations ¶
Source code in harborrl/consistency/config.py
harborrl.consistency.metrics ¶
Mergeable token statistics with bounded-memory percentile upper bounds.