tensor-optix 2.0.3__tar.gz → 2.0.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/PKG-INFO +50 -5
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/README.md +49 -4
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/pyproject.toml +1 -1
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/adapters/pytorch/torch_evaluator.py +9 -9
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/adapters/tensorflow/tf_evaluator.py +9 -9
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/algorithms/tf_dqn.py +11 -7
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/algorithms/tf_sac.py +14 -10
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/algorithms/tf_td3.py +19 -9
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/algorithms/torch_dqn.py +9 -5
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/algorithms/torch_rainbow_dqn.py +9 -5
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/algorithms/torch_recurrent_ppo.py +19 -1
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/algorithms/torch_sac.py +9 -5
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/algorithms/torch_td3.py +17 -7
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/callbacks/tensorboard_callback.py +7 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/callbacks/wandb_callback.py +7 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/cli.py +8 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/config.py +50 -8
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/core/backoff_scheduler.py +9 -3
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/core/base_evaluator.py +4 -1
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/core/checkpoint_registry.py +6 -1
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/core/diagnostic_controller.py +2 -1
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/core/ensemble_agent.py +12 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/core/loop_controller.py +56 -47
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/core/obs_utils.py +120 -120
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/core/policy_manager.py +32 -2
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/core/replay_buffer.py +29 -1
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/core/reward_shape.py +16 -10
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/distributed/async_learner.py +9 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/encoders/__init__.py +15 -15
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/encoders/obs_encoder.py +229 -229
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/encoders/obs_encoder_tf.py +80 -80
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/factory.py +64 -10
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/ledger/callback.py +19 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/ledger/provenance.py +19 -7
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/ml/loss_registry.py +2 -1
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/ml_core/__init__.py +53 -53
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/ml_core/adapters/flax_model.py +230 -230
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/ml_core/adapters/tf_model.py +208 -208
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/ml_core/adapters/torch_model.py +241 -241
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/ml_core/base_model.py +150 -150
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/ml_core/lr_schedules.py +67 -67
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/ml_core/metrics.py +201 -188
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/ml_core/metrics_impl/classification.py +101 -101
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/ml_core/metrics_impl/regression.py +46 -46
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/ml_core/trainer.py +240 -207
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/ml_core/transfer.py +152 -152
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/multi_agent/__init__.py +34 -34
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/multi_agent/aec_pipeline.py +191 -173
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/multi_agent/multi_agent_episode.py +18 -18
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/multi_agent/multi_agent_runtime.py +53 -53
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/multi_agent/parallel_pipeline.py +145 -145
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/multi_agent/seat_env.py +81 -81
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/nanonets/selector.py +9 -3
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/neuroevo/agent/graph_agent.py +74 -15
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/neuroevo/controller/topology_controller.py +16 -4
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/neuroevo/graph/neuron_graph.py +58 -2
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/neuroevo/graph/topology_ops.py +51 -16
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/neuroevo/hebbian.py +45 -4
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/neuroevo/neuromodulator.py +12 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/optimizer.py +17 -10
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/optimizers/backoff_optimizer.py +13 -4
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/optimizers/spsa_optimizer.py +18 -3
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/pipeline/batch_pipeline.py +5 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/pipeline/live_pipeline.py +30 -6
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/pipeline/vector_pipeline.py +19 -2
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/runtime/baseline.py +8 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/runtime/live_runtime.py +12 -4
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/scheduler/pool.py +36 -1
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/scheduler/worker.py +7 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/selection/selector.py +17 -1
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/simple.py +11 -1
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/strategy/grammar.py +8 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/strategy/worker.py +14 -0
- tensor_optix-2.0.4/tensor_optix/utils/console.py +28 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix.egg-info/PKG-INFO +50 -5
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix.egg-info/SOURCES.txt +1 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/setup.cfg +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/__init__.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/adapters/__init__.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/adapters/jax/__init__.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/adapters/jax/flax_agent.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/adapters/jax/flax_evaluator.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/adapters/pytorch/__init__.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/adapters/pytorch/torch_agent.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/adapters/tensorflow/__init__.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/adapters/tensorflow/tf_agent.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/algorithms/__init__.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/algorithms/flax_ppo.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/algorithms/tf_ppo.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/algorithms/tf_ppo_continuous.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/algorithms/torch_ppo.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/algorithms/torch_ppo_continuous.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/callbacks/__init__.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/callbacks/rich_dashboard.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/core/__init__.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/core/async_callback.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/core/base_agent.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/core/base_optimizer.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/core/base_pipeline.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/core/checkpoint_confirmation.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/core/device.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/core/her_buffer.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/core/meta_controller.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/core/noisy_linear.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/core/normalizers.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/core/regime_detector.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/core/resume_state.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/core/trajectory_buffer.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/core/types.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/distributed/__init__.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/distributed/vtrace.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/exploration/__init__.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/exploration/rnd.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/ledger/__init__.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/ledger/records.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/ledger/schema.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/ledger/store.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/ml/__init__.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/ml/dataset_pipeline.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/ml/ml_agent.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/ml_core/adapters/__init__.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/ml_core/metrics_impl/__init__.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/nanonets/__init__.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/nanonets/abstention.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/nanonets/features.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/nanonets/pooling.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/nanonets/smalln.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/neuroevo/__init__.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/neuroevo/agent/__init__.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/neuroevo/brain_network.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/neuroevo/controller/__init__.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/neuroevo/controller/topology_callback.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/neuroevo/graph/__init__.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/neuroevo/graph/neuron.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/neuroevo/optimizer/__init__.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/neuroevo/optimizer/topology_aware_adam.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/optimizers/__init__.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/optimizers/adaptive_optimizer.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/optimizers/momentum_optimizer.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/optimizers/pbt_optimizer.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/orchestrator.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/pipeline/__init__.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/runtime/__init__.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/runtime/experiment_stage.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/runtime/observer.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/runtime/promote.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/scheduler/__init__.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/scheduler/_mp_common.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/scheduler/budget.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/scheduler/dedup.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/scheduler/isolation.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/scheduler/retry.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/selection/__init__.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/selection/backfill.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/selection/uncertainty.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/strategy/__init__.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/strategy/candidate.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/strategy/comparator.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/strategy/promotion.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/strategy/runner.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/utils/__init__.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/utils/window_size.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix.egg-info/dependency_links.txt +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix.egg-info/entry_points.txt +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix.egg-info/requires.txt +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix.egg-info/top_level.txt +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tests/test_ml.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: tensor-optix
|
|
3
|
-
Version: 2.0.
|
|
3
|
+
Version: 2.0.4
|
|
4
4
|
Summary: Autonomous training loop for any sequential learning model — PPO, DQN, SAC, TD3, Rainbow DQN, Recurrent PPO for TensorFlow, PyTorch, and JAX/Flax; distributed async actor-learner (IMPALA + V-trace)
|
|
5
5
|
Author: sup3rus3r
|
|
6
6
|
License-Expression: MIT
|
|
@@ -162,7 +162,7 @@ pip install tensor-optix[torch]
|
|
|
162
162
|
pip install tensor-optix[all]
|
|
163
163
|
```
|
|
164
164
|
|
|
165
|
-
Environment extras: `[box2d]`, `[atari]`, `[mujoco]`
|
|
165
|
+
Environment extras: `[box2d]`, `[atari]`, `[mujoco]`, `[pettingzoo]` (multi-agent)
|
|
166
166
|
Logging extras: `[wandb]`, `[tensorboard]`
|
|
167
167
|
Export: `[onnx]`
|
|
168
168
|
|
|
@@ -194,7 +194,7 @@ All agents implement `BaseAgent` and are interchangeable with `RLOptimizer`.
|
|
|
194
194
|
|
|
195
195
|
### Auto-selection
|
|
196
196
|
|
|
197
|
-
`make_agent` inspects the environment action space and returns a fully constructed agent. Pass an algorithm name as the first argument, or let it be inferred.
|
|
197
|
+
`make_agent` inspects the environment action space and returns a fully constructed agent. Pass an algorithm name as the first argument, or let it be inferred. Observations may be a flat `Box`, an image `Box` `(H, W, C)` (CNN encoder), or a `Dict` of those (see [Encoders](https://sup3rus3r.github.io/tensor-optix/reference/encoders/)).
|
|
198
198
|
|
|
199
199
|
```python
|
|
200
200
|
from tensor_optix import make_agent
|
|
@@ -280,6 +280,32 @@ pipeline = VectorBatchPipeline(
|
|
|
280
280
|
)
|
|
281
281
|
```
|
|
282
282
|
|
|
283
|
+
Notes:
|
|
284
|
+
|
|
285
|
+
- `VectorBatchPipeline` works with every built-in agent except `TorchRecurrentPPOAgent`: PPO agents compute GAE per env, and the off-policy agents (DQN, Rainbow, SAC, TD3) build replay transitions per env. Envs are created with Gymnasium's `SAME_STEP` autoreset so no action-ignored "reset" transitions enter the training data.
|
|
286
|
+
- `BatchPipeline` resets a recurrent agent's hidden state (`reset_hidden()`) at every episode boundary.
|
|
287
|
+
- `LivePipeline` applies backpressure: when the consumer is slower than the source, the producer waits instead of dropping samples or restarting the stream.
|
|
288
|
+
|
|
289
|
+
### Multi-agent (PettingZoo)
|
|
290
|
+
|
|
291
|
+
`pip install tensor-optix[torch,pettingzoo]` adds pipelines for PettingZoo's Parallel and AEC (turn-based) APIs. Each seat is an ordinary agent; a window yields one `EpisodeData` per seat.
|
|
292
|
+
|
|
293
|
+
```python
|
|
294
|
+
from pettingzoo.classic import rps_v2
|
|
295
|
+
from tensor_optix import make_agent
|
|
296
|
+
from tensor_optix.multi_agent import SeatEnvView, AECMultiAgentPipeline, MultiAgentRunner
|
|
297
|
+
|
|
298
|
+
env = rps_v2.env()
|
|
299
|
+
env.reset(seed=0)
|
|
300
|
+
views = {aid: SeatEnvView(env, aid) for aid in env.possible_agents}
|
|
301
|
+
agents = {aid: make_agent(views[aid]) for aid in env.possible_agents}
|
|
302
|
+
|
|
303
|
+
pipeline = AECMultiAgentPipeline(env, agents, window_size=400, views=views)
|
|
304
|
+
MultiAgentRunner(pipeline, agents).run(max_windows=500)
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
In turn-based games each reward (including the terminal win/loss) is credited to the action that earned it. `MultiAgentRunner` is a minimal collect/learn driver - it does not run the convergence/checkpoint state machine. See [Multi-agent training](https://sup3rus3r.github.io/tensor-optix/guides/multi-agent/).
|
|
308
|
+
|
|
283
309
|
---
|
|
284
310
|
|
|
285
311
|
## The loop
|
|
@@ -309,7 +335,20 @@ opt.best_snapshot # -> PolicySnapshot: best weights + EvalMetrics + Hyperparam
|
|
|
309
335
|
|
|
310
336
|
Loop state transitions: `ACTIVE` -> `COOLING` -> `DORMANT` -> watchdog shutdown or policy spawn.
|
|
311
337
|
|
|
312
|
-
|
|
338
|
+
- Every non-improving eval counts toward `COOLING`/`DORMANT`, for on-policy and off-policy agents alike. While the score is flat the eval interval backs off (`backoff_factor`, default 2.0); set `backoff_factor=1.0` to evaluate every window.
|
|
339
|
+
- At `DORMANT` the loop stops by default. A `PolicyManagerCallback` with spawn budget remaining spawns a variant instead and training continues.
|
|
340
|
+
- `rollback_on_degradation=True` restores the best checkpoint when a degradation is confirmed (`min_consecutive_degradations` consecutive evals below `degradation_threshold x best`), for on-policy agents only - off-policy agents keep their weights because their replay buffer would immediately pull a restored policy back.
|
|
341
|
+
- On shutdown the loop restores best-known weights, not the final checkpoint.
|
|
342
|
+
- `verbose=True` prints a per-eval diagnostic block; it is safe on consoles that cannot render the box-drawing glyphs (they degrade to `?`).
|
|
343
|
+
|
|
344
|
+
### YAML / CLI
|
|
345
|
+
|
|
346
|
+
```bash
|
|
347
|
+
tensor-optix validate config.yaml
|
|
348
|
+
tensor-optix train config.yaml agent.learning_rate=1e-3 optimizer.max_episodes=200
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
The `algorithm` key selects the agent class and must be buildable for the env (e.g. `TorchDQNAgent` needs a discrete action space; a mismatch is a build error, not a silent substitution). See [Configure via YAML / CLI](https://sup3rus3r.github.io/tensor-optix/guides/cli-config/).
|
|
313
352
|
|
|
314
353
|
---
|
|
315
354
|
|
|
@@ -372,12 +411,14 @@ best_config = orch.run()
|
|
|
372
411
|
from tensor_optix import PolicyManager
|
|
373
412
|
|
|
374
413
|
pm = PolicyManager(registry, max_spawns=4)
|
|
375
|
-
cb = pm.as_callback(agent, agent_factory=make_agent)
|
|
414
|
+
cb = pm.as_callback(agent, agent_factory=lambda: make_agent(env)) # zero-argument factory
|
|
376
415
|
cb.set_stop_fn(opt.stop)
|
|
377
416
|
opt.add_callback(cb)
|
|
378
417
|
opt.run()
|
|
379
418
|
```
|
|
380
419
|
|
|
420
|
+
Each `DORMANT` event with budget remaining spawns a variant and training continues; once the budget is exhausted the callback stops the loop with the best weights restored. A multi-member `EnsembleAgent` combines policies at inference time - for discrete PPO members `act()` returns the averaged probability vector, which you sample or `argmax`.
|
|
421
|
+
|
|
381
422
|
---
|
|
382
423
|
|
|
383
424
|
## Callbacks
|
|
@@ -788,6 +829,8 @@ store.finalize_experiment(record.experiment_id, state=ExperimentState.COMPLETED)
|
|
|
788
829
|
|
|
789
830
|
Writes are idempotent on `experiment_id`, and every method opens a short, single-statement transaction — nothing here ever holds a lock for the duration of training.
|
|
790
831
|
|
|
832
|
+
To record an ordinary training run, attach `ExperimentLedgerCallback(store, task_env=..., algorithm=..., checkpoint_dir=...)` (from `tensor_optix.ledger.callback`) to `RLOptimizer`. A run that raises is finalized `FAILED` automatically; an interrupted one `CANCELLED`.
|
|
833
|
+
|
|
791
834
|
### Concurrent trial scheduler
|
|
792
835
|
|
|
793
836
|
`ConcurrentTrialScheduler` runs multiple Optuna trials as real OS processes, with the parent process as sole owner of the Optuna study and the ledger.
|
|
@@ -804,6 +847,8 @@ scheduler = ConcurrentTrialScheduler(
|
|
|
804
847
|
best_params, best_score = scheduler.run()
|
|
805
848
|
```
|
|
806
849
|
|
|
850
|
+
A worker that dies without reporting (OOM-kill, crash) is detected, retried up to `max_retries` times, and then recorded as `FAILED` - the scheduler never waits on a dead process.
|
|
851
|
+
|
|
807
852
|
### Cross-task transfer (Nanonets)
|
|
808
853
|
|
|
809
854
|
`NanonetsSelector` pools evidence from other tasks' ledger history when deciding how to allocate a new task's trial budget — but only when a conservative abstention gate confirms a source task's data is actually comparable (median performance at or above the target's own 95th percentile, both normalized against each task's own solve threshold so differently-scaled/signed scores are never compared on raw terms). When nothing passes the gate, it falls back to the non-learned baseline rather than guess.
|
|
@@ -91,7 +91,7 @@ pip install tensor-optix[torch]
|
|
|
91
91
|
pip install tensor-optix[all]
|
|
92
92
|
```
|
|
93
93
|
|
|
94
|
-
Environment extras: `[box2d]`, `[atari]`, `[mujoco]`
|
|
94
|
+
Environment extras: `[box2d]`, `[atari]`, `[mujoco]`, `[pettingzoo]` (multi-agent)
|
|
95
95
|
Logging extras: `[wandb]`, `[tensorboard]`
|
|
96
96
|
Export: `[onnx]`
|
|
97
97
|
|
|
@@ -123,7 +123,7 @@ All agents implement `BaseAgent` and are interchangeable with `RLOptimizer`.
|
|
|
123
123
|
|
|
124
124
|
### Auto-selection
|
|
125
125
|
|
|
126
|
-
`make_agent` inspects the environment action space and returns a fully constructed agent. Pass an algorithm name as the first argument, or let it be inferred.
|
|
126
|
+
`make_agent` inspects the environment action space and returns a fully constructed agent. Pass an algorithm name as the first argument, or let it be inferred. Observations may be a flat `Box`, an image `Box` `(H, W, C)` (CNN encoder), or a `Dict` of those (see [Encoders](https://sup3rus3r.github.io/tensor-optix/reference/encoders/)).
|
|
127
127
|
|
|
128
128
|
```python
|
|
129
129
|
from tensor_optix import make_agent
|
|
@@ -209,6 +209,32 @@ pipeline = VectorBatchPipeline(
|
|
|
209
209
|
)
|
|
210
210
|
```
|
|
211
211
|
|
|
212
|
+
Notes:
|
|
213
|
+
|
|
214
|
+
- `VectorBatchPipeline` works with every built-in agent except `TorchRecurrentPPOAgent`: PPO agents compute GAE per env, and the off-policy agents (DQN, Rainbow, SAC, TD3) build replay transitions per env. Envs are created with Gymnasium's `SAME_STEP` autoreset so no action-ignored "reset" transitions enter the training data.
|
|
215
|
+
- `BatchPipeline` resets a recurrent agent's hidden state (`reset_hidden()`) at every episode boundary.
|
|
216
|
+
- `LivePipeline` applies backpressure: when the consumer is slower than the source, the producer waits instead of dropping samples or restarting the stream.
|
|
217
|
+
|
|
218
|
+
### Multi-agent (PettingZoo)
|
|
219
|
+
|
|
220
|
+
`pip install tensor-optix[torch,pettingzoo]` adds pipelines for PettingZoo's Parallel and AEC (turn-based) APIs. Each seat is an ordinary agent; a window yields one `EpisodeData` per seat.
|
|
221
|
+
|
|
222
|
+
```python
|
|
223
|
+
from pettingzoo.classic import rps_v2
|
|
224
|
+
from tensor_optix import make_agent
|
|
225
|
+
from tensor_optix.multi_agent import SeatEnvView, AECMultiAgentPipeline, MultiAgentRunner
|
|
226
|
+
|
|
227
|
+
env = rps_v2.env()
|
|
228
|
+
env.reset(seed=0)
|
|
229
|
+
views = {aid: SeatEnvView(env, aid) for aid in env.possible_agents}
|
|
230
|
+
agents = {aid: make_agent(views[aid]) for aid in env.possible_agents}
|
|
231
|
+
|
|
232
|
+
pipeline = AECMultiAgentPipeline(env, agents, window_size=400, views=views)
|
|
233
|
+
MultiAgentRunner(pipeline, agents).run(max_windows=500)
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
In turn-based games each reward (including the terminal win/loss) is credited to the action that earned it. `MultiAgentRunner` is a minimal collect/learn driver - it does not run the convergence/checkpoint state machine. See [Multi-agent training](https://sup3rus3r.github.io/tensor-optix/guides/multi-agent/).
|
|
237
|
+
|
|
212
238
|
---
|
|
213
239
|
|
|
214
240
|
## The loop
|
|
@@ -238,7 +264,20 @@ opt.best_snapshot # -> PolicySnapshot: best weights + EvalMetrics + Hyperparam
|
|
|
238
264
|
|
|
239
265
|
Loop state transitions: `ACTIVE` -> `COOLING` -> `DORMANT` -> watchdog shutdown or policy spawn.
|
|
240
266
|
|
|
241
|
-
|
|
267
|
+
- Every non-improving eval counts toward `COOLING`/`DORMANT`, for on-policy and off-policy agents alike. While the score is flat the eval interval backs off (`backoff_factor`, default 2.0); set `backoff_factor=1.0` to evaluate every window.
|
|
268
|
+
- At `DORMANT` the loop stops by default. A `PolicyManagerCallback` with spawn budget remaining spawns a variant instead and training continues.
|
|
269
|
+
- `rollback_on_degradation=True` restores the best checkpoint when a degradation is confirmed (`min_consecutive_degradations` consecutive evals below `degradation_threshold x best`), for on-policy agents only - off-policy agents keep their weights because their replay buffer would immediately pull a restored policy back.
|
|
270
|
+
- On shutdown the loop restores best-known weights, not the final checkpoint.
|
|
271
|
+
- `verbose=True` prints a per-eval diagnostic block; it is safe on consoles that cannot render the box-drawing glyphs (they degrade to `?`).
|
|
272
|
+
|
|
273
|
+
### YAML / CLI
|
|
274
|
+
|
|
275
|
+
```bash
|
|
276
|
+
tensor-optix validate config.yaml
|
|
277
|
+
tensor-optix train config.yaml agent.learning_rate=1e-3 optimizer.max_episodes=200
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
The `algorithm` key selects the agent class and must be buildable for the env (e.g. `TorchDQNAgent` needs a discrete action space; a mismatch is a build error, not a silent substitution). See [Configure via YAML / CLI](https://sup3rus3r.github.io/tensor-optix/guides/cli-config/).
|
|
242
281
|
|
|
243
282
|
---
|
|
244
283
|
|
|
@@ -301,12 +340,14 @@ best_config = orch.run()
|
|
|
301
340
|
from tensor_optix import PolicyManager
|
|
302
341
|
|
|
303
342
|
pm = PolicyManager(registry, max_spawns=4)
|
|
304
|
-
cb = pm.as_callback(agent, agent_factory=make_agent)
|
|
343
|
+
cb = pm.as_callback(agent, agent_factory=lambda: make_agent(env)) # zero-argument factory
|
|
305
344
|
cb.set_stop_fn(opt.stop)
|
|
306
345
|
opt.add_callback(cb)
|
|
307
346
|
opt.run()
|
|
308
347
|
```
|
|
309
348
|
|
|
349
|
+
Each `DORMANT` event with budget remaining spawns a variant and training continues; once the budget is exhausted the callback stops the loop with the best weights restored. A multi-member `EnsembleAgent` combines policies at inference time - for discrete PPO members `act()` returns the averaged probability vector, which you sample or `argmax`.
|
|
350
|
+
|
|
310
351
|
---
|
|
311
352
|
|
|
312
353
|
## Callbacks
|
|
@@ -717,6 +758,8 @@ store.finalize_experiment(record.experiment_id, state=ExperimentState.COMPLETED)
|
|
|
717
758
|
|
|
718
759
|
Writes are idempotent on `experiment_id`, and every method opens a short, single-statement transaction — nothing here ever holds a lock for the duration of training.
|
|
719
760
|
|
|
761
|
+
To record an ordinary training run, attach `ExperimentLedgerCallback(store, task_env=..., algorithm=..., checkpoint_dir=...)` (from `tensor_optix.ledger.callback`) to `RLOptimizer`. A run that raises is finalized `FAILED` automatically; an interrupted one `CANCELLED`.
|
|
762
|
+
|
|
720
763
|
### Concurrent trial scheduler
|
|
721
764
|
|
|
722
765
|
`ConcurrentTrialScheduler` runs multiple Optuna trials as real OS processes, with the parent process as sole owner of the Optuna study and the ledger.
|
|
@@ -733,6 +776,8 @@ scheduler = ConcurrentTrialScheduler(
|
|
|
733
776
|
best_params, best_score = scheduler.run()
|
|
734
777
|
```
|
|
735
778
|
|
|
779
|
+
A worker that dies without reporting (OOM-kill, crash) is detected, retried up to `max_retries` times, and then recorded as `FAILED` - the scheduler never waits on a dead process.
|
|
780
|
+
|
|
736
781
|
### Cross-task transfer (Nanonets)
|
|
737
782
|
|
|
738
783
|
`NanonetsSelector` pools evidence from other tasks' ledger history when deciding how to allocate a new task's trial budget — but only when a conservative abstention gate confirms a source task's data is actually comparable (median performance at or above the target's own 95th percentile, both normalized against each task's own solve threshold so differently-scaled/signed scores are never compared on raw terms). When nothing passes the gate, it falls back to the non-learned baseline rather than guess.
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "tensor-optix"
|
|
7
|
-
version = "2.0.
|
|
7
|
+
version = "2.0.4"
|
|
8
8
|
description = "Autonomous training loop for any sequential learning model — PPO, DQN, SAC, TD3, Rainbow DQN, Recurrent PPO for TensorFlow, PyTorch, and JAX/Flax; distributed async actor-learner (IMPALA + V-trace)"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = "MIT"
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import numpy as np
|
|
2
2
|
from typing import Callable, Optional
|
|
3
3
|
from tensor_optix.core.base_evaluator import BaseEvaluator
|
|
4
|
+
from tensor_optix.core.reward_shape import split_episode_returns
|
|
4
5
|
from tensor_optix.core.types import EpisodeData, EvalMetrics
|
|
5
6
|
|
|
6
7
|
|
|
@@ -39,7 +40,8 @@ class TorchEvaluator(BaseEvaluator):
|
|
|
39
40
|
if self._primary_score_fn is not None:
|
|
40
41
|
primary = float(self._primary_score_fn(episode_data, train_diagnostics))
|
|
41
42
|
else:
|
|
42
|
-
|
|
43
|
+
n_envs = int((episode_data.metadata or {}).get("n_envs", 1))
|
|
44
|
+
primary = self._mean_episode_return(rewards, dones, n_envs)
|
|
43
45
|
|
|
44
46
|
metrics = {
|
|
45
47
|
"primary_score": primary,
|
|
@@ -54,20 +56,18 @@ class TorchEvaluator(BaseEvaluator):
|
|
|
54
56
|
episode_id=episode_data.episode_id)
|
|
55
57
|
|
|
56
58
|
@staticmethod
|
|
57
|
-
def _mean_episode_return(rewards: np.ndarray, dones: list) -> float:
|
|
59
|
+
def _mean_episode_return(rewards: np.ndarray, dones: list, n_envs: int = 1) -> float:
|
|
58
60
|
"""
|
|
59
61
|
Compute mean return of episodes that completed in this window.
|
|
60
62
|
dones should be terminated OR truncated — both signal an episode
|
|
61
63
|
boundary. Falls back to mean per-step reward only if the window
|
|
62
64
|
contains a single incomplete episode (very long envs, early training).
|
|
63
65
|
"""
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
episode_returns.append(current)
|
|
70
|
-
current = 0.0
|
|
66
|
+
# Per-env accumulation: a VectorBatchPipeline window interleaves
|
|
67
|
+
# n_envs envs, and each episode's return must only sum its own env.
|
|
68
|
+
episode_returns = [
|
|
69
|
+
float(np.sum(seg)) for seg in split_episode_returns(rewards, dones, n_envs)
|
|
70
|
+
]
|
|
71
71
|
if episode_returns:
|
|
72
72
|
return float(np.mean(episode_returns))
|
|
73
73
|
return float(rewards.mean())
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import numpy as np
|
|
2
2
|
from tensor_optix.core.base_evaluator import BaseEvaluator
|
|
3
|
+
from tensor_optix.core.reward_shape import split_episode_returns
|
|
3
4
|
from tensor_optix.core.types import EpisodeData, EvalMetrics
|
|
4
5
|
|
|
5
6
|
|
|
@@ -36,7 +37,8 @@ class TFEvaluator(BaseEvaluator):
|
|
|
36
37
|
if self._primary_score_fn is not None:
|
|
37
38
|
primary = float(self._primary_score_fn(episode_data, train_diagnostics))
|
|
38
39
|
else:
|
|
39
|
-
|
|
40
|
+
n_envs = int((episode_data.metadata or {}).get("n_envs", 1))
|
|
41
|
+
primary = self._mean_episode_return(rewards, dones, n_envs)
|
|
40
42
|
|
|
41
43
|
metrics = {
|
|
42
44
|
"primary_score": primary,
|
|
@@ -51,20 +53,18 @@ class TFEvaluator(BaseEvaluator):
|
|
|
51
53
|
episode_id=episode_data.episode_id)
|
|
52
54
|
|
|
53
55
|
@staticmethod
|
|
54
|
-
def _mean_episode_return(rewards: np.ndarray, dones: list) -> float:
|
|
56
|
+
def _mean_episode_return(rewards: np.ndarray, dones: list, n_envs: int = 1) -> float:
|
|
55
57
|
"""
|
|
56
58
|
Compute mean return of episodes that completed in this window.
|
|
57
59
|
dones should be terminated OR truncated — both signal an episode
|
|
58
60
|
boundary. Falls back to mean per-step reward only if the window
|
|
59
61
|
contains a single incomplete episode (very long envs, early training).
|
|
60
62
|
"""
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
episode_returns.append(current)
|
|
67
|
-
current = 0.0
|
|
63
|
+
# Per-env accumulation: a VectorBatchPipeline window interleaves
|
|
64
|
+
# n_envs envs, and each episode's return must only sum its own env.
|
|
65
|
+
episode_returns = [
|
|
66
|
+
float(np.sum(seg)) for seg in split_episode_returns(rewards, dones, n_envs)
|
|
67
|
+
]
|
|
68
68
|
if episode_returns:
|
|
69
69
|
return float(np.mean(episode_returns))
|
|
70
70
|
return float(rewards.mean())
|
|
@@ -6,7 +6,7 @@ import tensorflow as tf
|
|
|
6
6
|
|
|
7
7
|
from tensor_optix.core.base_agent import BaseAgent
|
|
8
8
|
from tensor_optix.core.types import EpisodeData, HyperparamSet
|
|
9
|
-
from tensor_optix.core.replay_buffer import PrioritizedReplayBuffer
|
|
9
|
+
from tensor_optix.core.replay_buffer import PrioritizedReplayBuffer, episode_n_envs, window_transition_pairs
|
|
10
10
|
from tensor_optix.core.obs_utils import to_batch_numpy, to_tf_batch, already_batched_to_tf, batch_index
|
|
11
11
|
|
|
12
12
|
|
|
@@ -119,12 +119,16 @@ class TFDQNAgent(BaseAgent):
|
|
|
119
119
|
done_arr = episode_data.dones
|
|
120
120
|
|
|
121
121
|
T = len(rew_arr)
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
122
|
+
# Pair each step with the NEXT step of the same environment. With a
|
|
123
|
+
# VectorBatchPipeline window the flat arrays interleave n_envs envs
|
|
124
|
+
# ([t * n_envs + i]), so index t + 1 belongs to a different env.
|
|
125
|
+
for env_pairs in window_transition_pairs(T, episode_n_envs(episode_data)):
|
|
126
|
+
for t, t_next in env_pairs:
|
|
127
|
+
self._buffer.push(
|
|
128
|
+
batch_index(obs_arr, t), int(act_arr[t]), float(rew_arr[t]),
|
|
129
|
+
batch_index(obs_arr, t_next), bool(done_arr[t]),
|
|
130
|
+
)
|
|
131
|
+
self._buffer.flush_episode()
|
|
128
132
|
|
|
129
133
|
self._learn_calls += 1
|
|
130
134
|
new_eps = max(epsilon_min, float(hp.get("epsilon", 1.0)) * epsilon_decay)
|
|
@@ -6,7 +6,7 @@ import tensorflow as tf
|
|
|
6
6
|
|
|
7
7
|
from tensor_optix.core.base_agent import BaseAgent
|
|
8
8
|
from tensor_optix.core.types import EpisodeData, HyperparamSet
|
|
9
|
-
from tensor_optix.core.replay_buffer import PrioritizedReplayBuffer
|
|
9
|
+
from tensor_optix.core.replay_buffer import PrioritizedReplayBuffer, episode_n_envs, window_transition_pairs
|
|
10
10
|
from tensor_optix.core.obs_utils import to_batch_numpy, to_tf_batch, already_batched_to_tf
|
|
11
11
|
|
|
12
12
|
|
|
@@ -175,15 +175,19 @@ class TFSACAgent(BaseAgent):
|
|
|
175
175
|
done_arr = episode_data.dones
|
|
176
176
|
T = len(rew_arr)
|
|
177
177
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
178
|
+
# Pair each step with the NEXT step of the same environment. With a
|
|
179
|
+
# VectorBatchPipeline window the flat arrays interleave n_envs envs
|
|
180
|
+
# ([t * n_envs + i]), so index t + 1 belongs to a different env.
|
|
181
|
+
for env_pairs in window_transition_pairs(T, episode_n_envs(episode_data)):
|
|
182
|
+
for t, t_next in env_pairs:
|
|
183
|
+
self._buffer.push(
|
|
184
|
+
obs_arr[t],
|
|
185
|
+
act_arr[t],
|
|
186
|
+
float(rew_arr[t]),
|
|
187
|
+
obs_arr[t_next],
|
|
188
|
+
float(done_arr[t]),
|
|
189
|
+
)
|
|
190
|
+
self._buffer.flush_episode()
|
|
187
191
|
|
|
188
192
|
if len(self._buffer) < batch_size:
|
|
189
193
|
return {
|
|
@@ -61,7 +61,7 @@ import tensorflow as tf
|
|
|
61
61
|
|
|
62
62
|
from tensor_optix.core.base_agent import BaseAgent
|
|
63
63
|
from tensor_optix.core.types import EpisodeData, HyperparamSet
|
|
64
|
-
from tensor_optix.core.replay_buffer import PrioritizedReplayBuffer
|
|
64
|
+
from tensor_optix.core.replay_buffer import PrioritizedReplayBuffer, episode_n_envs, window_transition_pairs
|
|
65
65
|
from tensor_optix.core.obs_utils import to_tf_batch, already_batched_to_tf
|
|
66
66
|
|
|
67
67
|
|
|
@@ -146,8 +146,14 @@ class TFTDDAgent(BaseAgent):
|
|
|
146
146
|
def act(self, observation) -> np.ndarray:
|
|
147
147
|
"""Deterministic action: a = π_θ(s) = tanh(actor(s))."""
|
|
148
148
|
obs = to_tf_batch(observation)
|
|
149
|
-
action = self._actor(obs, training=False)
|
|
150
|
-
|
|
149
|
+
action = self._actor(obs, training=False).numpy()[0]
|
|
150
|
+
# Optional Gaussian exploration noise (Fujimoto et al. 2018, σ=0.1).
|
|
151
|
+
# Off by default: act() stays deterministic unless the
|
|
152
|
+
# "exploration_noise" hyperparameter is set > 0.
|
|
153
|
+
sigma = float(self._hyperparams.params.get("exploration_noise", 0.0))
|
|
154
|
+
if sigma > 0.0:
|
|
155
|
+
action = np.clip(action + sigma * np.random.randn(*action.shape), -1.0, 1.0).astype(action.dtype)
|
|
156
|
+
return action
|
|
151
157
|
|
|
152
158
|
def learn(self, episode_data: EpisodeData) -> dict:
|
|
153
159
|
hp = self._hyperparams.params
|
|
@@ -164,12 +170,16 @@ class TFTDDAgent(BaseAgent):
|
|
|
164
170
|
done_arr = episode_data.dones
|
|
165
171
|
T = len(rew_arr)
|
|
166
172
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
+
# Pair each step with the NEXT step of the same environment. With a
|
|
174
|
+
# VectorBatchPipeline window the flat arrays interleave n_envs envs
|
|
175
|
+
# ([t * n_envs + i]), so index t + 1 belongs to a different env.
|
|
176
|
+
for env_pairs in window_transition_pairs(T, episode_n_envs(episode_data)):
|
|
177
|
+
for t, t_next in env_pairs:
|
|
178
|
+
self._buffer.push(
|
|
179
|
+
obs_arr[t], act_arr[t], float(rew_arr[t]),
|
|
180
|
+
obs_arr[t_next], float(done_arr[t]),
|
|
181
|
+
)
|
|
182
|
+
self._buffer.flush_episode()
|
|
173
183
|
|
|
174
184
|
if len(self._buffer) < batch_size:
|
|
175
185
|
return {
|
|
@@ -5,7 +5,7 @@ import numpy as np
|
|
|
5
5
|
|
|
6
6
|
from tensor_optix.core.base_agent import BaseAgent
|
|
7
7
|
from tensor_optix.core.types import EpisodeData, HyperparamSet
|
|
8
|
-
from tensor_optix.core.replay_buffer import PrioritizedReplayBuffer
|
|
8
|
+
from tensor_optix.core.replay_buffer import PrioritizedReplayBuffer, episode_n_envs, window_transition_pairs
|
|
9
9
|
from tensor_optix.core.obs_utils import to_batch_numpy, to_torch_batch, batch_index, already_batched_to_torch
|
|
10
10
|
|
|
11
11
|
|
|
@@ -130,10 +130,14 @@ class TorchDQNAgent(BaseAgent):
|
|
|
130
130
|
done_arr = episode_data.dones
|
|
131
131
|
T = len(rew_arr)
|
|
132
132
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
133
|
+
# Pair each step with the NEXT step of the same environment. With a
|
|
134
|
+
# VectorBatchPipeline window the flat arrays interleave n_envs envs
|
|
135
|
+
# ([t * n_envs + i]), so index t + 1 belongs to a different env.
|
|
136
|
+
for env_pairs in window_transition_pairs(T, episode_n_envs(episode_data)):
|
|
137
|
+
for t, t_next in env_pairs:
|
|
138
|
+
self._buffer.push(batch_index(obs_arr, t), int(act_arr[t]), float(rew_arr[t]),
|
|
139
|
+
batch_index(obs_arr, t_next), bool(done_arr[t]))
|
|
140
|
+
self._buffer.flush_episode()
|
|
137
141
|
|
|
138
142
|
self._learn_calls += 1
|
|
139
143
|
new_eps = max(epsilon_min, float(hp.get("epsilon", 1.0)) * epsilon_decay)
|
|
@@ -76,7 +76,7 @@ import numpy as np
|
|
|
76
76
|
|
|
77
77
|
from tensor_optix.core.base_agent import BaseAgent
|
|
78
78
|
from tensor_optix.core.types import EpisodeData, HyperparamSet
|
|
79
|
-
from tensor_optix.core.replay_buffer import PrioritizedReplayBuffer
|
|
79
|
+
from tensor_optix.core.replay_buffer import PrioritizedReplayBuffer, episode_n_envs, window_transition_pairs
|
|
80
80
|
from tensor_optix.core.noisy_linear import NoisyLinear
|
|
81
81
|
from tensor_optix.core.obs_utils import to_batch_numpy, to_torch_batch, batch_index, already_batched_to_torch
|
|
82
82
|
|
|
@@ -269,10 +269,14 @@ class TorchRainbowDQNAgent(BaseAgent):
|
|
|
269
269
|
done_arr = episode_data.dones
|
|
270
270
|
T = len(rew_arr)
|
|
271
271
|
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
272
|
+
# Pair each step with the NEXT step of the same environment. With a
|
|
273
|
+
# VectorBatchPipeline window the flat arrays interleave n_envs envs
|
|
274
|
+
# ([t * n_envs + i]), so index t + 1 belongs to a different env.
|
|
275
|
+
for env_pairs in window_transition_pairs(T, episode_n_envs(episode_data)):
|
|
276
|
+
for t, t_next in env_pairs:
|
|
277
|
+
self._buffer.push(batch_index(obs_arr, t), int(act_arr[t]), float(rew_arr[t]),
|
|
278
|
+
batch_index(obs_arr, t_next), bool(done_arr[t]))
|
|
279
|
+
self._buffer.flush_episode()
|
|
276
280
|
|
|
277
281
|
self._learn_calls += 1
|
|
278
282
|
|
|
@@ -219,10 +219,28 @@ class TorchRecurrentPPOAgent(BaseAgent):
|
|
|
219
219
|
self._cache_lp = self._cache_lp[T:]
|
|
220
220
|
self._cache_values = self._cache_values[T:]
|
|
221
221
|
self._cache_hidden = self._cache_hidden[T:]
|
|
222
|
+
|
|
223
|
+
# Bootstrap V(s_T) when the window ended mid-episode (BatchPipeline
|
|
224
|
+
# yields fixed-size windows, not whole episodes). self._h is the
|
|
225
|
+
# hidden state after the window's last step — exactly the context the
|
|
226
|
+
# critic needs for the post-window observation. Zero when terminal.
|
|
227
|
+
last_value = 0.0
|
|
228
|
+
final_obs = getattr(episode_data, "final_obs", None)
|
|
229
|
+
if (
|
|
230
|
+
T > 0 and not dones[-1] and self._h is not None
|
|
231
|
+
and final_obs is not None and not isinstance(final_obs, (list, tuple))
|
|
232
|
+
):
|
|
233
|
+
with torch.no_grad():
|
|
234
|
+
fo = torch.as_tensor(
|
|
235
|
+
np.atleast_2d(final_obs), dtype=torch.float32
|
|
236
|
+
).unsqueeze(0).to(self._device)
|
|
237
|
+
out, _ = self._rnn(fo, self._h)
|
|
238
|
+
last_value = float(self._critic_head(out.squeeze(0)).squeeze().item())
|
|
239
|
+
|
|
222
240
|
self._h = None # reset for next episode
|
|
223
241
|
|
|
224
242
|
# GAE advantage estimation
|
|
225
|
-
advantages, returns = compute_gae(rewards, val_arr, dones, gamma, gae_lambda,
|
|
243
|
+
advantages, returns = compute_gae(rewards, val_arr, dones, gamma, gae_lambda, last_value)
|
|
226
244
|
if T > 1:
|
|
227
245
|
advantages = (advantages - advantages.mean()) / (advantages.std() + 1e-8)
|
|
228
246
|
|
|
@@ -6,7 +6,7 @@ import numpy as np
|
|
|
6
6
|
from tensor_optix.core.base_agent import BaseAgent
|
|
7
7
|
from tensor_optix.core.resume_state import save_torch_resume_state, load_torch_resume_state
|
|
8
8
|
from tensor_optix.core.types import EpisodeData, HyperparamSet
|
|
9
|
-
from tensor_optix.core.replay_buffer import PrioritizedReplayBuffer
|
|
9
|
+
from tensor_optix.core.replay_buffer import PrioritizedReplayBuffer, episode_n_envs, window_transition_pairs
|
|
10
10
|
from tensor_optix.core.obs_utils import to_torch_batch, already_batched_to_torch
|
|
11
11
|
|
|
12
12
|
|
|
@@ -169,10 +169,14 @@ class TorchSACAgent(BaseAgent):
|
|
|
169
169
|
done_arr = episode_data.dones
|
|
170
170
|
T = len(rew_arr)
|
|
171
171
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
172
|
+
# Pair each step with the NEXT step of the same environment. With a
|
|
173
|
+
# VectorBatchPipeline window the flat arrays interleave n_envs envs
|
|
174
|
+
# ([t * n_envs + i]), so index t + 1 belongs to a different env.
|
|
175
|
+
for env_pairs in window_transition_pairs(T, episode_n_envs(episode_data)):
|
|
176
|
+
for t, t_next in env_pairs:
|
|
177
|
+
self._buffer.push(obs_arr[t], act_arr[t], float(rew_arr[t]),
|
|
178
|
+
obs_arr[t_next], float(done_arr[t]))
|
|
179
|
+
self._buffer.flush_episode()
|
|
176
180
|
|
|
177
181
|
if len(self._buffer) < batch_size:
|
|
178
182
|
return {
|
|
@@ -86,7 +86,7 @@ import numpy as np
|
|
|
86
86
|
|
|
87
87
|
from tensor_optix.core.base_agent import BaseAgent
|
|
88
88
|
from tensor_optix.core.types import EpisodeData, HyperparamSet
|
|
89
|
-
from tensor_optix.core.replay_buffer import PrioritizedReplayBuffer
|
|
89
|
+
from tensor_optix.core.replay_buffer import PrioritizedReplayBuffer, episode_n_envs, window_transition_pairs
|
|
90
90
|
from tensor_optix.core.obs_utils import to_torch_batch, already_batched_to_torch
|
|
91
91
|
|
|
92
92
|
|
|
@@ -179,6 +179,12 @@ class TorchTD3Agent(BaseAgent):
|
|
|
179
179
|
obs = to_torch_batch(observation, self._device)
|
|
180
180
|
with torch.no_grad():
|
|
181
181
|
action = self._actor(obs)
|
|
182
|
+
# Optional Gaussian exploration noise (Fujimoto et al. 2018, σ=0.1).
|
|
183
|
+
# Off by default: act() stays deterministic unless the
|
|
184
|
+
# "exploration_noise" hyperparameter is set > 0.
|
|
185
|
+
sigma = float(self._hyperparams.params.get("exploration_noise", 0.0))
|
|
186
|
+
if sigma > 0.0:
|
|
187
|
+
action = (action + sigma * torch.randn_like(action)).clamp(-1.0, 1.0)
|
|
182
188
|
return action.cpu().numpy()[0]
|
|
183
189
|
|
|
184
190
|
def learn(self, episode_data: EpisodeData) -> dict:
|
|
@@ -196,12 +202,16 @@ class TorchTD3Agent(BaseAgent):
|
|
|
196
202
|
done_arr = episode_data.dones
|
|
197
203
|
T = len(rew_arr)
|
|
198
204
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
+
# Pair each step with the NEXT step of the same environment. With a
|
|
206
|
+
# VectorBatchPipeline window the flat arrays interleave n_envs envs
|
|
207
|
+
# ([t * n_envs + i]), so index t + 1 belongs to a different env.
|
|
208
|
+
for env_pairs in window_transition_pairs(T, episode_n_envs(episode_data)):
|
|
209
|
+
for t, t_next in env_pairs:
|
|
210
|
+
self._buffer.push(
|
|
211
|
+
obs_arr[t], act_arr[t], float(rew_arr[t]),
|
|
212
|
+
obs_arr[t_next], float(done_arr[t]),
|
|
213
|
+
)
|
|
214
|
+
self._buffer.flush_episode()
|
|
205
215
|
|
|
206
216
|
if len(self._buffer) < batch_size:
|
|
207
217
|
return {
|
|
@@ -123,6 +123,10 @@ class TensorBoardCallback(LoopCallback):
|
|
|
123
123
|
self._writer.add_scalar(f"metrics/{k}", float(v), episode_id)
|
|
124
124
|
|
|
125
125
|
def on_improvement(self, snapshot: PolicySnapshot) -> None:
|
|
126
|
+
# These hooks fire before on_episode_end for the same episode;
|
|
127
|
+
# advance the step so a following on_hyperparam_update is not
|
|
128
|
+
# logged at an older step (W&B drops non-monotonic steps).
|
|
129
|
+
self._last_episode_id = max(self._last_episode_id, snapshot.episode_id)
|
|
126
130
|
if self._writer is None:
|
|
127
131
|
return
|
|
128
132
|
|
|
@@ -135,16 +139,19 @@ class TensorBoardCallback(LoopCallback):
|
|
|
135
139
|
self._writer.add_scalar(f"hyperparams/{k}", float(v), ep)
|
|
136
140
|
|
|
137
141
|
def on_plateau(self, episode_id: int, state) -> None:
|
|
142
|
+
self._last_episode_id = max(self._last_episode_id, episode_id)
|
|
138
143
|
if self._writer is None:
|
|
139
144
|
return
|
|
140
145
|
self._writer.add_scalar("events/plateau", 1, episode_id)
|
|
141
146
|
|
|
142
147
|
def on_dormant(self, episode_id: int) -> None:
|
|
148
|
+
self._last_episode_id = max(self._last_episode_id, episode_id)
|
|
143
149
|
if self._writer is None:
|
|
144
150
|
return
|
|
145
151
|
self._writer.add_scalar("events/convergence", 1, episode_id)
|
|
146
152
|
|
|
147
153
|
def on_degradation(self, episode_id: int, eval_metrics: Optional[EvalMetrics]) -> None:
|
|
154
|
+
self._last_episode_id = max(self._last_episode_id, episode_id)
|
|
148
155
|
if self._writer is None:
|
|
149
156
|
return
|
|
150
157
|
self._writer.add_scalar("events/degradation", 1, episode_id)
|