tensor-optix 2.0.4__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.4 → tensor_optix-2.0.5}/PKG-INFO +4 -2
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/README.md +3 -1
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/pyproject.toml +1 -1
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/core/backoff_scheduler.py +14 -4
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/multi_agent/__init__.py +16 -9
- tensor_optix-2.0.5/tensor_optix/multi_agent/multi_agent_runtime.py +359 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/utils/console.py +28 -28
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix.egg-info/PKG-INFO +4 -2
- tensor_optix-2.0.4/tensor_optix/multi_agent/multi_agent_runtime.py +0 -53
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/setup.cfg +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/__init__.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/adapters/__init__.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/adapters/jax/__init__.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/adapters/jax/flax_agent.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/adapters/jax/flax_evaluator.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/adapters/pytorch/__init__.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/adapters/pytorch/torch_agent.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/adapters/pytorch/torch_evaluator.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/adapters/tensorflow/__init__.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/adapters/tensorflow/tf_agent.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/adapters/tensorflow/tf_evaluator.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/algorithms/__init__.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/algorithms/flax_ppo.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/algorithms/tf_dqn.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/algorithms/tf_ppo.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/algorithms/tf_ppo_continuous.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/algorithms/tf_sac.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/algorithms/tf_td3.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/algorithms/torch_dqn.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/algorithms/torch_ppo.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/algorithms/torch_ppo_continuous.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/algorithms/torch_rainbow_dqn.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/algorithms/torch_recurrent_ppo.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/algorithms/torch_sac.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/algorithms/torch_td3.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/callbacks/__init__.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/callbacks/rich_dashboard.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/callbacks/tensorboard_callback.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/callbacks/wandb_callback.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/cli.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/config.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/core/__init__.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/core/async_callback.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/core/base_agent.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/core/base_evaluator.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/core/base_optimizer.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/core/base_pipeline.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/core/checkpoint_confirmation.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/core/checkpoint_registry.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/core/device.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/core/diagnostic_controller.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/core/ensemble_agent.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/core/her_buffer.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/core/loop_controller.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/core/meta_controller.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/core/noisy_linear.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/core/normalizers.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/core/obs_utils.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/core/policy_manager.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/core/regime_detector.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/core/replay_buffer.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/core/resume_state.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/core/reward_shape.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/core/trajectory_buffer.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/core/types.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/distributed/__init__.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/distributed/async_learner.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/distributed/vtrace.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/encoders/__init__.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/encoders/obs_encoder.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/encoders/obs_encoder_tf.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/exploration/__init__.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/exploration/rnd.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/factory.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/ledger/__init__.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/ledger/callback.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/ledger/provenance.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/ledger/records.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/ledger/schema.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/ledger/store.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/ml/__init__.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/ml/dataset_pipeline.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/ml/loss_registry.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/ml/ml_agent.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/ml_core/__init__.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/ml_core/adapters/__init__.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/ml_core/adapters/flax_model.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/ml_core/adapters/tf_model.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/ml_core/adapters/torch_model.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/ml_core/base_model.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/ml_core/lr_schedules.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/ml_core/metrics.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/ml_core/metrics_impl/__init__.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/ml_core/metrics_impl/classification.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/ml_core/metrics_impl/regression.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/ml_core/trainer.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/ml_core/transfer.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/multi_agent/aec_pipeline.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/multi_agent/multi_agent_episode.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/multi_agent/parallel_pipeline.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/multi_agent/seat_env.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/nanonets/__init__.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/nanonets/abstention.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/nanonets/features.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/nanonets/pooling.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/nanonets/selector.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/nanonets/smalln.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/neuroevo/__init__.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/neuroevo/agent/__init__.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/neuroevo/agent/graph_agent.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/neuroevo/brain_network.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/neuroevo/controller/__init__.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/neuroevo/controller/topology_callback.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/neuroevo/controller/topology_controller.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/neuroevo/graph/__init__.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/neuroevo/graph/neuron.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/neuroevo/graph/neuron_graph.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/neuroevo/graph/topology_ops.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/neuroevo/hebbian.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/neuroevo/neuromodulator.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/neuroevo/optimizer/__init__.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/neuroevo/optimizer/topology_aware_adam.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/optimizer.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/optimizers/__init__.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/optimizers/adaptive_optimizer.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/optimizers/backoff_optimizer.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/optimizers/momentum_optimizer.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/optimizers/pbt_optimizer.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/optimizers/spsa_optimizer.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/orchestrator.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/pipeline/__init__.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/pipeline/batch_pipeline.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/pipeline/live_pipeline.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/pipeline/vector_pipeline.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/runtime/__init__.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/runtime/baseline.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/runtime/experiment_stage.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/runtime/live_runtime.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/runtime/observer.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/runtime/promote.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/scheduler/__init__.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/scheduler/_mp_common.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/scheduler/budget.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/scheduler/dedup.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/scheduler/isolation.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/scheduler/pool.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/scheduler/retry.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/scheduler/worker.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/selection/__init__.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/selection/backfill.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/selection/selector.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/selection/uncertainty.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/simple.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/strategy/__init__.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/strategy/candidate.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/strategy/comparator.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/strategy/grammar.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/strategy/promotion.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/strategy/runner.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/strategy/worker.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/utils/__init__.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix/utils/window_size.py +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix.egg-info/SOURCES.txt +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix.egg-info/dependency_links.txt +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix.egg-info/entry_points.txt +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix.egg-info/requires.txt +0 -0
- {tensor_optix-2.0.4 → tensor_optix-2.0.5}/tensor_optix.egg-info/top_level.txt +0 -0
- {tensor_optix-2.0.4 → 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:
|
|
@@ -304,7 +306,7 @@ pipeline = AECMultiAgentPipeline(env, agents, window_size=400, views=views)
|
|
|
304
306
|
MultiAgentRunner(pipeline, agents).run(max_windows=500)
|
|
305
307
|
```
|
|
306
308
|
|
|
307
|
-
In turn-based games each reward (including the terminal win/loss) is credited to the action that earned it. `MultiAgentRunner`
|
|
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/).
|
|
308
310
|
|
|
309
311
|
---
|
|
310
312
|
|
|
@@ -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:
|
|
@@ -233,7 +235,7 @@ pipeline = AECMultiAgentPipeline(env, agents, window_size=400, views=views)
|
|
|
233
235
|
MultiAgentRunner(pipeline, agents).run(max_windows=500)
|
|
234
236
|
```
|
|
235
237
|
|
|
236
|
-
In turn-based games each reward (including the terminal win/loss) is credited to the action that earned it. `MultiAgentRunner`
|
|
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/).
|
|
237
239
|
|
|
238
240
|
---
|
|
239
241
|
|
|
@@ -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"
|
|
@@ -23,7 +23,7 @@ class BackoffScheduler:
|
|
|
23
23
|
|
|
24
24
|
where floor_per_step = adaptive_floor / trend_window.
|
|
25
25
|
|
|
26
|
-
Adaptive floor auto-scales to env reward range (noise_k × std of recent
|
|
26
|
+
Adaptive floor auto-scales to env reward range (noise_k × detrended std of recent
|
|
27
27
|
scores), capped at 50% of |best_score| to prevent early-chaos poisoning.
|
|
28
28
|
|
|
29
29
|
State transitions:
|
|
@@ -49,7 +49,8 @@ class BackoffScheduler:
|
|
|
49
49
|
):
|
|
50
50
|
"""
|
|
51
51
|
Args:
|
|
52
|
-
noise_k: Adaptive floor multiplier. floor = noise_k × std
|
|
52
|
+
noise_k: Adaptive floor multiplier. floor = noise_k × std of the
|
|
53
|
+
scores' residuals around their linear trend.
|
|
53
54
|
score_window: Rolling window size for std / trend computation.
|
|
54
55
|
trend_window: Number of most-recent scores used for slope fit.
|
|
55
56
|
Must be ≤ score_window. Default 8 — enough to be
|
|
@@ -86,12 +87,21 @@ class BackoffScheduler:
|
|
|
86
87
|
def _adaptive_floor(self) -> float:
|
|
87
88
|
"""
|
|
88
89
|
Adaptive absolute floor for improvement margin and degradation detection.
|
|
89
|
-
Returns noise_k × std(recent scores
|
|
90
|
+
Returns noise_k × std(residuals of recent scores around their linear
|
|
91
|
+
trend), capped at 50% of |best_score|.
|
|
90
92
|
Falls back to min_degradation_drop until at least 5 scores exist.
|
|
91
93
|
"""
|
|
92
94
|
if len(self._score_window) < 5:
|
|
93
95
|
return self._min_degradation_drop
|
|
94
|
-
|
|
96
|
+
# Noise = spread of the scores AROUND their linear trend, not their raw
|
|
97
|
+
# spread. The raw std of a steadily rising series is dominated by the
|
|
98
|
+
# trend itself (std of a ramp over W points ≈ slope × W/√12), so with
|
|
99
|
+
# a full window the floor always exceeded the slope it was compared
|
|
100
|
+
# against and steady linear improvement was classified as a plateau.
|
|
101
|
+
y = np.asarray(self._score_window, dtype=np.float64)
|
|
102
|
+
x = np.arange(len(y), dtype=np.float64)
|
|
103
|
+
slope, intercept = np.polyfit(x, y, 1)
|
|
104
|
+
floor = self._noise_k * float(np.std(y - (slope * x + intercept)))
|
|
95
105
|
if self._best_score is not None and abs(self._best_score) > 1e-8:
|
|
96
106
|
floor = min(floor, 0.5 * abs(self._best_score))
|
|
97
107
|
return max(floor, self._min_degradation_drop)
|
|
@@ -11,24 +11,31 @@ Dict[AgentID, EpisodeData] (one real EpisodeData per seat) instead of a
|
|
|
11
11
|
new multi-agent EpisodeData variant, so every existing agent class's
|
|
12
12
|
learn() is reused completely unmodified.
|
|
13
13
|
|
|
14
|
-
MultiAgentRunner
|
|
15
|
-
|
|
16
|
-
checkpointing
|
|
17
|
-
|
|
18
|
-
full machinery for that seat.
|
|
14
|
+
MultiAgentRunner drives every seat's agent.learn() per window and applies
|
|
15
|
+
per-seat convergence detection (BackoffScheduler) and best-snapshot
|
|
16
|
+
checkpointing (CheckpointRegistry); the run stops when all seats (or any
|
|
17
|
+
seat, configurable) have converged, and restores each seat's best weights.
|
|
19
18
|
|
|
20
|
-
Out of scope for this package
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
Out of scope for this package: shared/self-play policies across seats,
|
|
20
|
+
online hyperparameter tuning and degradation rollback per seat, and
|
|
21
|
+
vectorizing across multiple copies of a multi-agent environment.
|
|
23
22
|
"""
|
|
24
23
|
from tensor_optix.multi_agent.seat_env import SeatEnvView
|
|
25
24
|
from tensor_optix.multi_agent.parallel_pipeline import ParallelMultiAgentPipeline
|
|
26
25
|
from tensor_optix.multi_agent.aec_pipeline import AECMultiAgentPipeline
|
|
27
|
-
from tensor_optix.multi_agent.multi_agent_runtime import
|
|
26
|
+
from tensor_optix.multi_agent.multi_agent_runtime import (
|
|
27
|
+
MultiAgentCallback,
|
|
28
|
+
MultiAgentRunResult,
|
|
29
|
+
MultiAgentRunner,
|
|
30
|
+
SeatResult,
|
|
31
|
+
)
|
|
28
32
|
|
|
29
33
|
__all__ = [
|
|
30
34
|
"SeatEnvView",
|
|
31
35
|
"ParallelMultiAgentPipeline",
|
|
32
36
|
"AECMultiAgentPipeline",
|
|
33
37
|
"MultiAgentRunner",
|
|
38
|
+
"MultiAgentCallback",
|
|
39
|
+
"MultiAgentRunResult",
|
|
40
|
+
"SeatResult",
|
|
34
41
|
]
|
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
"""
|
|
2
|
+
tensor_optix.multi_agent.multi_agent_runtime — MultiAgentRunner: the
|
|
3
|
+
multi-agent training loop.
|
|
4
|
+
|
|
5
|
+
Each seat gets the same machinery the single-agent LoopController uses,
|
|
6
|
+
applied independently per seat:
|
|
7
|
+
|
|
8
|
+
- an evaluator scoring that seat's EpisodeData every window,
|
|
9
|
+
- a BackoffScheduler doing trend-based convergence detection
|
|
10
|
+
(ACTIVE -> COOLING -> DORMANT),
|
|
11
|
+
- a CheckpointRegistry holding that seat's best snapshot.
|
|
12
|
+
|
|
13
|
+
What "converged" means for the run as a whole is an explicit choice
|
|
14
|
+
(`stop_when`): by default the run stops once EVERY seat is DORMANT — in a
|
|
15
|
+
competitive game one seat plateauing while its opponent is still improving
|
|
16
|
+
is not convergence, it is one side losing ground.
|
|
17
|
+
|
|
18
|
+
Not done here (single-agent LoopController features with no obvious
|
|
19
|
+
multi-agent meaning yet): online hyperparameter tuning, degradation
|
|
20
|
+
rollback during training, policy spawning.
|
|
21
|
+
"""
|
|
22
|
+
from __future__ import annotations
|
|
23
|
+
|
|
24
|
+
import logging
|
|
25
|
+
import os
|
|
26
|
+
from dataclasses import dataclass, field
|
|
27
|
+
from typing import Any, Dict, Hashable, List, Optional
|
|
28
|
+
|
|
29
|
+
from tensor_optix.core.backoff_scheduler import BackoffScheduler
|
|
30
|
+
from tensor_optix.core.checkpoint_registry import CheckpointRegistry
|
|
31
|
+
from tensor_optix.core.types import EvalMetrics, HyperparamSet, LoopState, PolicySnapshot
|
|
32
|
+
|
|
33
|
+
logger = logging.getLogger(__name__)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class MultiAgentCallback:
|
|
37
|
+
"""
|
|
38
|
+
Hooks into MultiAgentRunner. Subclass and override what you need
|
|
39
|
+
(any object with some of these methods also works).
|
|
40
|
+
"""
|
|
41
|
+
|
|
42
|
+
def on_run_start(self) -> None: ...
|
|
43
|
+
def on_window_end(self, window_id: int, metrics: Dict[Hashable, EvalMetrics]) -> None: ...
|
|
44
|
+
def on_improvement(self, agent_id: Hashable, snapshot: Optional[PolicySnapshot], score: float) -> None: ...
|
|
45
|
+
def on_plateau(self, agent_id: Hashable, window_id: int) -> None: ...
|
|
46
|
+
def on_converged(self, agent_id: Hashable, window_id: int) -> None: ...
|
|
47
|
+
def on_run_stop(self, reason: str) -> None: ...
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
@dataclass
|
|
51
|
+
class SeatResult:
|
|
52
|
+
"""Per-seat outcome of a run."""
|
|
53
|
+
agent_id: Hashable
|
|
54
|
+
state: LoopState
|
|
55
|
+
converged: bool
|
|
56
|
+
windows_scored: int
|
|
57
|
+
best_score: Optional[float]
|
|
58
|
+
last_score: Optional[float]
|
|
59
|
+
best_snapshot: Optional[PolicySnapshot]
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
@dataclass
|
|
63
|
+
class MultiAgentRunResult:
|
|
64
|
+
"""What run() returns."""
|
|
65
|
+
windows_run: int
|
|
66
|
+
stop_reason: str # "converged" | "max_windows" | "stopped" | "pipeline_exhausted"
|
|
67
|
+
seats: Dict[Hashable, SeatResult] = field(default_factory=dict)
|
|
68
|
+
|
|
69
|
+
@property
|
|
70
|
+
def converged(self) -> bool:
|
|
71
|
+
return self.stop_reason == "converged"
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
class _Seat:
|
|
75
|
+
def __init__(self, agent_id, agent, scheduler: BackoffScheduler, registry: Optional[CheckpointRegistry]):
|
|
76
|
+
self.agent_id = agent_id
|
|
77
|
+
self.agent = agent
|
|
78
|
+
self.scheduler = scheduler
|
|
79
|
+
self.registry = registry
|
|
80
|
+
self.best_score: Optional[float] = None
|
|
81
|
+
self.last_score: Optional[float] = None
|
|
82
|
+
self.best_snapshot: Optional[PolicySnapshot] = None
|
|
83
|
+
self.windows_scored = 0
|
|
84
|
+
self.converged = False
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
class MultiAgentRunner:
|
|
88
|
+
"""
|
|
89
|
+
Owns N agents (one per seat) and one multi-agent pipeline
|
|
90
|
+
(ParallelMultiAgentPipeline or AECMultiAgentPipeline).
|
|
91
|
+
|
|
92
|
+
Each window, for every seat that took at least one step:
|
|
93
|
+
1. agent.learn(episode_data)
|
|
94
|
+
2. score the window with `evaluator` (default: mean return of the
|
|
95
|
+
episodes that completed in the window)
|
|
96
|
+
3. checkpoint the seat if the score beats its best by more than
|
|
97
|
+
`improvement_margin` (only when `checkpoint_dir` is set)
|
|
98
|
+
4. feed the score to the seat's BackoffScheduler; a seat whose score
|
|
99
|
+
trend has been flat for `dormant_threshold` consecutive windows is
|
|
100
|
+
converged (DORMANT)
|
|
101
|
+
|
|
102
|
+
The run stops when:
|
|
103
|
+
- `stop_when="all"` (default): every seat has converged
|
|
104
|
+
- `stop_when="any"`: the first seat converges
|
|
105
|
+
- `max_windows` is reached, the pipeline ends, or stop() is called
|
|
106
|
+
Convergence stopping can be disabled with `stop_on_convergence=False`.
|
|
107
|
+
|
|
108
|
+
When the run ends and `restore_best=True` (default), every seat with a
|
|
109
|
+
checkpoint is restored to its best snapshot. Note for competitive
|
|
110
|
+
games: each seat's "best" is its best score against the opponents it
|
|
111
|
+
faced AT THAT TIME, so restored seats may come from different stages
|
|
112
|
+
of training. Pass `restore_best=False` to keep the final, jointly
|
|
113
|
+
trained weights (best snapshots stay on disk and in the result).
|
|
114
|
+
|
|
115
|
+
A seat that got no turn in a window (possible with the AEC pipeline)
|
|
116
|
+
is skipped for that window — not learned, not scored, and it does not
|
|
117
|
+
count toward that seat's plateau counter.
|
|
118
|
+
|
|
119
|
+
Args:
|
|
120
|
+
pipeline, agents: as before.
|
|
121
|
+
evaluator: a BaseEvaluator, or {agent_id: BaseEvaluator}.
|
|
122
|
+
checkpoint_dir: root directory; each seat checkpoints into
|
|
123
|
+
<checkpoint_dir>/<agent_id>. None = no
|
|
124
|
+
checkpointing (and nothing to restore).
|
|
125
|
+
max_snapshots: snapshots kept per seat.
|
|
126
|
+
improvement_margin: minimum score gain over the seat's best for
|
|
127
|
+
a new checkpoint.
|
|
128
|
+
plateau_threshold / dormant_threshold / min_windows_before_dormant /
|
|
129
|
+
noise_k / score_window / trend_window:
|
|
130
|
+
per-seat BackoffScheduler settings (same
|
|
131
|
+
meaning as RLOptimizer's). Each seat is
|
|
132
|
+
evaluated every window (no eval backoff).
|
|
133
|
+
stop_when: "all" | "any".
|
|
134
|
+
stop_on_convergence: False = only max_windows / stop() end the run.
|
|
135
|
+
restore_best: restore each seat's best snapshot at the end.
|
|
136
|
+
callbacks: MultiAgentCallback-style objects.
|
|
137
|
+
"""
|
|
138
|
+
|
|
139
|
+
def __init__(
|
|
140
|
+
self,
|
|
141
|
+
pipeline: Any,
|
|
142
|
+
agents: Dict[Hashable, Any],
|
|
143
|
+
*,
|
|
144
|
+
evaluator: Any = None,
|
|
145
|
+
checkpoint_dir: Optional[str] = None,
|
|
146
|
+
max_snapshots: int = 10,
|
|
147
|
+
improvement_margin: float = 0.0,
|
|
148
|
+
plateau_threshold: int = 5,
|
|
149
|
+
dormant_threshold: int = 20,
|
|
150
|
+
min_windows_before_dormant: int = 0,
|
|
151
|
+
noise_k: float = 2.0,
|
|
152
|
+
score_window: int = 20,
|
|
153
|
+
trend_window: int = 8,
|
|
154
|
+
stop_when: str = "all",
|
|
155
|
+
stop_on_convergence: bool = True,
|
|
156
|
+
restore_best: bool = True,
|
|
157
|
+
callbacks: Optional[List[Any]] = None,
|
|
158
|
+
) -> None:
|
|
159
|
+
if stop_when not in ("all", "any"):
|
|
160
|
+
raise ValueError(f"stop_when must be 'all' or 'any', got {stop_when!r}")
|
|
161
|
+
self._pipeline = pipeline
|
|
162
|
+
self._agents = agents
|
|
163
|
+
self._improvement_margin = improvement_margin
|
|
164
|
+
self._stop_when = stop_when
|
|
165
|
+
self._stop_on_convergence = stop_on_convergence
|
|
166
|
+
self._restore_best = restore_best
|
|
167
|
+
self._callbacks: List[Any] = list(callbacks or [])
|
|
168
|
+
self._stop_requested = False
|
|
169
|
+
|
|
170
|
+
if evaluator is None:
|
|
171
|
+
# Framework-agnostic despite the name: numpy-only mean episode return.
|
|
172
|
+
from tensor_optix.adapters.pytorch.torch_evaluator import TorchEvaluator
|
|
173
|
+
evaluator = TorchEvaluator()
|
|
174
|
+
self._evaluators: Dict[Hashable, Any] = (
|
|
175
|
+
dict(evaluator) if isinstance(evaluator, dict)
|
|
176
|
+
else {aid: evaluator for aid in agents}
|
|
177
|
+
)
|
|
178
|
+
missing = [aid for aid in agents if aid not in self._evaluators]
|
|
179
|
+
if missing:
|
|
180
|
+
raise ValueError(f"No evaluator supplied for seat(s): {missing}")
|
|
181
|
+
|
|
182
|
+
self._seats: Dict[Hashable, _Seat] = {}
|
|
183
|
+
for aid, agent in agents.items():
|
|
184
|
+
registry = None
|
|
185
|
+
if checkpoint_dir is not None:
|
|
186
|
+
registry = CheckpointRegistry(
|
|
187
|
+
os.path.join(checkpoint_dir, _safe_dirname(aid)),
|
|
188
|
+
max_snapshots=max_snapshots,
|
|
189
|
+
)
|
|
190
|
+
scheduler = BackoffScheduler(
|
|
191
|
+
base_interval=1,
|
|
192
|
+
backoff_factor=1.0, # every window is evaluated
|
|
193
|
+
plateau_threshold=plateau_threshold,
|
|
194
|
+
dormant_threshold=dormant_threshold,
|
|
195
|
+
min_episodes_before_dormant=min_windows_before_dormant,
|
|
196
|
+
noise_k=noise_k,
|
|
197
|
+
score_window=score_window,
|
|
198
|
+
trend_window=trend_window,
|
|
199
|
+
)
|
|
200
|
+
self._seats[aid] = _Seat(aid, agent, scheduler, registry)
|
|
201
|
+
|
|
202
|
+
# ------------------------------------------------------------------
|
|
203
|
+
# Public API
|
|
204
|
+
# ------------------------------------------------------------------
|
|
205
|
+
|
|
206
|
+
def stop(self) -> None:
|
|
207
|
+
"""Stop cleanly after the current window."""
|
|
208
|
+
self._stop_requested = True
|
|
209
|
+
|
|
210
|
+
def add_callback(self, callback: Any) -> None:
|
|
211
|
+
self._callbacks.append(callback)
|
|
212
|
+
|
|
213
|
+
@property
|
|
214
|
+
def states(self) -> Dict[Hashable, LoopState]:
|
|
215
|
+
return {aid: seat.scheduler.current_state for aid, seat in self._seats.items()}
|
|
216
|
+
|
|
217
|
+
@property
|
|
218
|
+
def best_snapshots(self) -> Dict[Hashable, Optional[PolicySnapshot]]:
|
|
219
|
+
return {aid: seat.best_snapshot for aid, seat in self._seats.items()}
|
|
220
|
+
|
|
221
|
+
@property
|
|
222
|
+
def best_scores(self) -> Dict[Hashable, Optional[float]]:
|
|
223
|
+
return {aid: seat.best_score for aid, seat in self._seats.items()}
|
|
224
|
+
|
|
225
|
+
def run(self, max_windows: Optional[int] = None) -> MultiAgentRunResult:
|
|
226
|
+
self._stop_requested = False
|
|
227
|
+
self._pipeline.setup()
|
|
228
|
+
self._fire("on_run_start")
|
|
229
|
+
windows_run = 0
|
|
230
|
+
stop_reason = "pipeline_exhausted"
|
|
231
|
+
try:
|
|
232
|
+
for window in self._pipeline.episodes():
|
|
233
|
+
window_metrics: Dict[Hashable, EvalMetrics] = {}
|
|
234
|
+
for aid, episode_data in window.items():
|
|
235
|
+
if len(episode_data.rewards) == 0:
|
|
236
|
+
continue
|
|
237
|
+
seat = self._seats.get(aid)
|
|
238
|
+
if seat is None:
|
|
239
|
+
continue
|
|
240
|
+
diagnostics = seat.agent.learn(episode_data) or {}
|
|
241
|
+
metrics = self._evaluators[aid].score(episode_data, diagnostics)
|
|
242
|
+
metrics.episode_id = windows_run
|
|
243
|
+
window_metrics[aid] = metrics
|
|
244
|
+
self._update_seat(seat, metrics, windows_run)
|
|
245
|
+
|
|
246
|
+
self._fire("on_window_end", windows_run, window_metrics)
|
|
247
|
+
windows_run += 1
|
|
248
|
+
|
|
249
|
+
if self._stop_requested:
|
|
250
|
+
stop_reason = "stopped"
|
|
251
|
+
break
|
|
252
|
+
if self._stop_on_convergence and self._run_converged():
|
|
253
|
+
stop_reason = "converged"
|
|
254
|
+
logger.info(
|
|
255
|
+
"MultiAgentRunner: converged after %d windows (stop_when=%s)",
|
|
256
|
+
windows_run, self._stop_when,
|
|
257
|
+
)
|
|
258
|
+
break
|
|
259
|
+
if max_windows is not None and windows_run >= max_windows:
|
|
260
|
+
stop_reason = "max_windows"
|
|
261
|
+
break
|
|
262
|
+
finally:
|
|
263
|
+
try:
|
|
264
|
+
if self._restore_best:
|
|
265
|
+
self._restore_best_weights()
|
|
266
|
+
finally:
|
|
267
|
+
self._pipeline.teardown()
|
|
268
|
+
self._fire("on_run_stop", stop_reason)
|
|
269
|
+
|
|
270
|
+
return MultiAgentRunResult(
|
|
271
|
+
windows_run=windows_run,
|
|
272
|
+
stop_reason=stop_reason,
|
|
273
|
+
seats={
|
|
274
|
+
aid: SeatResult(
|
|
275
|
+
agent_id=aid,
|
|
276
|
+
state=seat.scheduler.current_state,
|
|
277
|
+
converged=seat.converged,
|
|
278
|
+
windows_scored=seat.windows_scored,
|
|
279
|
+
best_score=seat.best_score,
|
|
280
|
+
last_score=seat.last_score,
|
|
281
|
+
best_snapshot=seat.best_snapshot,
|
|
282
|
+
)
|
|
283
|
+
for aid, seat in self._seats.items()
|
|
284
|
+
},
|
|
285
|
+
)
|
|
286
|
+
|
|
287
|
+
# ------------------------------------------------------------------
|
|
288
|
+
# Internals
|
|
289
|
+
# ------------------------------------------------------------------
|
|
290
|
+
|
|
291
|
+
def _update_seat(self, seat: _Seat, metrics: EvalMetrics, window_id: int) -> None:
|
|
292
|
+
score = float(metrics.primary_score)
|
|
293
|
+
seat.last_score = score
|
|
294
|
+
seat.windows_scored += 1
|
|
295
|
+
|
|
296
|
+
# --- checkpoint: raw score beats this seat's best ---
|
|
297
|
+
if seat.best_score is None or score > seat.best_score + self._improvement_margin:
|
|
298
|
+
seat.best_score = score
|
|
299
|
+
if seat.registry is not None:
|
|
300
|
+
seat.best_snapshot = seat.registry.save(
|
|
301
|
+
seat.agent, metrics, _hyperparams_of(seat.agent, window_id)
|
|
302
|
+
)
|
|
303
|
+
self._fire("on_improvement", seat.agent_id, seat.best_snapshot, score)
|
|
304
|
+
|
|
305
|
+
# --- convergence: trend over the seat's recent scores ---
|
|
306
|
+
sched = seat.scheduler
|
|
307
|
+
first = sched.best_score is None
|
|
308
|
+
sched.record_score(score)
|
|
309
|
+
if first or sched.is_improving():
|
|
310
|
+
sched.record_improvement(score, append=False)
|
|
311
|
+
seat.converged = False
|
|
312
|
+
return
|
|
313
|
+
|
|
314
|
+
prev_state = sched.current_state
|
|
315
|
+
sched.record_non_improvement()
|
|
316
|
+
state = sched.current_state
|
|
317
|
+
if state == LoopState.COOLING and prev_state != LoopState.COOLING:
|
|
318
|
+
self._fire("on_plateau", seat.agent_id, window_id)
|
|
319
|
+
elif state == LoopState.DORMANT and not seat.converged:
|
|
320
|
+
seat.converged = True
|
|
321
|
+
logger.info("MultiAgentRunner: seat %r converged at window %d", seat.agent_id, window_id)
|
|
322
|
+
self._fire("on_converged", seat.agent_id, window_id)
|
|
323
|
+
|
|
324
|
+
def _run_converged(self) -> bool:
|
|
325
|
+
flags = [seat.converged for seat in self._seats.values()]
|
|
326
|
+
if not flags:
|
|
327
|
+
return False
|
|
328
|
+
return all(flags) if self._stop_when == "all" else any(flags)
|
|
329
|
+
|
|
330
|
+
def _restore_best_weights(self) -> None:
|
|
331
|
+
for seat in self._seats.values():
|
|
332
|
+
if seat.registry is not None and seat.best_snapshot is not None:
|
|
333
|
+
seat.registry.load_best(seat.agent)
|
|
334
|
+
logger.info(
|
|
335
|
+
"MultiAgentRunner: seat %r restored to best snapshot (score=%.4f)",
|
|
336
|
+
seat.agent_id, seat.best_snapshot.eval_metrics.primary_score,
|
|
337
|
+
)
|
|
338
|
+
|
|
339
|
+
def _fire(self, event: str, *args) -> None:
|
|
340
|
+
for cb in self._callbacks:
|
|
341
|
+
fn = getattr(cb, event, None)
|
|
342
|
+
if fn is None:
|
|
343
|
+
continue
|
|
344
|
+
try:
|
|
345
|
+
fn(*args)
|
|
346
|
+
except Exception as exc:
|
|
347
|
+
logger.warning("MultiAgentRunner callback %s raised during %s: %s", cb, event, exc)
|
|
348
|
+
|
|
349
|
+
|
|
350
|
+
def _hyperparams_of(agent, window_id: int) -> HyperparamSet:
|
|
351
|
+
getter = getattr(agent, "get_hyperparams", None)
|
|
352
|
+
if getter is not None:
|
|
353
|
+
return getter()
|
|
354
|
+
return HyperparamSet(params={}, episode_id=window_id)
|
|
355
|
+
|
|
356
|
+
|
|
357
|
+
def _safe_dirname(agent_id: Hashable) -> str:
|
|
358
|
+
text = str(agent_id)
|
|
359
|
+
return "".join(c if (c.isalnum() or c in "-_.") else "_" for c in text) or "seat"
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
"""
|
|
2
|
-
tensor_optix.utils.console — encoding-safe console output.
|
|
3
|
-
|
|
4
|
-
Progress output uses box-drawing and arrow glyphs (━, →, ×, ✓ ...). On a
|
|
5
|
-
stream whose encoding cannot represent them — typically a Windows console or
|
|
6
|
-
a redirected/piped stdout using cp1252 — a plain print() raises
|
|
7
|
-
UnicodeEncodeError, which would abort a training run just for being verbose.
|
|
8
|
-
safe_print() degrades the unencodable characters to "?" instead.
|
|
9
|
-
"""
|
|
10
|
-
import sys
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
def safe_print(*args, sep: str = " ", end: str = "\n", file=None, flush: bool = False) -> None:
|
|
14
|
-
"""print() that never raises UnicodeEncodeError on a narrow-encoding stream."""
|
|
15
|
-
stream = file if file is not None else sys.stdout
|
|
16
|
-
if stream is None: # e.g. pythonw / detached process with no stdout
|
|
17
|
-
return
|
|
18
|
-
text = sep.join(str(a) for a in args) + end
|
|
19
|
-
try:
|
|
20
|
-
stream.write(text)
|
|
21
|
-
except UnicodeEncodeError:
|
|
22
|
-
encoding = getattr(stream, "encoding", None) or "ascii"
|
|
23
|
-
stream.write(text.encode(encoding, errors="replace").decode(encoding))
|
|
24
|
-
if flush:
|
|
25
|
-
try:
|
|
26
|
-
stream.flush()
|
|
27
|
-
except Exception:
|
|
28
|
-
pass
|
|
1
|
+
"""
|
|
2
|
+
tensor_optix.utils.console — encoding-safe console output.
|
|
3
|
+
|
|
4
|
+
Progress output uses box-drawing and arrow glyphs (━, →, ×, ✓ ...). On a
|
|
5
|
+
stream whose encoding cannot represent them — typically a Windows console or
|
|
6
|
+
a redirected/piped stdout using cp1252 — a plain print() raises
|
|
7
|
+
UnicodeEncodeError, which would abort a training run just for being verbose.
|
|
8
|
+
safe_print() degrades the unencodable characters to "?" instead.
|
|
9
|
+
"""
|
|
10
|
+
import sys
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def safe_print(*args, sep: str = " ", end: str = "\n", file=None, flush: bool = False) -> None:
|
|
14
|
+
"""print() that never raises UnicodeEncodeError on a narrow-encoding stream."""
|
|
15
|
+
stream = file if file is not None else sys.stdout
|
|
16
|
+
if stream is None: # e.g. pythonw / detached process with no stdout
|
|
17
|
+
return
|
|
18
|
+
text = sep.join(str(a) for a in args) + end
|
|
19
|
+
try:
|
|
20
|
+
stream.write(text)
|
|
21
|
+
except UnicodeEncodeError:
|
|
22
|
+
encoding = getattr(stream, "encoding", None) or "ascii"
|
|
23
|
+
stream.write(text.encode(encoding, errors="replace").decode(encoding))
|
|
24
|
+
if flush:
|
|
25
|
+
try:
|
|
26
|
+
stream.flush()
|
|
27
|
+
except Exception:
|
|
28
|
+
pass
|
|
@@ -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:
|
|
@@ -304,7 +306,7 @@ pipeline = AECMultiAgentPipeline(env, agents, window_size=400, views=views)
|
|
|
304
306
|
MultiAgentRunner(pipeline, agents).run(max_windows=500)
|
|
305
307
|
```
|
|
306
308
|
|
|
307
|
-
In turn-based games each reward (including the terminal win/loss) is credited to the action that earned it. `MultiAgentRunner`
|
|
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/).
|
|
308
310
|
|
|
309
311
|
---
|
|
310
312
|
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
tensor_optix.multi_agent.multi_agent_runtime — MultiAgentRunner: the
|
|
3
|
-
smallest possible multi-agent loop.
|
|
4
|
-
|
|
5
|
-
Deliberately NOT a multi-agent LoopController. No convergence detection,
|
|
6
|
-
no checkpointing, no rollback across seats -- those are real, separate
|
|
7
|
-
design questions (what does DORMANT mean when 3 of 5 seats are still
|
|
8
|
-
improving and 2 have plateaued?) not solved here. A caller wanting the
|
|
9
|
-
RL core's full convergence/checkpoint machinery for one seat wires up an
|
|
10
|
-
ordinary single-agent LoopController around that seat's agent themselves,
|
|
11
|
-
exactly as they would for any BaseAgent today.
|
|
12
|
-
"""
|
|
13
|
-
from __future__ import annotations
|
|
14
|
-
|
|
15
|
-
import logging
|
|
16
|
-
from typing import Any, Dict, Hashable, Optional
|
|
17
|
-
|
|
18
|
-
logger = logging.getLogger(__name__)
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
class MultiAgentRunner:
|
|
22
|
-
"""
|
|
23
|
-
Owns N agents (one per seat) and one multi-agent pipeline
|
|
24
|
-
(ParallelMultiAgentPipeline or AECMultiAgentPipeline). Drives each
|
|
25
|
-
seat's own agent.learn() call per window, independently.
|
|
26
|
-
|
|
27
|
-
run() calls agents[aid].learn(episode_data) for every aid whose
|
|
28
|
-
EpisodeData this window has at least one step (T > 0) -- an empty
|
|
29
|
-
EpisodeData (a seat that got no turns this window, possible in the
|
|
30
|
-
AEC pipeline, or that was never active in a Parallel window) is
|
|
31
|
-
skipped rather than passed to learn(), since every existing agent's
|
|
32
|
-
learn() assumes at least one step of data.
|
|
33
|
-
"""
|
|
34
|
-
|
|
35
|
-
def __init__(self, pipeline: Any, agents: Dict[Hashable, Any]) -> None:
|
|
36
|
-
self._pipeline = pipeline
|
|
37
|
-
self._agents = agents
|
|
38
|
-
|
|
39
|
-
def run(self, max_windows: Optional[int] = None) -> None:
|
|
40
|
-
self._pipeline.setup()
|
|
41
|
-
try:
|
|
42
|
-
windows_run = 0
|
|
43
|
-
for window in self._pipeline.episodes():
|
|
44
|
-
for aid, episode_data in window.items():
|
|
45
|
-
if len(episode_data.rewards) == 0:
|
|
46
|
-
continue
|
|
47
|
-
self._agents[aid].learn(episode_data)
|
|
48
|
-
|
|
49
|
-
windows_run += 1
|
|
50
|
-
if max_windows is not None and windows_run >= max_windows:
|
|
51
|
-
break
|
|
52
|
-
finally:
|
|
53
|
-
self._pipeline.teardown()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|