tensor-optix 2.0.3__tar.gz → 2.0.5__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.5}/PKG-INFO +52 -5
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/README.md +51 -4
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/pyproject.toml +1 -1
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/adapters/pytorch/torch_evaluator.py +9 -9
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/adapters/tensorflow/tf_evaluator.py +9 -9
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/algorithms/tf_dqn.py +11 -7
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/algorithms/tf_sac.py +14 -10
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/algorithms/tf_td3.py +19 -9
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/algorithms/torch_dqn.py +9 -5
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/algorithms/torch_rainbow_dqn.py +9 -5
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/algorithms/torch_recurrent_ppo.py +19 -1
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/algorithms/torch_sac.py +9 -5
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/algorithms/torch_td3.py +17 -7
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/callbacks/tensorboard_callback.py +7 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/callbacks/wandb_callback.py +7 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/cli.py +8 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/config.py +50 -8
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/core/backoff_scheduler.py +23 -7
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/core/base_evaluator.py +4 -1
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/core/checkpoint_registry.py +6 -1
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/core/diagnostic_controller.py +2 -1
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/core/ensemble_agent.py +12 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/core/loop_controller.py +56 -47
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/core/obs_utils.py +120 -120
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/core/policy_manager.py +32 -2
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/core/replay_buffer.py +29 -1
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/core/reward_shape.py +16 -10
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/distributed/async_learner.py +9 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/encoders/__init__.py +15 -15
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/encoders/obs_encoder.py +229 -229
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/encoders/obs_encoder_tf.py +80 -80
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/factory.py +64 -10
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/ledger/callback.py +19 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/ledger/provenance.py +19 -7
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/ml/loss_registry.py +2 -1
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/ml_core/__init__.py +53 -53
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/ml_core/adapters/flax_model.py +230 -230
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/ml_core/adapters/tf_model.py +208 -208
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/ml_core/adapters/torch_model.py +241 -241
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/ml_core/base_model.py +150 -150
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/ml_core/lr_schedules.py +67 -67
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/ml_core/metrics.py +201 -188
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/ml_core/metrics_impl/classification.py +101 -101
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/ml_core/metrics_impl/regression.py +46 -46
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/ml_core/trainer.py +240 -207
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/ml_core/transfer.py +152 -152
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/multi_agent/__init__.py +41 -34
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/multi_agent/aec_pipeline.py +191 -173
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/multi_agent/multi_agent_episode.py +18 -18
- tensor_optix-2.0.5/tensor_optix/multi_agent/multi_agent_runtime.py +359 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/multi_agent/parallel_pipeline.py +145 -145
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/multi_agent/seat_env.py +81 -81
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/nanonets/selector.py +9 -3
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/neuroevo/agent/graph_agent.py +74 -15
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/neuroevo/controller/topology_controller.py +16 -4
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/neuroevo/graph/neuron_graph.py +58 -2
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/neuroevo/graph/topology_ops.py +51 -16
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/neuroevo/hebbian.py +45 -4
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/neuroevo/neuromodulator.py +12 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/optimizer.py +17 -10
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/optimizers/backoff_optimizer.py +13 -4
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/optimizers/spsa_optimizer.py +18 -3
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/pipeline/batch_pipeline.py +5 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/pipeline/live_pipeline.py +30 -6
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/pipeline/vector_pipeline.py +19 -2
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/runtime/baseline.py +8 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/runtime/live_runtime.py +12 -4
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/scheduler/pool.py +36 -1
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/scheduler/worker.py +7 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/selection/selector.py +17 -1
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/simple.py +11 -1
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/strategy/grammar.py +8 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/strategy/worker.py +14 -0
- tensor_optix-2.0.5/tensor_optix/utils/console.py +28 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix.egg-info/PKG-INFO +52 -5
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix.egg-info/SOURCES.txt +1 -0
- tensor_optix-2.0.3/tensor_optix/multi_agent/multi_agent_runtime.py +0 -53
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/setup.cfg +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/__init__.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/adapters/__init__.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/adapters/jax/__init__.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/adapters/jax/flax_agent.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/adapters/jax/flax_evaluator.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/adapters/pytorch/__init__.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/adapters/pytorch/torch_agent.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/adapters/tensorflow/__init__.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/adapters/tensorflow/tf_agent.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/algorithms/__init__.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/algorithms/flax_ppo.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/algorithms/tf_ppo.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/algorithms/tf_ppo_continuous.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/algorithms/torch_ppo.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/algorithms/torch_ppo_continuous.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/callbacks/__init__.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/callbacks/rich_dashboard.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/core/__init__.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/core/async_callback.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/core/base_agent.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/core/base_optimizer.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/core/base_pipeline.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/core/checkpoint_confirmation.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/core/device.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/core/her_buffer.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/core/meta_controller.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/core/noisy_linear.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/core/normalizers.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/core/regime_detector.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/core/resume_state.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/core/trajectory_buffer.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/core/types.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/distributed/__init__.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/distributed/vtrace.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/exploration/__init__.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/exploration/rnd.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/ledger/__init__.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/ledger/records.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/ledger/schema.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/ledger/store.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/ml/__init__.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/ml/dataset_pipeline.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/ml/ml_agent.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/ml_core/adapters/__init__.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/ml_core/metrics_impl/__init__.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/nanonets/__init__.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/nanonets/abstention.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/nanonets/features.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/nanonets/pooling.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/nanonets/smalln.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/neuroevo/__init__.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/neuroevo/agent/__init__.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/neuroevo/brain_network.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/neuroevo/controller/__init__.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/neuroevo/controller/topology_callback.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/neuroevo/graph/__init__.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/neuroevo/graph/neuron.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/neuroevo/optimizer/__init__.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/neuroevo/optimizer/topology_aware_adam.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/optimizers/__init__.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/optimizers/adaptive_optimizer.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/optimizers/momentum_optimizer.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/optimizers/pbt_optimizer.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/orchestrator.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/pipeline/__init__.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/runtime/__init__.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/runtime/experiment_stage.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/runtime/observer.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/runtime/promote.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/scheduler/__init__.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/scheduler/_mp_common.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/scheduler/budget.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/scheduler/dedup.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/scheduler/isolation.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/scheduler/retry.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/selection/__init__.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/selection/backfill.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/selection/uncertainty.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/strategy/__init__.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/strategy/candidate.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/strategy/comparator.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/strategy/promotion.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/strategy/runner.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/utils/__init__.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/utils/window_size.py +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix.egg-info/dependency_links.txt +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix.egg-info/entry_points.txt +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix.egg-info/requires.txt +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix.egg-info/top_level.txt +0 -0
- {tensor_optix-2.0.3 → tensor_optix-2.0.5}/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.5
|
|
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
|
|
@@ -71,6 +71,8 @@ Requires-Dist: torch>=2.11.0; extra == "dev"
|
|
|
71
71
|
|
|
72
72
|
# tensor-optix
|
|
73
73
|
|
|
74
|
+
[See Documentation](https://sup3rus3r.github.io/tensor-optix/)
|
|
75
|
+
|
|
74
76
|
tensor-optix is a training framework for reinforcement learning and for supervised/unsupervised machine learning. Both have statistical convergence control, online hyperparameter optimisation, and real checkpointing.
|
|
75
77
|
|
|
76
78
|
It has two parallel cores:
|
|
@@ -162,7 +164,7 @@ pip install tensor-optix[torch]
|
|
|
162
164
|
pip install tensor-optix[all]
|
|
163
165
|
```
|
|
164
166
|
|
|
165
|
-
Environment extras: `[box2d]`, `[atari]`, `[mujoco]`
|
|
167
|
+
Environment extras: `[box2d]`, `[atari]`, `[mujoco]`, `[pettingzoo]` (multi-agent)
|
|
166
168
|
Logging extras: `[wandb]`, `[tensorboard]`
|
|
167
169
|
Export: `[onnx]`
|
|
168
170
|
|
|
@@ -194,7 +196,7 @@ All agents implement `BaseAgent` and are interchangeable with `RLOptimizer`.
|
|
|
194
196
|
|
|
195
197
|
### Auto-selection
|
|
196
198
|
|
|
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.
|
|
199
|
+
`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
200
|
|
|
199
201
|
```python
|
|
200
202
|
from tensor_optix import make_agent
|
|
@@ -280,6 +282,32 @@ pipeline = VectorBatchPipeline(
|
|
|
280
282
|
)
|
|
281
283
|
```
|
|
282
284
|
|
|
285
|
+
Notes:
|
|
286
|
+
|
|
287
|
+
- `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.
|
|
288
|
+
- `BatchPipeline` resets a recurrent agent's hidden state (`reset_hidden()`) at every episode boundary.
|
|
289
|
+
- `LivePipeline` applies backpressure: when the consumer is slower than the source, the producer waits instead of dropping samples or restarting the stream.
|
|
290
|
+
|
|
291
|
+
### Multi-agent (PettingZoo)
|
|
292
|
+
|
|
293
|
+
`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.
|
|
294
|
+
|
|
295
|
+
```python
|
|
296
|
+
from pettingzoo.classic import rps_v2
|
|
297
|
+
from tensor_optix import make_agent
|
|
298
|
+
from tensor_optix.multi_agent import SeatEnvView, AECMultiAgentPipeline, MultiAgentRunner
|
|
299
|
+
|
|
300
|
+
env = rps_v2.env()
|
|
301
|
+
env.reset(seed=0)
|
|
302
|
+
views = {aid: SeatEnvView(env, aid) for aid in env.possible_agents}
|
|
303
|
+
agents = {aid: make_agent(views[aid]) for aid in env.possible_agents}
|
|
304
|
+
|
|
305
|
+
pipeline = AECMultiAgentPipeline(env, agents, window_size=400, views=views)
|
|
306
|
+
MultiAgentRunner(pipeline, agents).run(max_windows=500)
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
In turn-based games each reward (including the terminal win/loss) is credited to the action that earned it. `MultiAgentRunner` scores every seat each window, checkpoints each seat's best weights (`checkpoint_dir=`), detects per-seat convergence with the same trend test as the single-agent loop, and stops once every seat has converged (`stop_when="any"` for the first), restoring best weights. See [Multi-agent training](https://sup3rus3r.github.io/tensor-optix/guides/multi-agent/).
|
|
310
|
+
|
|
283
311
|
---
|
|
284
312
|
|
|
285
313
|
## The loop
|
|
@@ -309,7 +337,20 @@ opt.best_snapshot # -> PolicySnapshot: best weights + EvalMetrics + Hyperparam
|
|
|
309
337
|
|
|
310
338
|
Loop state transitions: `ACTIVE` -> `COOLING` -> `DORMANT` -> watchdog shutdown or policy spawn.
|
|
311
339
|
|
|
312
|
-
|
|
340
|
+
- 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.
|
|
341
|
+
- At `DORMANT` the loop stops by default. A `PolicyManagerCallback` with spawn budget remaining spawns a variant instead and training continues.
|
|
342
|
+
- `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.
|
|
343
|
+
- On shutdown the loop restores best-known weights, not the final checkpoint.
|
|
344
|
+
- `verbose=True` prints a per-eval diagnostic block; it is safe on consoles that cannot render the box-drawing glyphs (they degrade to `?`).
|
|
345
|
+
|
|
346
|
+
### YAML / CLI
|
|
347
|
+
|
|
348
|
+
```bash
|
|
349
|
+
tensor-optix validate config.yaml
|
|
350
|
+
tensor-optix train config.yaml agent.learning_rate=1e-3 optimizer.max_episodes=200
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
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
354
|
|
|
314
355
|
---
|
|
315
356
|
|
|
@@ -372,12 +413,14 @@ best_config = orch.run()
|
|
|
372
413
|
from tensor_optix import PolicyManager
|
|
373
414
|
|
|
374
415
|
pm = PolicyManager(registry, max_spawns=4)
|
|
375
|
-
cb = pm.as_callback(agent, agent_factory=make_agent)
|
|
416
|
+
cb = pm.as_callback(agent, agent_factory=lambda: make_agent(env)) # zero-argument factory
|
|
376
417
|
cb.set_stop_fn(opt.stop)
|
|
377
418
|
opt.add_callback(cb)
|
|
378
419
|
opt.run()
|
|
379
420
|
```
|
|
380
421
|
|
|
422
|
+
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`.
|
|
423
|
+
|
|
381
424
|
---
|
|
382
425
|
|
|
383
426
|
## Callbacks
|
|
@@ -788,6 +831,8 @@ store.finalize_experiment(record.experiment_id, state=ExperimentState.COMPLETED)
|
|
|
788
831
|
|
|
789
832
|
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
833
|
|
|
834
|
+
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`.
|
|
835
|
+
|
|
791
836
|
### Concurrent trial scheduler
|
|
792
837
|
|
|
793
838
|
`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 +849,8 @@ scheduler = ConcurrentTrialScheduler(
|
|
|
804
849
|
best_params, best_score = scheduler.run()
|
|
805
850
|
```
|
|
806
851
|
|
|
852
|
+
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.
|
|
853
|
+
|
|
807
854
|
### Cross-task transfer (Nanonets)
|
|
808
855
|
|
|
809
856
|
`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.
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# tensor-optix
|
|
2
2
|
|
|
3
|
+
[See Documentation](https://sup3rus3r.github.io/tensor-optix/)
|
|
4
|
+
|
|
3
5
|
tensor-optix is a training framework for reinforcement learning and for supervised/unsupervised machine learning. Both have statistical convergence control, online hyperparameter optimisation, and real checkpointing.
|
|
4
6
|
|
|
5
7
|
It has two parallel cores:
|
|
@@ -91,7 +93,7 @@ pip install tensor-optix[torch]
|
|
|
91
93
|
pip install tensor-optix[all]
|
|
92
94
|
```
|
|
93
95
|
|
|
94
|
-
Environment extras: `[box2d]`, `[atari]`, `[mujoco]`
|
|
96
|
+
Environment extras: `[box2d]`, `[atari]`, `[mujoco]`, `[pettingzoo]` (multi-agent)
|
|
95
97
|
Logging extras: `[wandb]`, `[tensorboard]`
|
|
96
98
|
Export: `[onnx]`
|
|
97
99
|
|
|
@@ -123,7 +125,7 @@ All agents implement `BaseAgent` and are interchangeable with `RLOptimizer`.
|
|
|
123
125
|
|
|
124
126
|
### Auto-selection
|
|
125
127
|
|
|
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.
|
|
128
|
+
`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
129
|
|
|
128
130
|
```python
|
|
129
131
|
from tensor_optix import make_agent
|
|
@@ -209,6 +211,32 @@ pipeline = VectorBatchPipeline(
|
|
|
209
211
|
)
|
|
210
212
|
```
|
|
211
213
|
|
|
214
|
+
Notes:
|
|
215
|
+
|
|
216
|
+
- `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.
|
|
217
|
+
- `BatchPipeline` resets a recurrent agent's hidden state (`reset_hidden()`) at every episode boundary.
|
|
218
|
+
- `LivePipeline` applies backpressure: when the consumer is slower than the source, the producer waits instead of dropping samples or restarting the stream.
|
|
219
|
+
|
|
220
|
+
### Multi-agent (PettingZoo)
|
|
221
|
+
|
|
222
|
+
`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.
|
|
223
|
+
|
|
224
|
+
```python
|
|
225
|
+
from pettingzoo.classic import rps_v2
|
|
226
|
+
from tensor_optix import make_agent
|
|
227
|
+
from tensor_optix.multi_agent import SeatEnvView, AECMultiAgentPipeline, MultiAgentRunner
|
|
228
|
+
|
|
229
|
+
env = rps_v2.env()
|
|
230
|
+
env.reset(seed=0)
|
|
231
|
+
views = {aid: SeatEnvView(env, aid) for aid in env.possible_agents}
|
|
232
|
+
agents = {aid: make_agent(views[aid]) for aid in env.possible_agents}
|
|
233
|
+
|
|
234
|
+
pipeline = AECMultiAgentPipeline(env, agents, window_size=400, views=views)
|
|
235
|
+
MultiAgentRunner(pipeline, agents).run(max_windows=500)
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
In turn-based games each reward (including the terminal win/loss) is credited to the action that earned it. `MultiAgentRunner` scores every seat each window, checkpoints each seat's best weights (`checkpoint_dir=`), detects per-seat convergence with the same trend test as the single-agent loop, and stops once every seat has converged (`stop_when="any"` for the first), restoring best weights. See [Multi-agent training](https://sup3rus3r.github.io/tensor-optix/guides/multi-agent/).
|
|
239
|
+
|
|
212
240
|
---
|
|
213
241
|
|
|
214
242
|
## The loop
|
|
@@ -238,7 +266,20 @@ opt.best_snapshot # -> PolicySnapshot: best weights + EvalMetrics + Hyperparam
|
|
|
238
266
|
|
|
239
267
|
Loop state transitions: `ACTIVE` -> `COOLING` -> `DORMANT` -> watchdog shutdown or policy spawn.
|
|
240
268
|
|
|
241
|
-
|
|
269
|
+
- 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.
|
|
270
|
+
- At `DORMANT` the loop stops by default. A `PolicyManagerCallback` with spawn budget remaining spawns a variant instead and training continues.
|
|
271
|
+
- `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.
|
|
272
|
+
- On shutdown the loop restores best-known weights, not the final checkpoint.
|
|
273
|
+
- `verbose=True` prints a per-eval diagnostic block; it is safe on consoles that cannot render the box-drawing glyphs (they degrade to `?`).
|
|
274
|
+
|
|
275
|
+
### YAML / CLI
|
|
276
|
+
|
|
277
|
+
```bash
|
|
278
|
+
tensor-optix validate config.yaml
|
|
279
|
+
tensor-optix train config.yaml agent.learning_rate=1e-3 optimizer.max_episodes=200
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
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
283
|
|
|
243
284
|
---
|
|
244
285
|
|
|
@@ -301,12 +342,14 @@ best_config = orch.run()
|
|
|
301
342
|
from tensor_optix import PolicyManager
|
|
302
343
|
|
|
303
344
|
pm = PolicyManager(registry, max_spawns=4)
|
|
304
|
-
cb = pm.as_callback(agent, agent_factory=make_agent)
|
|
345
|
+
cb = pm.as_callback(agent, agent_factory=lambda: make_agent(env)) # zero-argument factory
|
|
305
346
|
cb.set_stop_fn(opt.stop)
|
|
306
347
|
opt.add_callback(cb)
|
|
307
348
|
opt.run()
|
|
308
349
|
```
|
|
309
350
|
|
|
351
|
+
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`.
|
|
352
|
+
|
|
310
353
|
---
|
|
311
354
|
|
|
312
355
|
## Callbacks
|
|
@@ -717,6 +760,8 @@ store.finalize_experiment(record.experiment_id, state=ExperimentState.COMPLETED)
|
|
|
717
760
|
|
|
718
761
|
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
762
|
|
|
763
|
+
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`.
|
|
764
|
+
|
|
720
765
|
### Concurrent trial scheduler
|
|
721
766
|
|
|
722
767
|
`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 +778,8 @@ scheduler = ConcurrentTrialScheduler(
|
|
|
733
778
|
best_params, best_score = scheduler.run()
|
|
734
779
|
```
|
|
735
780
|
|
|
781
|
+
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.
|
|
782
|
+
|
|
736
783
|
### Cross-task transfer (Nanonets)
|
|
737
784
|
|
|
738
785
|
`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.5"
|
|
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 {
|