tensor-optix 2.0.8__tar.gz → 2.1.0__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.8 → tensor_optix-2.1.0}/PKG-INFO +8 -4
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/README.md +7 -3
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/pyproject.toml +1 -1
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/__init__.py +2 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/algorithms/tf_dqn.py +6 -3
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/algorithms/tf_sac.py +6 -3
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/algorithms/tf_td3.py +6 -3
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/algorithms/torch_dqn.py +6 -3
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/algorithms/torch_rainbow_dqn.py +6 -3
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/algorithms/torch_sac.py +6 -3
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/algorithms/torch_td3.py +6 -3
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/core/__init__.py +1 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/core/async_callback.py +3 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/core/backoff_scheduler.py +49 -5
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/core/base_optimizer.py +10 -1
- tensor_optix-2.1.0/tensor_optix/core/convergence.py +704 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/core/loop_controller.py +152 -131
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/core/normalizers.py +9 -1
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/core/replay_buffer.py +69 -4
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/distributed/vtrace.py +3 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/ml_core/__init__.py +53 -53
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/ml_core/base_model.py +178 -150
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/ml_core/metrics.py +201 -201
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/ml_core/trainer.py +118 -46
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/multi_agent/multi_agent_runtime.py +100 -102
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/neuroevo/controller/topology_controller.py +761 -747
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/optimizer.py +6 -6
- tensor_optix-2.1.0/tensor_optix/runtime/observer.py +109 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix.egg-info/PKG-INFO +8 -4
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix.egg-info/SOURCES.txt +1 -0
- tensor_optix-2.0.8/tensor_optix/runtime/observer.py +0 -98
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/setup.cfg +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/adapters/__init__.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/adapters/jax/__init__.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/adapters/jax/flax_agent.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/adapters/jax/flax_evaluator.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/adapters/pytorch/__init__.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/adapters/pytorch/torch_agent.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/adapters/pytorch/torch_evaluator.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/adapters/tensorflow/__init__.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/adapters/tensorflow/tf_agent.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/adapters/tensorflow/tf_evaluator.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/algorithms/__init__.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/algorithms/flax_ppo.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/algorithms/tf_ppo.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/algorithms/tf_ppo_continuous.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/algorithms/torch_ppo.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/algorithms/torch_ppo_continuous.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/algorithms/torch_recurrent_ppo.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/callbacks/__init__.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/callbacks/rich_dashboard.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/callbacks/tensorboard_callback.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/callbacks/wandb_callback.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/cli.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/config.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/core/base_agent.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/core/base_evaluator.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/core/base_pipeline.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/core/checkpoint_confirmation.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/core/checkpoint_registry.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/core/device.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/core/diagnostic_controller.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/core/ensemble_agent.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/core/her_buffer.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/core/meta_controller.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/core/noisy_linear.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/core/obs_utils.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/core/policy_manager.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/core/regime_detector.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/core/resume_state.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/core/reward_shape.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/core/trajectory_buffer.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/core/types.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/distributed/__init__.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/distributed/async_learner.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/encoders/__init__.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/encoders/obs_encoder.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/encoders/obs_encoder_tf.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/exploration/__init__.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/exploration/rnd.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/factory.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/ledger/__init__.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/ledger/callback.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/ledger/provenance.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/ledger/records.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/ledger/schema.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/ledger/store.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/ml/__init__.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/ml/dataset_pipeline.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/ml/loss_registry.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/ml/ml_agent.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/ml_core/adapters/__init__.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/ml_core/adapters/flax_model.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/ml_core/adapters/tf_model.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/ml_core/adapters/torch_model.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/ml_core/lr_schedules.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/ml_core/metrics_impl/__init__.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/ml_core/metrics_impl/classification.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/ml_core/metrics_impl/regression.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/ml_core/transfer.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/multi_agent/__init__.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/multi_agent/aec_pipeline.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/multi_agent/multi_agent_episode.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/multi_agent/parallel_pipeline.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/multi_agent/seat_env.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/multi_agent/self_play.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/nanonets/__init__.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/nanonets/abstention.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/nanonets/features.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/nanonets/pooling.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/nanonets/selector.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/nanonets/smalln.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/neuroevo/__init__.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/neuroevo/agent/__init__.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/neuroevo/agent/graph_agent.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/neuroevo/brain_network.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/neuroevo/controller/__init__.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/neuroevo/controller/topology_callback.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/neuroevo/graph/__init__.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/neuroevo/graph/neuron.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/neuroevo/graph/neuron_graph.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/neuroevo/graph/topology_ops.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/neuroevo/hebbian.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/neuroevo/neuromodulator.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/neuroevo/optimizer/__init__.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/neuroevo/optimizer/topology_aware_adam.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/optimizers/__init__.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/optimizers/adaptive_optimizer.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/optimizers/backoff_optimizer.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/optimizers/momentum_optimizer.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/optimizers/pbt_optimizer.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/optimizers/spsa_optimizer.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/orchestrator.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/pipeline/__init__.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/pipeline/batch_pipeline.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/pipeline/live_pipeline.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/pipeline/vector_pipeline.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/runtime/__init__.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/runtime/baseline.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/runtime/experiment_stage.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/runtime/live_runtime.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/runtime/promote.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/scheduler/__init__.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/scheduler/_mp_common.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/scheduler/budget.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/scheduler/dedup.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/scheduler/isolation.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/scheduler/pool.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/scheduler/retry.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/scheduler/worker.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/selection/__init__.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/selection/backfill.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/selection/selector.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/selection/uncertainty.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/simple.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/strategy/__init__.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/strategy/candidate.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/strategy/comparator.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/strategy/grammar.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/strategy/promotion.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/strategy/runner.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/strategy/worker.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/utils/__init__.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/utils/console.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix/utils/window_size.py +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix.egg-info/dependency_links.txt +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix.egg-info/entry_points.txt +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix.egg-info/requires.txt +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/tensor_optix.egg-info/top_level.txt +0 -0
- {tensor_optix-2.0.8 → tensor_optix-2.1.0}/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.1.0
|
|
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
|
|
@@ -80,11 +80,11 @@ It has two parallel cores:
|
|
|
80
80
|
- **RL core**. An episode-driven loop (`LoopController`/`RLOptimizer`) built around `BaseAgent`'s `act()`/`learn()` contract. Statistical convergence control, SPSA-based online hyperparameter tuning, and an optional neuroevolution subsystem for dynamic topology.
|
|
81
81
|
- **ML core** (`tensor_optix.ml_core`). An epoch/batch-driven loop (`Trainer`, wrapped by `BaseMLModel.fit()`) built around a sklearn-style `fit()`/`predict()`/`evaluate()` contract. Real classification metrics (accuracy, precision/recall/F1, confusion matrix) and regression metrics (MAE, RMSE, R²), validation-based early stopping, and checkpointing on the best metric.
|
|
82
82
|
|
|
83
|
-
Both cores reuse the same lower-level, algorithm-agnostic machinery: `CheckpointRegistry`, `
|
|
83
|
+
Both cores reuse the same lower-level, algorithm-agnostic machinery: `CheckpointRegistry`, the `ConvergenceMonitor` convergence detector, `SPSAOptimizer`. Each core has its own contract on top because an RL episode and a training epoch aren't the same shape. See [Concepts](https://sup3rus3r.github.io/tensor-optix/getting-started/concepts/).
|
|
84
84
|
|
|
85
85
|
## RL core
|
|
86
86
|
|
|
87
|
-
The RL loop runs your agent against a pipeline, maintains a separate validation signal, and manages four states: ACTIVE, COOLING, DORMANT, and watchdog shutdown. Convergence is detected
|
|
87
|
+
The RL loop runs your agent against a pipeline, maintains a separate validation signal, and manages four states: ACTIVE, COOLING, DORMANT, and watchdog shutdown. Convergence is detected by a `ConvergenceMonitor` that reads short, medium and long score trends together against the run's own peak, with noise and autocorrelation estimated from the curve itself. Climbing back after a dip is reported as a regression, not as improvement, and a slow learner is never declared converged while its long-scale trend is still rising (see [Concepts](https://sup3rus3r.github.io/tensor-optix/getting-started/concepts/)). Hyperparameters are updated every episode via SPSA gradient estimates, with automatic routing to momentum-based or sign-only updates depending on the autocorrelation structure of the score landscape (`AdaptiveOptimizer`). Checkpointing and rollback are driven by the validation signal only, never training score. On DORMANT, a MetaController evaluates the generalization gap and its slope to decide between spawning a policy variant, pruning the ensemble, or stopping.
|
|
88
88
|
|
|
89
89
|
The neuroevo subsystem (`pip install tensor-optix[neuroevo]`) represents the policy as a `NeuronGraph`: a mutable directed graph of heterogeneous scalar neurons (point, GRU, LSTM, trainable-GRU, trainable-LSTM) with variable-delay edges. Weights for excitatory and inhibitory neurons follow softplus Dale's Law: raw parameter θ maps to `softplus(θ)` (excitatory) or `-softplus(θ)` (inhibitory), eliminating gradient dead zones at weight boundaries. `TopologyController` runs as a loop callback and evaluates three independent signals per episode: improvement slope significance, residual autocorrelation structure, and gradient utilization across hidden neurons. All three must cross their thresholds before a grow operation fires. Pruning is by importance score (incident edge weight magnitude times mean absolute activation). Merging is by Pearson correlation of per-episode activation histories. After every structural mutation the controller calls `graph.invalidate_compile()` to reset for the new topology. `TopologyAwareAdam` resets momentum state for parameters affected by any structural change. `BrainNetwork` composes multiple named `NeuronGraph` regions with sparse learnable inter-region edges. When a neuron is pruned from a region, all inter-region edges referencing it are automatically cleaned up. `HebbianHook` accumulates co-activation products across each episode and applies an Oja-style weight update after the PPO gradient step. `NeuromodulatorSignal` maps a `RegimeDetector` output (trending / ranging / volatile) to simultaneous changes in Hebbian learning rate, entropy coefficient, and topology grow/prune thresholds.
|
|
90
90
|
|
|
@@ -130,6 +130,10 @@ history = model.fit(
|
|
|
130
130
|
epochs=50, early_stopping_patience=5, checkpoint_dir="./checkpoints",
|
|
131
131
|
)
|
|
132
132
|
print(history.val_metrics[-1].metrics) # {'accuracy': 0.94, 'f1_macro': 0.93, ...}
|
|
133
|
+
|
|
134
|
+
# or let tensor-optix decide when to stop:
|
|
135
|
+
history = model.fit((X_train, y_train), (X_val, y_val), epochs=None)
|
|
136
|
+
print(history.stop_reason) # "converged"
|
|
133
137
|
```
|
|
134
138
|
|
|
135
139
|
Metrics are auto-detected from the target dtype. Integer/class-index targets get classification metrics (accuracy, per-class and macro precision/recall/F1, confusion matrix). Float targets get regression metrics (MAE, RMSE, R²). Pass `metrics="classification"`, `metrics="regression"`, or a list of custom `(y_true, y_pred) -> float` callables to override. `TorchMLModel`, `TFMLModel`, and `FlaxMLModel` are provided. The Torch and TF adapters accept a raw `(X, y)` array pair or a native `Dataset`/`DataLoader`/`tf.data.Dataset`; the Flax adapter accepts a raw `(X, y)` array pair only. `fit()` also takes `lr_schedule=` (see `tensor_optix.ml_core.lr_schedules`), `augment=` for per-batch data augmentation, and there are `freeze_layers()`/`unfreeze_layers()`/`load_pretrained_backbone()` helpers for transfer learning. See [Train an ML model](https://sup3rus3r.github.io/tensor-optix/guides/ml-core/) for the full guide.
|
|
@@ -327,7 +331,7 @@ opt = RLOptimizer(
|
|
|
327
331
|
checkpoint_score_fn=lambda a: evaluate(a, held_out_env),
|
|
328
332
|
|
|
329
333
|
# Convergence parameters
|
|
330
|
-
dormant_threshold=
|
|
334
|
+
dormant_threshold=100, # episodes without new ground -> DORMANT (default 160)
|
|
331
335
|
min_episodes_before_dormant=50, # statistical warmup before convergence detection activates
|
|
332
336
|
)
|
|
333
337
|
|
|
@@ -9,11 +9,11 @@ It has two parallel cores:
|
|
|
9
9
|
- **RL core**. An episode-driven loop (`LoopController`/`RLOptimizer`) built around `BaseAgent`'s `act()`/`learn()` contract. Statistical convergence control, SPSA-based online hyperparameter tuning, and an optional neuroevolution subsystem for dynamic topology.
|
|
10
10
|
- **ML core** (`tensor_optix.ml_core`). An epoch/batch-driven loop (`Trainer`, wrapped by `BaseMLModel.fit()`) built around a sklearn-style `fit()`/`predict()`/`evaluate()` contract. Real classification metrics (accuracy, precision/recall/F1, confusion matrix) and regression metrics (MAE, RMSE, R²), validation-based early stopping, and checkpointing on the best metric.
|
|
11
11
|
|
|
12
|
-
Both cores reuse the same lower-level, algorithm-agnostic machinery: `CheckpointRegistry`, `
|
|
12
|
+
Both cores reuse the same lower-level, algorithm-agnostic machinery: `CheckpointRegistry`, the `ConvergenceMonitor` convergence detector, `SPSAOptimizer`. Each core has its own contract on top because an RL episode and a training epoch aren't the same shape. See [Concepts](https://sup3rus3r.github.io/tensor-optix/getting-started/concepts/).
|
|
13
13
|
|
|
14
14
|
## RL core
|
|
15
15
|
|
|
16
|
-
The RL loop runs your agent against a pipeline, maintains a separate validation signal, and manages four states: ACTIVE, COOLING, DORMANT, and watchdog shutdown. Convergence is detected
|
|
16
|
+
The RL loop runs your agent against a pipeline, maintains a separate validation signal, and manages four states: ACTIVE, COOLING, DORMANT, and watchdog shutdown. Convergence is detected by a `ConvergenceMonitor` that reads short, medium and long score trends together against the run's own peak, with noise and autocorrelation estimated from the curve itself. Climbing back after a dip is reported as a regression, not as improvement, and a slow learner is never declared converged while its long-scale trend is still rising (see [Concepts](https://sup3rus3r.github.io/tensor-optix/getting-started/concepts/)). Hyperparameters are updated every episode via SPSA gradient estimates, with automatic routing to momentum-based or sign-only updates depending on the autocorrelation structure of the score landscape (`AdaptiveOptimizer`). Checkpointing and rollback are driven by the validation signal only, never training score. On DORMANT, a MetaController evaluates the generalization gap and its slope to decide between spawning a policy variant, pruning the ensemble, or stopping.
|
|
17
17
|
|
|
18
18
|
The neuroevo subsystem (`pip install tensor-optix[neuroevo]`) represents the policy as a `NeuronGraph`: a mutable directed graph of heterogeneous scalar neurons (point, GRU, LSTM, trainable-GRU, trainable-LSTM) with variable-delay edges. Weights for excitatory and inhibitory neurons follow softplus Dale's Law: raw parameter θ maps to `softplus(θ)` (excitatory) or `-softplus(θ)` (inhibitory), eliminating gradient dead zones at weight boundaries. `TopologyController` runs as a loop callback and evaluates three independent signals per episode: improvement slope significance, residual autocorrelation structure, and gradient utilization across hidden neurons. All three must cross their thresholds before a grow operation fires. Pruning is by importance score (incident edge weight magnitude times mean absolute activation). Merging is by Pearson correlation of per-episode activation histories. After every structural mutation the controller calls `graph.invalidate_compile()` to reset for the new topology. `TopologyAwareAdam` resets momentum state for parameters affected by any structural change. `BrainNetwork` composes multiple named `NeuronGraph` regions with sparse learnable inter-region edges. When a neuron is pruned from a region, all inter-region edges referencing it are automatically cleaned up. `HebbianHook` accumulates co-activation products across each episode and applies an Oja-style weight update after the PPO gradient step. `NeuromodulatorSignal` maps a `RegimeDetector` output (trending / ranging / volatile) to simultaneous changes in Hebbian learning rate, entropy coefficient, and topology grow/prune thresholds.
|
|
19
19
|
|
|
@@ -59,6 +59,10 @@ history = model.fit(
|
|
|
59
59
|
epochs=50, early_stopping_patience=5, checkpoint_dir="./checkpoints",
|
|
60
60
|
)
|
|
61
61
|
print(history.val_metrics[-1].metrics) # {'accuracy': 0.94, 'f1_macro': 0.93, ...}
|
|
62
|
+
|
|
63
|
+
# or let tensor-optix decide when to stop:
|
|
64
|
+
history = model.fit((X_train, y_train), (X_val, y_val), epochs=None)
|
|
65
|
+
print(history.stop_reason) # "converged"
|
|
62
66
|
```
|
|
63
67
|
|
|
64
68
|
Metrics are auto-detected from the target dtype. Integer/class-index targets get classification metrics (accuracy, per-class and macro precision/recall/F1, confusion matrix). Float targets get regression metrics (MAE, RMSE, R²). Pass `metrics="classification"`, `metrics="regression"`, or a list of custom `(y_true, y_pred) -> float` callables to override. `TorchMLModel`, `TFMLModel`, and `FlaxMLModel` are provided. The Torch and TF adapters accept a raw `(X, y)` array pair or a native `Dataset`/`DataLoader`/`tf.data.Dataset`; the Flax adapter accepts a raw `(X, y)` array pair only. `fit()` also takes `lr_schedule=` (see `tensor_optix.ml_core.lr_schedules`), `augment=` for per-batch data augmentation, and there are `freeze_layers()`/`unfreeze_layers()`/`load_pretrained_backbone()` helpers for transfer learning. See [Train an ML model](https://sup3rus3r.github.io/tensor-optix/guides/ml-core/) for the full guide.
|
|
@@ -256,7 +260,7 @@ opt = RLOptimizer(
|
|
|
256
260
|
checkpoint_score_fn=lambda a: evaluate(a, held_out_env),
|
|
257
261
|
|
|
258
262
|
# Convergence parameters
|
|
259
|
-
dormant_threshold=
|
|
263
|
+
dormant_threshold=100, # episodes without new ground -> DORMANT (default 160)
|
|
260
264
|
min_episodes_before_dormant=50, # statistical warmup before convergence detection activates
|
|
261
265
|
)
|
|
262
266
|
|
|
@@ -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.1.0"
|
|
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"
|
|
@@ -11,6 +11,7 @@ from .core.base_evaluator import BaseEvaluator
|
|
|
11
11
|
from .core.base_optimizer import BaseOptimizer
|
|
12
12
|
from .core.base_pipeline import BasePipeline
|
|
13
13
|
from .core.loop_controller import LoopCallback
|
|
14
|
+
from .core.convergence import ConvergenceMonitor, ConvergenceRegime, ConvergenceReport
|
|
14
15
|
from .core.policy_manager import PolicyManager, PolicyManagerCallback
|
|
15
16
|
from .core.ensemble_agent import EnsembleAgent
|
|
16
17
|
from .core.regime_detector import RegimeDetector
|
|
@@ -28,6 +29,7 @@ __all__ = [
|
|
|
28
29
|
"EpisodeData", "EvalMetrics", "HyperparamSet", "PolicySnapshot", "LoopState",
|
|
29
30
|
"BaseAgent", "BaseEvaluator", "BaseOptimizer", "BasePipeline",
|
|
30
31
|
"LoopCallback",
|
|
32
|
+
"ConvergenceMonitor", "ConvergenceRegime", "ConvergenceReport",
|
|
31
33
|
"PolicyManager", "PolicyManagerCallback", "EnsembleAgent",
|
|
32
34
|
"RegimeDetector", "MetaController", "MetaAction",
|
|
33
35
|
"BatchPipeline", "LivePipeline",
|
|
@@ -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, window_transitions
|
|
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
|
|
|
@@ -113,7 +113,10 @@ class TFDQNAgent(BaseAgent):
|
|
|
113
113
|
# DQN pushes the RAW observation into the buffer (not pre-encoded)
|
|
114
114
|
# -- same single-network constraint as TorchDQNAgent, see
|
|
115
115
|
# torch_dqn.py's learn() comment for the full rationale.
|
|
116
|
-
|
|
116
|
+
# Window observations plus each env's post-window observation, so the
|
|
117
|
+
# last step of the window is stored too (see window_transitions).
|
|
118
|
+
window_obs, env_pair_lists = window_transitions(episode_data)
|
|
119
|
+
obs_arr = to_batch_numpy(window_obs)
|
|
117
120
|
act_arr = episode_data.actions
|
|
118
121
|
rew_arr = episode_data.rewards
|
|
119
122
|
done_arr = episode_data.dones
|
|
@@ -122,7 +125,7 @@ class TFDQNAgent(BaseAgent):
|
|
|
122
125
|
# Pair each step with the NEXT step of the same environment. With a
|
|
123
126
|
# VectorBatchPipeline window the flat arrays interleave n_envs envs
|
|
124
127
|
# ([t * n_envs + i]), so index t + 1 belongs to a different env.
|
|
125
|
-
for env_pairs in
|
|
128
|
+
for env_pairs in env_pair_lists:
|
|
126
129
|
for t, t_next in env_pairs:
|
|
127
130
|
self._buffer.push(
|
|
128
131
|
batch_index(obs_arr, t), int(act_arr[t]), float(rew_arr[t]),
|
|
@@ -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, window_transitions
|
|
10
10
|
from tensor_optix.core.obs_utils import to_batch_numpy, to_tf_batch, already_batched_to_tf
|
|
11
11
|
|
|
12
12
|
|
|
@@ -168,7 +168,10 @@ class TFSACAgent(BaseAgent):
|
|
|
168
168
|
batch_size = int(hp.get("batch_size", 256))
|
|
169
169
|
updates_per_step = float(hp.get("updates_per_step", 1))
|
|
170
170
|
|
|
171
|
-
|
|
171
|
+
# Window observations plus each env's post-window observation, so the
|
|
172
|
+
# last step of the window is stored too (see window_transitions).
|
|
173
|
+
window_obs, env_pair_lists = window_transitions(episode_data)
|
|
174
|
+
obs_batched = to_tf_batch(window_obs)
|
|
172
175
|
obs_arr = self._encode(obs_batched).numpy()
|
|
173
176
|
act_arr = np.array(episode_data.actions, dtype=np.float32)
|
|
174
177
|
rew_arr = episode_data.rewards
|
|
@@ -178,7 +181,7 @@ class TFSACAgent(BaseAgent):
|
|
|
178
181
|
# Pair each step with the NEXT step of the same environment. With a
|
|
179
182
|
# VectorBatchPipeline window the flat arrays interleave n_envs envs
|
|
180
183
|
# ([t * n_envs + i]), so index t + 1 belongs to a different env.
|
|
181
|
-
for env_pairs in
|
|
184
|
+
for env_pairs in env_pair_lists:
|
|
182
185
|
for t, t_next in env_pairs:
|
|
183
186
|
self._buffer.push(
|
|
184
187
|
obs_arr[t],
|
|
@@ -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, window_transitions
|
|
65
65
|
from tensor_optix.core.obs_utils import to_tf_batch, already_batched_to_tf
|
|
66
66
|
|
|
67
67
|
|
|
@@ -163,7 +163,10 @@ class TFTDDAgent(BaseAgent):
|
|
|
163
163
|
updates_per_step = float(hp.get("updates_per_step", 1))
|
|
164
164
|
policy_delay = int(hp.get("policy_delay", 2))
|
|
165
165
|
|
|
166
|
-
|
|
166
|
+
# Window observations plus each env's post-window observation, so the
|
|
167
|
+
# last step of the window is stored too (see window_transitions).
|
|
168
|
+
window_obs, env_pair_lists = window_transitions(episode_data)
|
|
169
|
+
obs_batched = to_tf_batch(window_obs)
|
|
167
170
|
obs_arr = self._encode(obs_batched).numpy()
|
|
168
171
|
act_arr = np.array(episode_data.actions, dtype=np.float32)
|
|
169
172
|
rew_arr = episode_data.rewards
|
|
@@ -173,7 +176,7 @@ class TFTDDAgent(BaseAgent):
|
|
|
173
176
|
# Pair each step with the NEXT step of the same environment. With a
|
|
174
177
|
# VectorBatchPipeline window the flat arrays interleave n_envs envs
|
|
175
178
|
# ([t * n_envs + i]), so index t + 1 belongs to a different env.
|
|
176
|
-
for env_pairs in
|
|
179
|
+
for env_pairs in env_pair_lists:
|
|
177
180
|
for t, t_next in env_pairs:
|
|
178
181
|
self._buffer.push(
|
|
179
182
|
obs_arr[t], act_arr[t], float(rew_arr[t]),
|
|
@@ -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, window_transitions
|
|
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
|
|
|
@@ -124,7 +124,10 @@ class TorchDQNAgent(BaseAgent):
|
|
|
124
124
|
# of being bypassed via a pre-encoded buffer (see
|
|
125
125
|
# tensor_optix.encoders' module docstring). PrioritizedReplayBuffer
|
|
126
126
|
# already supports storing dict observations for exactly this case.
|
|
127
|
-
|
|
127
|
+
# Window observations plus each env's post-window observation, so the
|
|
128
|
+
# last step of the window is stored too (see window_transitions).
|
|
129
|
+
window_obs, env_pair_lists = window_transitions(episode_data)
|
|
130
|
+
obs_arr = to_batch_numpy(window_obs)
|
|
128
131
|
act_arr = episode_data.actions
|
|
129
132
|
rew_arr = episode_data.rewards
|
|
130
133
|
done_arr = episode_data.dones
|
|
@@ -133,7 +136,7 @@ class TorchDQNAgent(BaseAgent):
|
|
|
133
136
|
# Pair each step with the NEXT step of the same environment. With a
|
|
134
137
|
# VectorBatchPipeline window the flat arrays interleave n_envs envs
|
|
135
138
|
# ([t * n_envs + i]), so index t + 1 belongs to a different env.
|
|
136
|
-
for env_pairs in
|
|
139
|
+
for env_pairs in env_pair_lists:
|
|
137
140
|
for t, t_next in env_pairs:
|
|
138
141
|
self._buffer.push(batch_index(obs_arr, t), int(act_arr[t]), float(rew_arr[t]),
|
|
139
142
|
batch_index(obs_arr, t_next), bool(done_arr[t]))
|
|
@@ -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, window_transitions
|
|
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
|
|
|
@@ -263,7 +263,10 @@ class TorchRainbowDQNAgent(BaseAgent):
|
|
|
263
263
|
# comment): q_network sees raw observations in both act() and the
|
|
264
264
|
# distributional Bellman update below, so the buffer stores the raw
|
|
265
265
|
# (possibly dict) observation rather than a pre-encoded vector.
|
|
266
|
-
|
|
266
|
+
# Window observations plus each env's post-window observation, so the
|
|
267
|
+
# last step of the window is stored too (see window_transitions).
|
|
268
|
+
window_obs, env_pair_lists = window_transitions(episode_data)
|
|
269
|
+
obs_arr = to_batch_numpy(window_obs)
|
|
267
270
|
act_arr = episode_data.actions
|
|
268
271
|
rew_arr = episode_data.rewards
|
|
269
272
|
done_arr = episode_data.dones
|
|
@@ -272,7 +275,7 @@ class TorchRainbowDQNAgent(BaseAgent):
|
|
|
272
275
|
# Pair each step with the NEXT step of the same environment. With a
|
|
273
276
|
# VectorBatchPipeline window the flat arrays interleave n_envs envs
|
|
274
277
|
# ([t * n_envs + i]), so index t + 1 belongs to a different env.
|
|
275
|
-
for env_pairs in
|
|
278
|
+
for env_pairs in env_pair_lists:
|
|
276
279
|
for t, t_next in env_pairs:
|
|
277
280
|
self._buffer.push(batch_index(obs_arr, t), int(act_arr[t]), float(rew_arr[t]),
|
|
278
281
|
batch_index(obs_arr, t_next), bool(done_arr[t]))
|
|
@@ -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, window_transitions
|
|
10
10
|
from tensor_optix.core.obs_utils import to_torch_batch, already_batched_to_torch
|
|
11
11
|
|
|
12
12
|
|
|
@@ -162,7 +162,10 @@ class TorchSACAgent(BaseAgent):
|
|
|
162
162
|
batch_size = int(hp.get("batch_size", 256))
|
|
163
163
|
updates_per_step = float(hp.get("updates_per_step", 1))
|
|
164
164
|
|
|
165
|
-
|
|
165
|
+
# Window observations plus each env's post-window observation, so the
|
|
166
|
+
# last step of the window is stored too (see window_transitions).
|
|
167
|
+
window_obs, env_pair_lists = window_transitions(episode_data)
|
|
168
|
+
obs_batched = to_torch_batch(window_obs, self._device)
|
|
166
169
|
obs_arr = self._encode(obs_batched).cpu().numpy()
|
|
167
170
|
act_arr = np.array(episode_data.actions, dtype=np.float32)
|
|
168
171
|
rew_arr = episode_data.rewards
|
|
@@ -172,7 +175,7 @@ class TorchSACAgent(BaseAgent):
|
|
|
172
175
|
# Pair each step with the NEXT step of the same environment. With a
|
|
173
176
|
# VectorBatchPipeline window the flat arrays interleave n_envs envs
|
|
174
177
|
# ([t * n_envs + i]), so index t + 1 belongs to a different env.
|
|
175
|
-
for env_pairs in
|
|
178
|
+
for env_pairs in env_pair_lists:
|
|
176
179
|
for t, t_next in env_pairs:
|
|
177
180
|
self._buffer.push(obs_arr[t], act_arr[t], float(rew_arr[t]),
|
|
178
181
|
obs_arr[t_next], float(done_arr[t]))
|
|
@@ -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, window_transitions
|
|
90
90
|
from tensor_optix.core.obs_utils import to_torch_batch, already_batched_to_torch
|
|
91
91
|
|
|
92
92
|
|
|
@@ -195,7 +195,10 @@ class TorchTD3Agent(BaseAgent):
|
|
|
195
195
|
updates_per_step = float(hp.get("updates_per_step", 1))
|
|
196
196
|
policy_delay = int(hp.get("policy_delay", 2))
|
|
197
197
|
|
|
198
|
-
|
|
198
|
+
# Window observations plus each env's post-window observation, so the
|
|
199
|
+
# last step of the window is stored too (see window_transitions).
|
|
200
|
+
window_obs, env_pair_lists = window_transitions(episode_data)
|
|
201
|
+
obs_batched = to_torch_batch(window_obs, self._device)
|
|
199
202
|
obs_arr = self._encode(obs_batched).cpu().numpy()
|
|
200
203
|
act_arr = np.array(episode_data.actions, dtype=np.float32)
|
|
201
204
|
rew_arr = episode_data.rewards
|
|
@@ -205,7 +208,7 @@ class TorchTD3Agent(BaseAgent):
|
|
|
205
208
|
# Pair each step with the NEXT step of the same environment. With a
|
|
206
209
|
# VectorBatchPipeline window the flat arrays interleave n_envs envs
|
|
207
210
|
# ([t * n_envs + i]), so index t + 1 belongs to a different env.
|
|
208
|
-
for env_pairs in
|
|
211
|
+
for env_pairs in env_pair_lists:
|
|
209
212
|
for t, t_next in env_pairs:
|
|
210
213
|
self._buffer.push(
|
|
211
214
|
obs_arr[t], act_arr[t], float(rew_arr[t]),
|
|
@@ -6,6 +6,7 @@ from .base_pipeline import BasePipeline
|
|
|
6
6
|
from .loop_controller import LoopController, LoopCallback
|
|
7
7
|
from .checkpoint_registry import CheckpointRegistry
|
|
8
8
|
from .backoff_scheduler import BackoffScheduler
|
|
9
|
+
from .convergence import ConvergenceMonitor, ConvergenceRegime, ConvergenceReport, ScaleReading
|
|
9
10
|
from .policy_manager import PolicyManager, PolicyManagerCallback
|
|
10
11
|
from .ensemble_agent import EnsembleAgent
|
|
11
12
|
from .regime_detector import RegimeDetector
|
|
@@ -108,6 +108,9 @@ class AsyncCallbackAdapter(LoopCallback):
|
|
|
108
108
|
def on_degradation(self, episode_id, eval_metrics) -> None:
|
|
109
109
|
self._enqueue("on_degradation", episode_id, eval_metrics)
|
|
110
110
|
|
|
111
|
+
def on_convergence(self, episode_id, report) -> None:
|
|
112
|
+
self._enqueue("on_convergence", episode_id, report)
|
|
113
|
+
|
|
111
114
|
def on_hyperparam_update(self, old_params, new_params) -> None:
|
|
112
115
|
self._enqueue("on_hyperparam_update", old_params, new_params)
|
|
113
116
|
|
|
@@ -1,11 +1,25 @@
|
|
|
1
1
|
from collections import deque
|
|
2
|
+
from typing import Optional
|
|
2
3
|
import numpy as np
|
|
3
4
|
from .types import LoopState
|
|
4
5
|
|
|
5
6
|
|
|
6
7
|
class BackoffScheduler:
|
|
7
8
|
"""
|
|
8
|
-
Controls
|
|
9
|
+
Controls the evaluation / adaptation interval.
|
|
10
|
+
|
|
11
|
+
Since the convergence redesign, ``LoopController`` uses this class only
|
|
12
|
+
for its *cadence* (``should_adapt`` / ``advance_interval``): when the
|
|
13
|
+
costly steps (validation pipeline, ``optimizer.suggest``) run. Convergence
|
|
14
|
+
detection and the ACTIVE / COOLING / DORMANT state live in
|
|
15
|
+
``tensor_optix.core.convergence.ConvergenceMonitor``.
|
|
16
|
+
|
|
17
|
+
The trend / state-machine methods below are kept for standalone use and
|
|
18
|
+
backward compatibility. ``plateau_threshold`` and ``dormant_threshold``,
|
|
19
|
+
when given explicitly, become the monitor's cooling / dormant patience
|
|
20
|
+
(in episodes) for the loop that owns this scheduler.
|
|
21
|
+
|
|
22
|
+
Legacy behaviour of the standalone state machine:
|
|
9
23
|
|
|
10
24
|
Improvement and degradation are detected via **linear trend** over the
|
|
11
25
|
recent score window, not point-to-point comparison.
|
|
@@ -37,8 +51,8 @@ class BackoffScheduler:
|
|
|
37
51
|
base_interval: int = 1,
|
|
38
52
|
backoff_factor: float = 2.0,
|
|
39
53
|
max_interval_episodes: int = 100,
|
|
40
|
-
plateau_threshold: int =
|
|
41
|
-
dormant_threshold: int =
|
|
54
|
+
plateau_threshold: Optional[int] = None,
|
|
55
|
+
dormant_threshold: Optional[int] = None,
|
|
42
56
|
degradation_threshold: float = 0.95,
|
|
43
57
|
min_degradation_drop: float = 1e-4,
|
|
44
58
|
min_episodes_before_dormant: int = 0,
|
|
@@ -63,8 +77,14 @@ class BackoffScheduler:
|
|
|
63
77
|
self._base_interval = base_interval
|
|
64
78
|
self._backoff_factor = backoff_factor
|
|
65
79
|
self._max_interval = max_interval_episodes
|
|
66
|
-
|
|
67
|
-
|
|
80
|
+
# None = "not set by the caller": the standalone state machine uses the
|
|
81
|
+
# historical 5 / 20, and an owning LoopController uses the monitor's
|
|
82
|
+
# own defaults instead of these.
|
|
83
|
+
self.explicit_plateau_threshold = plateau_threshold
|
|
84
|
+
self.explicit_dormant_threshold = dormant_threshold
|
|
85
|
+
self._plateau_threshold = 5 if plateau_threshold is None else int(plateau_threshold)
|
|
86
|
+
self._dormant_threshold = 20 if dormant_threshold is None else int(dormant_threshold)
|
|
87
|
+
self._monitor = None
|
|
68
88
|
self._degradation_threshold = degradation_threshold
|
|
69
89
|
self._min_degradation_drop = min_degradation_drop
|
|
70
90
|
self._min_episodes_before_dormant = min_episodes_before_dormant
|
|
@@ -247,12 +267,33 @@ class BackoffScheduler:
|
|
|
247
267
|
self._current_interval = self._base_interval
|
|
248
268
|
self._state = LoopState.ACTIVE
|
|
249
269
|
|
|
270
|
+
def attach_monitor(self, monitor) -> None:
|
|
271
|
+
"""
|
|
272
|
+
Link the ConvergenceMonitor that a LoopController built from this
|
|
273
|
+
scheduler, so code that still resets the scheduler directly (e.g.
|
|
274
|
+
TopologyController after a topology change) also restarts the
|
|
275
|
+
monitor that actually drives convergence.
|
|
276
|
+
"""
|
|
277
|
+
self._monitor = monitor
|
|
278
|
+
|
|
279
|
+
def advance_interval(self, improved: bool) -> None:
|
|
280
|
+
"""Cadence only: reset to base on progress, back off otherwise."""
|
|
281
|
+
if improved:
|
|
282
|
+
self._current_interval = self._base_interval
|
|
283
|
+
else:
|
|
284
|
+
self._current_interval = min(
|
|
285
|
+
max(1, int(self._current_interval * self._backoff_factor)),
|
|
286
|
+
self._max_interval,
|
|
287
|
+
)
|
|
288
|
+
|
|
250
289
|
def record_restart(self) -> None:
|
|
251
290
|
"""
|
|
252
291
|
Called after DORMANT fires and PolicyManager has acted.
|
|
253
292
|
Gives the new policy variant a clean slate.
|
|
254
293
|
Does NOT reset best_score — the new variant must beat the existing best.
|
|
255
294
|
"""
|
|
295
|
+
if self._monitor is not None:
|
|
296
|
+
self._monitor.restart()
|
|
256
297
|
self._consecutive_non_improvements = 0
|
|
257
298
|
self._current_interval = self._base_interval
|
|
258
299
|
self._state = LoopState.ACTIVE
|
|
@@ -265,6 +306,9 @@ class BackoffScheduler:
|
|
|
265
306
|
|
|
266
307
|
def is_converged(self, cv_threshold: float = 0.05, gap_threshold: float = 0.20) -> bool:
|
|
267
308
|
"""
|
|
309
|
+
Deprecated: no loop calls this. Use ConvergenceMonitor's report
|
|
310
|
+
(``regime == PLATEAU`` with ``state == DORMANT``) instead.
|
|
311
|
+
|
|
268
312
|
True when the policy has genuinely converged:
|
|
269
313
|
flat trend AND low CV AND performing near its personal best.
|
|
270
314
|
|
|
@@ -42,7 +42,16 @@ class BaseOptimizer(ABC):
|
|
|
42
42
|
"""Called when a new best score is achieved. Override to react."""
|
|
43
43
|
|
|
44
44
|
def on_plateau(self, metrics_history: List[EvalMetrics]) -> None:
|
|
45
|
-
"""Called when
|
|
45
|
+
"""Called when the run goes DORMANT (converged or stuck). Override to react."""
|
|
46
|
+
|
|
47
|
+
def on_cooling(self, metrics_history: List[EvalMetrics]) -> None:
|
|
48
|
+
"""
|
|
49
|
+
Called once when the run enters COOLING: no new ground for the cooling
|
|
50
|
+
patience, but not yet given up on. This is the moment to change
|
|
51
|
+
something -- by default, the same reaction as a plateau (widen the
|
|
52
|
+
search), early enough that the wider search actually gets to run.
|
|
53
|
+
"""
|
|
54
|
+
self.on_plateau(metrics_history)
|
|
46
55
|
|
|
47
56
|
@property
|
|
48
57
|
def is_probing(self) -> bool:
|