pypi / tianshou
tianshou
What changed in tianshou 1 to 2, from its official release notes, upgrade guides and advisories. Sources checked 2026-10-29.
38 breaking14 new APIs and options1 behavior and defaults4 fixes and other
See which of these apply to your code, ranked, in your agent:
npx @unstale/cli inittianshou 241 changes
Breaking changes 30
Compatibility was adjusted to require pandas versions below 3.
Interfaces are more well-defined and usable, parameters are extensively documented, and some parameter names are made more consistent and intuitive.
The revised hierarchy separates on-policy, off-policy, and offline algorithms at the type level and makes inheritance relationships meaningful.
Replaces the former BasePolicy abstraction; instantiate an Algorithm and pass it a Policy.
Renamed to Actor.
Renamed to max_grad_norm for consistency.
Renamed from continuous.Actor.
Renamed from continuous.ActorProb.
Removed as a member and constructor argument from the listed network and module classes.
Renamed to gamma.
Renamed to n_step_return_horizon.
Replaces trainer iterator semantics; manual trainer use should call reset followed by execute_epoch.
Removed from algorithm constructors; schedulers are handled through the factory abstractions.
Training parameters are now passed through this dedicated configuration object instead of directly as keyword arguments.
Renamed from OffpolicyTrainer; trainers now use dedicated configuration objects.
Training parameters are now passed through this dedicated configuration object instead of directly as keyword arguments.
Renamed from OnpolicyTrainer; trainers now use dedicated configuration objects.
Training parameters are now passed through this dedicated configuration object instead of directly as keyword arguments.
Algorithms now require optimizer factories rather than torch.optim.Optimizer instances; the factory creates optimizers internally.
Agents persisted with earlier versions cannot be loaded in v2.
Introduced as the policy abstraction optimized by an Algorithm.
Renamed from reset_buffer in run and reset for clarity.
Replaces run's reset_prior_to_run parameter; run now replicates reset's parameters.
Replaced by TrainingConfig and on-policy/off-policy subclasses with aligned parameter names.
Replaced by set_eps_training and set_eps_inference.
The default changed from True to False, avoiding assumptions that collection-step scores are meaningful for early stopping.
The package formerly named tianshou.policy was renamed to tianshou.algorithm, reflecting the separation between learning algorithms and policies.
Atari helper modules atari_network and atari_wrapper moved into this library package.
Replaces SamplingConfig as the high-level training configuration abstraction.
Replaces the trainer parameter update_per_step with a clearer name.
New APIs and options 8
A separate Algorithm abstraction establishes a clear separation between learning algorithms and policies.
Discrete Q-learning policies accept this parameter to set epsilon for inference separately from training.
Discrete Q-learning policies accept this parameter to set epsilon for training separately from inference.
Adds an option to customize the collector factory.
Factory abstraction for creating learning-rate schedulers through the optimizer factory setup.
Introduced as the trainer specialization for offline learning, with its own configuration class.
A separate Policy abstraction establishes a clear separation between learning algorithms and policies.
Lets an Algorithm directly initiate the learning process.
Fixes and other changes 3
Experiment.run now returns an ExperimentResult with trainer_result set.
Original policy parameters are now restored when line search fails.
Tianshou v2 is compatible with Python 3.12.
tianshou 116 changes
Breaking changes 8
The internal attribute critic1 was renamed to critic.
Support for gym environments is dropped; only Gymnasium environments are supported.
Gymnasium environments are now the only supported environment type.
Several signatures no longer accept **kwargs, including policy constructors.
Trainer functions such as offpolicy_trainer are removed in favor of the OffpolicyTrainer class and its run method.
Use the OffpolicyTrainer class and its run method in place of trainer functions such as offpolicy_trainer.
Python versions below 3.11 are no longer supported.
Training methods return dataclasses instead of dictionaries.
New APIs and options 6
A method computes an action directly from a policy's observation and can be used for unrolling.
BatchPrototypes covers fields needed and returned by methods relying on batches in a backwards-compatible way.
CalQL is supported as part of CQL.
High-level interfaces for experiments are available.
ReplayBuffer supports custom keys.
The multiprocessing context can be set explicitly for SubprocEnvWorker.
Behavior and default changes 1
critic2 no longer needs to be explicitly constructed and passed when it should use the same network as critic.
Fixes and other changes 1
The implementation uses dist.mode instead of inferring loc or argmax from the dist_fn input.