tt-rl 0.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.
- tt_rl-0.1.0/LICENSE +21 -0
- tt_rl-0.1.0/PKG-INFO +273 -0
- tt_rl-0.1.0/README.md +225 -0
- tt_rl-0.1.0/pyproject.toml +138 -0
- tt_rl-0.1.0/setup.cfg +4 -0
- tt_rl-0.1.0/tests/test_action_mask.py +236 -0
- tt_rl-0.1.0/tests/test_algos_clock.py +127 -0
- tt_rl-0.1.0/tests/test_algos_contract.py +237 -0
- tt_rl-0.1.0/tests/test_algos_extension.py +230 -0
- tt_rl-0.1.0/tests/test_algos_no_ttnn.py +192 -0
- tt_rl-0.1.0/tests/test_algos_registry.py +300 -0
- tt_rl-0.1.0/tests/test_algos_step_modes.py +69 -0
- tt_rl-0.1.0/tests/test_algos_transition.py +97 -0
- tt_rl-0.1.0/tests/test_import_isolation.py +120 -0
- tt_rl-0.1.0/tests/test_obs_coercion.py +203 -0
- tt_rl-0.1.0/tests/test_obs_leaves.py +293 -0
- tt_rl-0.1.0/tests/test_obs_split.py +142 -0
- tt_rl-0.1.0/tests/test_public_api.py +201 -0
- tt_rl-0.1.0/tests/test_registries_are_live.py +304 -0
- tt_rl-0.1.0/tests/test_ttnn_version.py +117 -0
- tt_rl-0.1.0/tt_rl.egg-info/PKG-INFO +273 -0
- tt_rl-0.1.0/tt_rl.egg-info/SOURCES.txt +247 -0
- tt_rl-0.1.0/tt_rl.egg-info/dependency_links.txt +1 -0
- tt_rl-0.1.0/tt_rl.egg-info/entry_points.txt +2 -0
- tt_rl-0.1.0/tt_rl.egg-info/requires.txt +34 -0
- tt_rl-0.1.0/tt_rl.egg-info/top_level.txt +1 -0
- tt_rl-0.1.0/ttrl/__init__.py +269 -0
- tt_rl-0.1.0/ttrl/algos/__init__.py +52 -0
- tt_rl-0.1.0/ttrl/algos/base.py +253 -0
- tt_rl-0.1.0/ttrl/algos/checkpoint.py +112 -0
- tt_rl-0.1.0/ttrl/algos/checks.py +131 -0
- tt_rl-0.1.0/ttrl/algos/clock.py +99 -0
- tt_rl-0.1.0/ttrl/algos/config.py +118 -0
- tt_rl-0.1.0/ttrl/algos/dqn/__init__.py +31 -0
- tt_rl-0.1.0/ttrl/algos/dqn/agent.py +265 -0
- tt_rl-0.1.0/ttrl/algos/dqn/config.py +151 -0
- tt_rl-0.1.0/ttrl/algos/dqn/losses.py +140 -0
- tt_rl-0.1.0/ttrl/algos/gaussian.py +167 -0
- tt_rl-0.1.0/ttrl/algos/grads.py +65 -0
- tt_rl-0.1.0/ttrl/algos/mask.py +165 -0
- tt_rl-0.1.0/ttrl/algos/offpolicy.py +145 -0
- tt_rl-0.1.0/ttrl/algos/ppo/__init__.py +32 -0
- tt_rl-0.1.0/ttrl/algos/ppo/agent.py +238 -0
- tt_rl-0.1.0/ttrl/algos/ppo/boundaries.py +259 -0
- tt_rl-0.1.0/ttrl/algos/ppo/build.py +37 -0
- tt_rl-0.1.0/ttrl/algos/ppo/config.py +211 -0
- tt_rl-0.1.0/ttrl/algos/ppo/learn.py +112 -0
- tt_rl-0.1.0/ttrl/algos/ppo/loss.py +83 -0
- tt_rl-0.1.0/ttrl/algos/ppo/partial.py +259 -0
- tt_rl-0.1.0/ttrl/algos/ppo/policy.py +206 -0
- tt_rl-0.1.0/ttrl/algos/ppo/recurrent.py +233 -0
- tt_rl-0.1.0/ttrl/algos/ppo/state.py +65 -0
- tt_rl-0.1.0/ttrl/algos/registry.py +51 -0
- tt_rl-0.1.0/ttrl/algos/sac/__init__.py +30 -0
- tt_rl-0.1.0/ttrl/algos/sac/agent.py +296 -0
- tt_rl-0.1.0/ttrl/algos/sac/config.py +183 -0
- tt_rl-0.1.0/ttrl/algos/sac/losses.py +94 -0
- tt_rl-0.1.0/ttrl/algos/sac/policy.py +59 -0
- tt_rl-0.1.0/ttrl/algos/sac/step.py +130 -0
- tt_rl-0.1.0/ttrl/algos/sac/targets.py +96 -0
- tt_rl-0.1.0/ttrl/algos/scaling.py +101 -0
- tt_rl-0.1.0/ttrl/buffers/__init__.py +21 -0
- tt_rl-0.1.0/ttrl/buffers/boundaries.py +106 -0
- tt_rl-0.1.0/ttrl/buffers/checks.py +130 -0
- tt_rl-0.1.0/ttrl/buffers/indexing.py +131 -0
- tt_rl-0.1.0/ttrl/buffers/openepisodes.py +55 -0
- tt_rl-0.1.0/ttrl/buffers/persist.py +239 -0
- tt_rl-0.1.0/ttrl/buffers/replay.py +282 -0
- tt_rl-0.1.0/ttrl/buffers/replaybatch.py +76 -0
- tt_rl-0.1.0/ttrl/buffers/rollout.py +290 -0
- tt_rl-0.1.0/ttrl/buffers/samplers.py +168 -0
- tt_rl-0.1.0/ttrl/buffers/sampling.py +258 -0
- tt_rl-0.1.0/ttrl/buffers/seqbatch.py +120 -0
- tt_rl-0.1.0/ttrl/buffers/sequences.py +202 -0
- tt_rl-0.1.0/ttrl/buffers/types.py +161 -0
- tt_rl-0.1.0/ttrl/buffers/window.py +179 -0
- tt_rl-0.1.0/ttrl/buffers/writes.py +70 -0
- tt_rl-0.1.0/ttrl/cli/__init__.py +46 -0
- tt_rl-0.1.0/ttrl/cli/__main__.py +7 -0
- tt_rl-0.1.0/ttrl/cli/doctor.py +52 -0
- tt_rl-0.1.0/ttrl/cli/logs.py +49 -0
- tt_rl-0.1.0/ttrl/cli/probes/__init__.py +1 -0
- tt_rl-0.1.0/ttrl/cli/probes/_ttnn.py +21 -0
- tt_rl-0.1.0/ttrl/cli/probes/chip_report.py +90 -0
- tt_rl-0.1.0/ttrl/cli/probes/chips.py +91 -0
- tt_rl-0.1.0/ttrl/cli/probes/extras.py +57 -0
- tt_rl-0.1.0/ttrl/cli/probes/hardware.py +151 -0
- tt_rl-0.1.0/ttrl/cli/probes/traps.py +81 -0
- tt_rl-0.1.0/ttrl/cli/probes/versions.py +207 -0
- tt_rl-0.1.0/ttrl/cli/report.py +103 -0
- tt_rl-0.1.0/ttrl/cli/train.py +210 -0
- tt_rl-0.1.0/ttrl/deploy/__init__.py +47 -0
- tt_rl-0.1.0/ttrl/deploy/artifact.py +283 -0
- tt_rl-0.1.0/ttrl/deploy/conv.py +69 -0
- tt_rl-0.1.0/ttrl/deploy/export.py +240 -0
- tt_rl-0.1.0/ttrl/deploy/graph.py +285 -0
- tt_rl-0.1.0/ttrl/deploy/policies.py +115 -0
- tt_rl-0.1.0/ttrl/deploy/read.py +75 -0
- tt_rl-0.1.0/ttrl/deploy/towers.py +73 -0
- tt_rl-0.1.0/ttrl/deploy/transform.py +108 -0
- tt_rl-0.1.0/ttrl/engine/__init__.py +96 -0
- tt_rl-0.1.0/ttrl/engine/autograd.py +271 -0
- tt_rl-0.1.0/ttrl/engine/carry.py +165 -0
- tt_rl-0.1.0/ttrl/engine/config.py +23 -0
- tt_rl-0.1.0/ttrl/engine/conv/__init__.py +77 -0
- tt_rl-0.1.0/ttrl/engine/conv/backward.py +78 -0
- tt_rl-0.1.0/ttrl/engine/conv/config.py +144 -0
- tt_rl-0.1.0/ttrl/engine/conv/forward.py +205 -0
- tt_rl-0.1.0/ttrl/engine/conv/geometry.py +277 -0
- tt_rl-0.1.0/ttrl/engine/conv/module.py +263 -0
- tt_rl-0.1.0/ttrl/engine/conv/packing.py +187 -0
- tt_rl-0.1.0/ttrl/engine/conv/transform.py +277 -0
- tt_rl-0.1.0/ttrl/engine/conv/weights.py +238 -0
- tt_rl-0.1.0/ttrl/engine/device/__init__.py +71 -0
- tt_rl-0.1.0/ttrl/engine/device/acquire.py +140 -0
- tt_rl-0.1.0/ttrl/engine/device/liveness.py +299 -0
- tt_rl-0.1.0/ttrl/engine/device/profile.py +77 -0
- tt_rl-0.1.0/ttrl/engine/device/scope.py +229 -0
- tt_rl-0.1.0/ttrl/engine/layers.py +200 -0
- tt_rl-0.1.0/ttrl/engine/mesh/__init__.py +44 -0
- tt_rl-0.1.0/ttrl/engine/mesh/devices.py +116 -0
- tt_rl-0.1.0/ttrl/engine/mesh/open.py +187 -0
- tt_rl-0.1.0/ttrl/engine/mesh/resume.py +100 -0
- tt_rl-0.1.0/ttrl/engine/mesh/sync.py +249 -0
- tt_rl-0.1.0/ttrl/engine/mesh/topology.py +128 -0
- tt_rl-0.1.0/ttrl/engine/nn/__init__.py +6 -0
- tt_rl-0.1.0/ttrl/engine/nn/containers.py +84 -0
- tt_rl-0.1.0/ttrl/engine/nn/discovery.py +163 -0
- tt_rl-0.1.0/ttrl/engine/nn/module.py +190 -0
- tt_rl-0.1.0/ttrl/engine/ops/__init__.py +44 -0
- tt_rl-0.1.0/ttrl/engine/ops/broadcast.py +55 -0
- tt_rl-0.1.0/ttrl/engine/ops/elementwise.py +148 -0
- tt_rl-0.1.0/ttrl/engine/ops/functional.py +195 -0
- tt_rl-0.1.0/ttrl/engine/ops/matmul.py +86 -0
- tt_rl-0.1.0/ttrl/engine/ops/reduce.py +99 -0
- tt_rl-0.1.0/ttrl/engine/ops/select.py +63 -0
- tt_rl-0.1.0/ttrl/engine/ops/shape.py +151 -0
- tt_rl-0.1.0/ttrl/engine/ops/unary.py +150 -0
- tt_rl-0.1.0/ttrl/engine/optim/__init__.py +7 -0
- tt_rl-0.1.0/ttrl/engine/optim/adam.py +137 -0
- tt_rl-0.1.0/ttrl/engine/optim/base.py +15 -0
- tt_rl-0.1.0/ttrl/engine/optim/checkpoint.py +104 -0
- tt_rl-0.1.0/ttrl/engine/optim/scalars.py +27 -0
- tt_rl-0.1.0/ttrl/engine/recurrent.py +168 -0
- tt_rl-0.1.0/ttrl/engine/step/__init__.py +7 -0
- tt_rl-0.1.0/ttrl/engine/step/core.py +160 -0
- tt_rl-0.1.0/ttrl/engine/step/inputs.py +102 -0
- tt_rl-0.1.0/ttrl/engine/step/metrics.py +112 -0
- tt_rl-0.1.0/ttrl/engine/tensor/__init__.py +26 -0
- tt_rl-0.1.0/ttrl/engine/tensor/arena.py +87 -0
- tt_rl-0.1.0/ttrl/engine/tensor/precision.py +28 -0
- tt_rl-0.1.0/ttrl/engine/tensor/transfer.py +51 -0
- tt_rl-0.1.0/ttrl/engine/trace.py +126 -0
- tt_rl-0.1.0/ttrl/envs/__init__.py +87 -0
- tt_rl-0.1.0/ttrl/envs/_children.py +145 -0
- tt_rl-0.1.0/ttrl/envs/_worker.py +85 -0
- tt_rl-0.1.0/ttrl/envs/atari/__init__.py +141 -0
- tt_rl-0.1.0/ttrl/envs/atari/emulator.py +77 -0
- tt_rl-0.1.0/ttrl/envs/atari/wrappers.py +220 -0
- tt_rl-0.1.0/ttrl/envs/base.py +190 -0
- tt_rl-0.1.0/ttrl/envs/bounds.py +98 -0
- tt_rl-0.1.0/ttrl/envs/check.py +173 -0
- tt_rl-0.1.0/ttrl/envs/check_clauses.py +201 -0
- tt_rl-0.1.0/ttrl/envs/episodes.py +125 -0
- tt_rl-0.1.0/ttrl/envs/gym_adapter.py +154 -0
- tt_rl-0.1.0/ttrl/envs/mujoco.py +229 -0
- tt_rl-0.1.0/ttrl/envs/obs_batch.py +76 -0
- tt_rl-0.1.0/ttrl/envs/registry.py +96 -0
- tt_rl-0.1.0/ttrl/envs/render.py +77 -0
- tt_rl-0.1.0/ttrl/envs/running.py +108 -0
- tt_rl-0.1.0/ttrl/envs/vec_normalize.py +292 -0
- tt_rl-0.1.0/ttrl/envs/vec_wrapper.py +152 -0
- tt_rl-0.1.0/ttrl/envs/vector.py +223 -0
- tt_rl-0.1.0/ttrl/envs/vector_async.py +212 -0
- tt_rl-0.1.0/ttrl/envs/wrappers/__init__.py +45 -0
- tt_rl-0.1.0/ttrl/envs/wrappers/control.py +137 -0
- tt_rl-0.1.0/ttrl/envs/wrappers/core.py +299 -0
- tt_rl-0.1.0/ttrl/envs/wrappers/leaf.py +85 -0
- tt_rl-0.1.0/ttrl/envs/wrappers/observation.py +133 -0
- tt_rl-0.1.0/ttrl/envs/wrappers/privileged.py +73 -0
- tt_rl-0.1.0/ttrl/envs/wrappers/reward.py +57 -0
- tt_rl-0.1.0/ttrl/nets/__init__.py +100 -0
- tt_rl-0.1.0/ttrl/nets/acting.py +188 -0
- tt_rl-0.1.0/ttrl/nets/build.py +215 -0
- tt_rl-0.1.0/ttrl/nets/choice.py +130 -0
- tt_rl-0.1.0/ttrl/nets/encoders.py +237 -0
- tt_rl-0.1.0/ttrl/nets/fusion.py +71 -0
- tt_rl-0.1.0/ttrl/nets/heads.py +116 -0
- tt_rl-0.1.0/ttrl/nets/models.py +135 -0
- tt_rl-0.1.0/ttrl/nets/multi.py +145 -0
- tt_rl-0.1.0/ttrl/nets/obs.py +213 -0
- tt_rl-0.1.0/ttrl/nets/recurrent.py +196 -0
- tt_rl-0.1.0/ttrl/nets/registry.py +241 -0
- tt_rl-0.1.0/ttrl/nets/towers.py +60 -0
- tt_rl-0.1.0/ttrl/spaces/__init__.py +29 -0
- tt_rl-0.1.0/ttrl/spaces/action.py +169 -0
- tt_rl-0.1.0/ttrl/spaces/fields.py +96 -0
- tt_rl-0.1.0/ttrl/spaces/group.py +239 -0
- tt_rl-0.1.0/ttrl/spaces/mask.py +89 -0
- tt_rl-0.1.0/ttrl/spaces/obs.py +266 -0
- tt_rl-0.1.0/ttrl/spaces/observation.py +241 -0
- tt_rl-0.1.0/ttrl/spaces/refusals.py +88 -0
- tt_rl-0.1.0/ttrl/train/__init__.py +64 -0
- tt_rl-0.1.0/ttrl/train/builders.py +146 -0
- tt_rl-0.1.0/ttrl/train/cadence.py +258 -0
- tt_rl-0.1.0/ttrl/train/checkpoint/__init__.py +52 -0
- tt_rl-0.1.0/ttrl/train/checkpoint/atomic.py +37 -0
- tt_rl-0.1.0/ttrl/train/checkpoint/best.py +279 -0
- tt_rl-0.1.0/ttrl/train/checkpoint/file.py +218 -0
- tt_rl-0.1.0/ttrl/train/checkpoint/history.py +103 -0
- tt_rl-0.1.0/ttrl/train/checkpoint/read.py +104 -0
- tt_rl-0.1.0/ttrl/train/checkpoint/retype.py +47 -0
- tt_rl-0.1.0/ttrl/train/checkpoint/specs.py +62 -0
- tt_rl-0.1.0/ttrl/train/checkpoint/tree.py +261 -0
- tt_rl-0.1.0/ttrl/train/checkpoint/types.py +67 -0
- tt_rl-0.1.0/ttrl/train/config/__init__.py +24 -0
- tt_rl-0.1.0/ttrl/train/config/coerce.py +222 -0
- tt_rl-0.1.0/ttrl/train/config/device.py +127 -0
- tt_rl-0.1.0/ttrl/train/config/env.py +152 -0
- tt_rl-0.1.0/ttrl/train/config/horizon.py +75 -0
- tt_rl-0.1.0/ttrl/train/config/loader.py +160 -0
- tt_rl-0.1.0/ttrl/train/config/overrides.py +129 -0
- tt_rl-0.1.0/ttrl/train/config/schema.py +279 -0
- tt_rl-0.1.0/ttrl/train/device.py +68 -0
- tt_rl-0.1.0/ttrl/train/eval_checkpoint.py +120 -0
- tt_rl-0.1.0/ttrl/train/eval_metrics.py +64 -0
- tt_rl-0.1.0/ttrl/train/evaluate.py +208 -0
- tt_rl-0.1.0/ttrl/train/film.py +182 -0
- tt_rl-0.1.0/ttrl/train/gitstate.py +141 -0
- tt_rl-0.1.0/ttrl/train/hooks.py +62 -0
- tt_rl-0.1.0/ttrl/train/logging.py +294 -0
- tt_rl-0.1.0/ttrl/train/loop.py +266 -0
- tt_rl-0.1.0/ttrl/train/periodic.py +74 -0
- tt_rl-0.1.0/ttrl/train/provenance.py +218 -0
- tt_rl-0.1.0/ttrl/train/record.py +251 -0
- tt_rl-0.1.0/ttrl/train/record_env.py +67 -0
- tt_rl-0.1.0/ttrl/train/replicas.py +289 -0
- tt_rl-0.1.0/ttrl/train/restore.py +117 -0
- tt_rl-0.1.0/ttrl/train/resume.py +210 -0
- tt_rl-0.1.0/ttrl/train/resume_env.py +161 -0
- tt_rl-0.1.0/ttrl/train/run.py +96 -0
- tt_rl-0.1.0/ttrl/train/scoping.py +110 -0
- tt_rl-0.1.0/ttrl/train/snapshot.py +137 -0
- tt_rl-0.1.0/ttrl/train/stop.py +144 -0
- tt_rl-0.1.0/ttrl/train/teardown.py +148 -0
- tt_rl-0.1.0/ttrl/train/throughput.py +64 -0
- tt_rl-0.1.0/ttrl/train/trackers.py +125 -0
- tt_rl-0.1.0/ttrl/train/trainer.py +299 -0
- tt_rl-0.1.0/ttrl/train/video.py +46 -0
tt_rl-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Antoni Bertel
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
tt_rl-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tt-rl
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Reinforcement learning on Tenstorrent, natively on TT-NN
|
|
5
|
+
Author: Antoni Bertel
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/scaleresearch/tt-rl
|
|
8
|
+
Project-URL: Repository, https://github.com/scaleresearch/tt-rl
|
|
9
|
+
Project-URL: Issues, https://github.com/scaleresearch/tt-rl/issues
|
|
10
|
+
Keywords: reinforcement-learning,tenstorrent,ttnn,blackhole,rl
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Science/Research
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
16
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
17
|
+
Requires-Python: <3.13,>=3.12
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE
|
|
20
|
+
Requires-Dist: ttnn<0.81,>=0.80.0
|
|
21
|
+
Requires-Dist: numpy<2,>=1.26
|
|
22
|
+
Provides-Extra: atari
|
|
23
|
+
Requires-Dist: gymnasium[atari]>=1.4; extra == "atari"
|
|
24
|
+
Requires-Dist: ale-py>=0.12; extra == "atari"
|
|
25
|
+
Requires-Dist: opencv-python-headless>=4.11; extra == "atari"
|
|
26
|
+
Provides-Extra: mujoco
|
|
27
|
+
Requires-Dist: gymnasium[mujoco]>=1.4; extra == "mujoco"
|
|
28
|
+
Requires-Dist: mujoco<4,>=3.17; extra == "mujoco"
|
|
29
|
+
Requires-Dist: opencv-python-headless>=4.11; extra == "mujoco"
|
|
30
|
+
Provides-Extra: logging
|
|
31
|
+
Requires-Dist: tensorboard>=2.21; extra == "logging"
|
|
32
|
+
Provides-Extra: tracker
|
|
33
|
+
Requires-Dist: wandb>=0.19; extra == "tracker"
|
|
34
|
+
Provides-Extra: plots
|
|
35
|
+
Requires-Dist: matplotlib>=3.9; extra == "plots"
|
|
36
|
+
Provides-Extra: onnx
|
|
37
|
+
Requires-Dist: onnx>=1.21; extra == "onnx"
|
|
38
|
+
Provides-Extra: dev
|
|
39
|
+
Requires-Dist: pytest>=9; extra == "dev"
|
|
40
|
+
Requires-Dist: torch>=2.14; extra == "dev"
|
|
41
|
+
Requires-Dist: tensorboard>=2.21; extra == "dev"
|
|
42
|
+
Requires-Dist: matplotlib>=3.9; extra == "dev"
|
|
43
|
+
Requires-Dist: tt-rl[onnx]; extra == "dev"
|
|
44
|
+
Requires-Dist: onnxruntime>=1.20; extra == "dev"
|
|
45
|
+
Requires-Dist: tt-rl[atari]; extra == "dev"
|
|
46
|
+
Requires-Dist: tt-rl[mujoco]; extra == "dev"
|
|
47
|
+
Dynamic: license-file
|
|
48
|
+
|
|
49
|
+
# tt-rl
|
|
50
|
+
|
|
51
|
+
[](https://github.com/scaleresearch/tt-rl/actions/workflows/ci.yml)
|
|
52
|
+
[](LICENSE)
|
|
53
|
+
|
|
54
|
+
Reinforcement learning on Tenstorrent hardware, built directly on
|
|
55
|
+
[TT-NN](https://github.com/tenstorrent/tt-metal). Networks, gradients, the Adam
|
|
56
|
+
step and the device trace all run on the chip through `ttnn`. Environments
|
|
57
|
+
and replay buffers stay on the host.
|
|
58
|
+
|
|
59
|
+
<table>
|
|
60
|
+
<tr>
|
|
61
|
+
<td align="center"><img src="https://raw.githubusercontent.com/scaleresearch/tt-rl/master/assets/pong.gif" height="260" alt="Pong"><br>Pong, DQN</td>
|
|
62
|
+
<td align="center"><img src="https://raw.githubusercontent.com/scaleresearch/tt-rl/master/assets/breakout.gif" height="260" alt="Breakout"><br>Breakout, DQN</td>
|
|
63
|
+
<td align="center"><img src="https://raw.githubusercontent.com/scaleresearch/tt-rl/master/assets/boxing.gif" height="260" alt="Boxing"><br>Boxing, DQN</td>
|
|
64
|
+
<td align="center"><img src="https://raw.githubusercontent.com/scaleresearch/tt-rl/master/assets/hopper.gif" height="260" alt="Hopper"><br>Hopper, SAC</td>
|
|
65
|
+
</tr>
|
|
66
|
+
</table>
|
|
67
|
+
|
|
68
|
+
- **Algorithms:** DQN (double, n-step, prioritized replay), PPO (GAE, clipping,
|
|
69
|
+
optional GRU memory) and SAC (twin critics, learned temperature).
|
|
70
|
+
- **Environments:** Atari pixels, MuJoCo state vectors, and any environment you
|
|
71
|
+
write against a small protocol.
|
|
72
|
+
- **Single or multiple chips:** a run trains on one chip, or data-parallel
|
|
73
|
+
across several with one replica per chip.
|
|
74
|
+
- **Deploy anywhere:** export a trained policy to numpy or ONNX and run it on
|
|
75
|
+
any CPU.
|
|
76
|
+
|
|
77
|
+
## Results
|
|
78
|
+
|
|
79
|
+
Measured on one Blackhole chip. Atari scores are the mean over 30 evaluation
|
|
80
|
+
episodes with sticky actions (0.25), which is harder than the
|
|
81
|
+
`NoFrameskip-v4` setting most published numbers use. A step is one agent
|
|
82
|
+
action, four Atari frames. Each score is the best evaluation of its run.
|
|
83
|
+
|
|
84
|
+
| Task | Algorithm | Steps | Score | Weights |
|
|
85
|
+
|---|---|---|---|---|
|
|
86
|
+
| Pong | DQN | 10M | 17.8 | [ttrl-dqn-pong](https://huggingface.co/scaleresearch/ttrl-dqn-pong) |
|
|
87
|
+
| Breakout | DQN | 10M | 144.8 | [ttrl-dqn-breakout](https://huggingface.co/scaleresearch/ttrl-dqn-breakout) |
|
|
88
|
+
| Boxing | DQN | 10M | 91.0 | [ttrl-dqn-boxing](https://huggingface.co/scaleresearch/ttrl-dqn-boxing) |
|
|
89
|
+
| Hopper-v5 | SAC | 1M | 3604 | [ttrl-sac-hopper](https://huggingface.co/scaleresearch/ttrl-sac-hopper) |
|
|
90
|
+
|
|
91
|
+
Each config in `configs/` records how it was measured in its docstring. The
|
|
92
|
+
trained policies are on Hugging Face as ONNX and numpy weights, with a
|
|
93
|
+
`play.py` that runs them on CPU.
|
|
94
|
+
|
|
95
|
+
### Learning
|
|
96
|
+
|
|
97
|
+
From an untrained agent to the final one, at fixed checkpoints of the same
|
|
98
|
+
run (Atari clips play at 3x speed):
|
|
99
|
+
|
|
100
|
+

|
|
101
|
+
|
|
102
|
+

|
|
103
|
+
|
|
104
|
+
<details>
|
|
105
|
+
<summary>Breakout and Boxing</summary>
|
|
106
|
+
|
|
107
|
+

|
|
108
|
+
|
|
109
|
+

|
|
110
|
+
|
|
111
|
+
</details>
|
|
112
|
+
|
|
113
|
+
## Requirements
|
|
114
|
+
|
|
115
|
+
- Linux and Python 3.12. `ttnn` 0.80 ships wheels for 3.10 and 3.12, and
|
|
116
|
+
3.10 is dropped because current Pillow and filelock no longer support it.
|
|
117
|
+
- A Tenstorrent Blackhole chip with its driver and firmware installed.
|
|
118
|
+
Developed on a TT-QuietBox with four Blackhole chips.
|
|
119
|
+
|
|
120
|
+
## Install
|
|
121
|
+
|
|
122
|
+
ttrl installs from source for now. A PyPI release as `tt-rl` is on its way,
|
|
123
|
+
after which `pip install tt-rl` will be enough.
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
git clone https://github.com/scaleresearch/tt-rl && cd tt-rl
|
|
127
|
+
pip install -e '.[atari]' # Atari
|
|
128
|
+
pip install -e '.[mujoco]' # MuJoCo
|
|
129
|
+
pip install -e '.[dev]' # both, plus the test suite's dependencies
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
`ttnn` installs from PyPI as a dependency. Then check the machine:
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
ttrl doctor
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
It reports versions, which chips exist and who holds each one, and opens a
|
|
139
|
+
free chip to confirm a trace captures and replays.
|
|
140
|
+
|
|
141
|
+
## Train
|
|
142
|
+
|
|
143
|
+
A run is a Python config. Arguments after the path override any field by
|
|
144
|
+
its dotted name:
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
ttrl train configs/pong_dqn.py device.chip=0
|
|
148
|
+
ttrl train configs/pong_dqn.py total_frames=3000 algo_cfg.learning_starts=500 log_dir=runs/smoke
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
The same from Python:
|
|
152
|
+
|
|
153
|
+
```python
|
|
154
|
+
import ttrl
|
|
155
|
+
|
|
156
|
+
config = ttrl.load_config("configs/pong_dqn.py", overrides=["device.chip=0"])
|
|
157
|
+
result = ttrl.run(config)
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
A run writes metrics, checkpoints and `checkpoint-best.npz` to its
|
|
161
|
+
`log_dir`. `ttrl train --resume best <config>` continues from the best one;
|
|
162
|
+
DQN and SAC runs also need `checkpoint_replay=True` so the replay buffer is
|
|
163
|
+
saved with them.
|
|
164
|
+
`examples/atari-dqn` and `examples/mujoco-sac` are standalone projects that
|
|
165
|
+
use ttrl as a library.
|
|
166
|
+
|
|
167
|
+
A chip is exclusive to one process. `device.chip=N` names a physical chip,
|
|
168
|
+
the `N` in `/dev/tenstorrent/N`; leave it unset to take the lowest free one.
|
|
169
|
+
|
|
170
|
+
### Multiple chips
|
|
171
|
+
|
|
172
|
+
`device.chips` trains one replica per chip. Each replica steps its own
|
|
173
|
+
environments and runs its own updates, and every `device.sync_every` updates
|
|
174
|
+
(50 by default) the replicas average their parameters, so they stay one model.
|
|
175
|
+
|
|
176
|
+
```bash
|
|
177
|
+
ttrl train configs/pong_ppo.py device.chips=4 # any 4 chips
|
|
178
|
+
ttrl train configs/pong_ppo.py device.chips=all # every chip on the machine
|
|
179
|
+
ttrl train configs/pong_ppo.py 'device.chips=[0,1]' # these physical chips
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
```python
|
|
183
|
+
config = ttrl.load_config("configs/pong_ppo.py", overrides=["device.chips=4"])
|
|
184
|
+
ttrl.run(config)
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
N replicas collect N times the experience per update round, so a multi-chip
|
|
188
|
+
run is a different recipe from its single-chip config, and learning rates or
|
|
189
|
+
batch sizes may need retuning. PPO, which already runs many environments at
|
|
190
|
+
once, is the natural fit.
|
|
191
|
+
|
|
192
|
+
## Deploy without a chip
|
|
193
|
+
|
|
194
|
+
```python
|
|
195
|
+
import ttrl
|
|
196
|
+
|
|
197
|
+
artifact = ttrl.export_policy("runs/pong/checkpoint-best.npz", "pong.policy.npz")
|
|
198
|
+
ttrl.export_onnx(artifact, "pong.onnx") # needs the [onnx] extra
|
|
199
|
+
|
|
200
|
+
policy = ttrl.load_policy(artifact) # numpy only
|
|
201
|
+
action = policy(obs) # obs: one raw observation
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
The ONNX graph has one input, `obs`, and two outputs, `action` and `head`
|
|
205
|
+
(the Q-values or action distribution). It runs with `onnxruntime`, and the
|
|
206
|
+
Atari DQN graph also compiles unchanged with Tenstorrent's TT-Forge-ONNX.
|
|
207
|
+
|
|
208
|
+
## Your own environment
|
|
209
|
+
|
|
210
|
+
An environment is any object with `obs_spec`, `action_spec`, `episode_bound`,
|
|
211
|
+
`reset`, `step` and `close`. Nothing needs subclassing:
|
|
212
|
+
|
|
213
|
+
```python
|
|
214
|
+
import numpy as np
|
|
215
|
+
import ttrl
|
|
216
|
+
from ttrl.envs import check_env
|
|
217
|
+
from ttrl.envs.registry import register
|
|
218
|
+
from ttrl.envs.wrappers import RecordEpisodeStatistics
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
class Slider:
|
|
222
|
+
"""Move a point to the origin. Reward is the step's reduction in |x|."""
|
|
223
|
+
|
|
224
|
+
obs_spec = ttrl.ObsSpec.vector(2)
|
|
225
|
+
action_spec = ttrl.ActionSpec.discrete(3)
|
|
226
|
+
episode_bound = 64
|
|
227
|
+
|
|
228
|
+
def reset(self, *, seed=None):
|
|
229
|
+
self.rng = np.random.default_rng(seed)
|
|
230
|
+
self.x, self.t = float(self.rng.uniform(-1.0, 1.0)), 0
|
|
231
|
+
return self._obs(), {}
|
|
232
|
+
|
|
233
|
+
def _obs(self):
|
|
234
|
+
return np.array([self.x, self.t / self.episode_bound], dtype=np.float32)
|
|
235
|
+
|
|
236
|
+
def step(self, action):
|
|
237
|
+
before = abs(self.x)
|
|
238
|
+
self.x = float(np.clip(self.x + (int(action) - 1) * 0.05, -1.0, 1.0))
|
|
239
|
+
self.t += 1
|
|
240
|
+
return self._obs(), before - abs(self.x), False, self.t >= self.episode_bound, {}
|
|
241
|
+
|
|
242
|
+
def close(self):
|
|
243
|
+
pass
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
register("slider", lambda **kw: RecordEpisodeStatistics(Slider(**kw)))
|
|
247
|
+
check_env(RecordEpisodeStatistics(Slider()))
|
|
248
|
+
|
|
249
|
+
config = ttrl.TrainConfig(
|
|
250
|
+
algo="dqn",
|
|
251
|
+
total_frames=4_000,
|
|
252
|
+
eval_interval=4_000,
|
|
253
|
+
log_dir="runs/slider",
|
|
254
|
+
env=ttrl.EnvConfig(name="slider", n_envs=1),
|
|
255
|
+
algo_cfg=ttrl.DQNConfig(batch_size=64, learning_starts=500, buffer_capacity=4_000),
|
|
256
|
+
)
|
|
257
|
+
ttrl.run(config)
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
`check_env` raises on the first contract violation with a message saying what
|
|
261
|
+
was expected. `RecordEpisodeStatistics` is required: evaluation reads each
|
|
262
|
+
episode's score from it.
|
|
263
|
+
|
|
264
|
+
## Tests
|
|
265
|
+
|
|
266
|
+
```bash
|
|
267
|
+
pytest # host suite, no chip needed
|
|
268
|
+
pytest -m tt # hardware suite, needs a chip
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
## License
|
|
272
|
+
|
|
273
|
+
MIT
|
tt_rl-0.1.0/README.md
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
# tt-rl
|
|
2
|
+
|
|
3
|
+
[](https://github.com/scaleresearch/tt-rl/actions/workflows/ci.yml)
|
|
4
|
+
[](LICENSE)
|
|
5
|
+
|
|
6
|
+
Reinforcement learning on Tenstorrent hardware, built directly on
|
|
7
|
+
[TT-NN](https://github.com/tenstorrent/tt-metal). Networks, gradients, the Adam
|
|
8
|
+
step and the device trace all run on the chip through `ttnn`. Environments
|
|
9
|
+
and replay buffers stay on the host.
|
|
10
|
+
|
|
11
|
+
<table>
|
|
12
|
+
<tr>
|
|
13
|
+
<td align="center"><img src="https://raw.githubusercontent.com/scaleresearch/tt-rl/master/assets/pong.gif" height="260" alt="Pong"><br>Pong, DQN</td>
|
|
14
|
+
<td align="center"><img src="https://raw.githubusercontent.com/scaleresearch/tt-rl/master/assets/breakout.gif" height="260" alt="Breakout"><br>Breakout, DQN</td>
|
|
15
|
+
<td align="center"><img src="https://raw.githubusercontent.com/scaleresearch/tt-rl/master/assets/boxing.gif" height="260" alt="Boxing"><br>Boxing, DQN</td>
|
|
16
|
+
<td align="center"><img src="https://raw.githubusercontent.com/scaleresearch/tt-rl/master/assets/hopper.gif" height="260" alt="Hopper"><br>Hopper, SAC</td>
|
|
17
|
+
</tr>
|
|
18
|
+
</table>
|
|
19
|
+
|
|
20
|
+
- **Algorithms:** DQN (double, n-step, prioritized replay), PPO (GAE, clipping,
|
|
21
|
+
optional GRU memory) and SAC (twin critics, learned temperature).
|
|
22
|
+
- **Environments:** Atari pixels, MuJoCo state vectors, and any environment you
|
|
23
|
+
write against a small protocol.
|
|
24
|
+
- **Single or multiple chips:** a run trains on one chip, or data-parallel
|
|
25
|
+
across several with one replica per chip.
|
|
26
|
+
- **Deploy anywhere:** export a trained policy to numpy or ONNX and run it on
|
|
27
|
+
any CPU.
|
|
28
|
+
|
|
29
|
+
## Results
|
|
30
|
+
|
|
31
|
+
Measured on one Blackhole chip. Atari scores are the mean over 30 evaluation
|
|
32
|
+
episodes with sticky actions (0.25), which is harder than the
|
|
33
|
+
`NoFrameskip-v4` setting most published numbers use. A step is one agent
|
|
34
|
+
action, four Atari frames. Each score is the best evaluation of its run.
|
|
35
|
+
|
|
36
|
+
| Task | Algorithm | Steps | Score | Weights |
|
|
37
|
+
|---|---|---|---|---|
|
|
38
|
+
| Pong | DQN | 10M | 17.8 | [ttrl-dqn-pong](https://huggingface.co/scaleresearch/ttrl-dqn-pong) |
|
|
39
|
+
| Breakout | DQN | 10M | 144.8 | [ttrl-dqn-breakout](https://huggingface.co/scaleresearch/ttrl-dqn-breakout) |
|
|
40
|
+
| Boxing | DQN | 10M | 91.0 | [ttrl-dqn-boxing](https://huggingface.co/scaleresearch/ttrl-dqn-boxing) |
|
|
41
|
+
| Hopper-v5 | SAC | 1M | 3604 | [ttrl-sac-hopper](https://huggingface.co/scaleresearch/ttrl-sac-hopper) |
|
|
42
|
+
|
|
43
|
+
Each config in `configs/` records how it was measured in its docstring. The
|
|
44
|
+
trained policies are on Hugging Face as ONNX and numpy weights, with a
|
|
45
|
+
`play.py` that runs them on CPU.
|
|
46
|
+
|
|
47
|
+
### Learning
|
|
48
|
+
|
|
49
|
+
From an untrained agent to the final one, at fixed checkpoints of the same
|
|
50
|
+
run (Atari clips play at 3x speed):
|
|
51
|
+
|
|
52
|
+

|
|
53
|
+
|
|
54
|
+

|
|
55
|
+
|
|
56
|
+
<details>
|
|
57
|
+
<summary>Breakout and Boxing</summary>
|
|
58
|
+
|
|
59
|
+

|
|
60
|
+
|
|
61
|
+

|
|
62
|
+
|
|
63
|
+
</details>
|
|
64
|
+
|
|
65
|
+
## Requirements
|
|
66
|
+
|
|
67
|
+
- Linux and Python 3.12. `ttnn` 0.80 ships wheels for 3.10 and 3.12, and
|
|
68
|
+
3.10 is dropped because current Pillow and filelock no longer support it.
|
|
69
|
+
- A Tenstorrent Blackhole chip with its driver and firmware installed.
|
|
70
|
+
Developed on a TT-QuietBox with four Blackhole chips.
|
|
71
|
+
|
|
72
|
+
## Install
|
|
73
|
+
|
|
74
|
+
ttrl installs from source for now. A PyPI release as `tt-rl` is on its way,
|
|
75
|
+
after which `pip install tt-rl` will be enough.
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
git clone https://github.com/scaleresearch/tt-rl && cd tt-rl
|
|
79
|
+
pip install -e '.[atari]' # Atari
|
|
80
|
+
pip install -e '.[mujoco]' # MuJoCo
|
|
81
|
+
pip install -e '.[dev]' # both, plus the test suite's dependencies
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
`ttnn` installs from PyPI as a dependency. Then check the machine:
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
ttrl doctor
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
It reports versions, which chips exist and who holds each one, and opens a
|
|
91
|
+
free chip to confirm a trace captures and replays.
|
|
92
|
+
|
|
93
|
+
## Train
|
|
94
|
+
|
|
95
|
+
A run is a Python config. Arguments after the path override any field by
|
|
96
|
+
its dotted name:
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
ttrl train configs/pong_dqn.py device.chip=0
|
|
100
|
+
ttrl train configs/pong_dqn.py total_frames=3000 algo_cfg.learning_starts=500 log_dir=runs/smoke
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
The same from Python:
|
|
104
|
+
|
|
105
|
+
```python
|
|
106
|
+
import ttrl
|
|
107
|
+
|
|
108
|
+
config = ttrl.load_config("configs/pong_dqn.py", overrides=["device.chip=0"])
|
|
109
|
+
result = ttrl.run(config)
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
A run writes metrics, checkpoints and `checkpoint-best.npz` to its
|
|
113
|
+
`log_dir`. `ttrl train --resume best <config>` continues from the best one;
|
|
114
|
+
DQN and SAC runs also need `checkpoint_replay=True` so the replay buffer is
|
|
115
|
+
saved with them.
|
|
116
|
+
`examples/atari-dqn` and `examples/mujoco-sac` are standalone projects that
|
|
117
|
+
use ttrl as a library.
|
|
118
|
+
|
|
119
|
+
A chip is exclusive to one process. `device.chip=N` names a physical chip,
|
|
120
|
+
the `N` in `/dev/tenstorrent/N`; leave it unset to take the lowest free one.
|
|
121
|
+
|
|
122
|
+
### Multiple chips
|
|
123
|
+
|
|
124
|
+
`device.chips` trains one replica per chip. Each replica steps its own
|
|
125
|
+
environments and runs its own updates, and every `device.sync_every` updates
|
|
126
|
+
(50 by default) the replicas average their parameters, so they stay one model.
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
ttrl train configs/pong_ppo.py device.chips=4 # any 4 chips
|
|
130
|
+
ttrl train configs/pong_ppo.py device.chips=all # every chip on the machine
|
|
131
|
+
ttrl train configs/pong_ppo.py 'device.chips=[0,1]' # these physical chips
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
```python
|
|
135
|
+
config = ttrl.load_config("configs/pong_ppo.py", overrides=["device.chips=4"])
|
|
136
|
+
ttrl.run(config)
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
N replicas collect N times the experience per update round, so a multi-chip
|
|
140
|
+
run is a different recipe from its single-chip config, and learning rates or
|
|
141
|
+
batch sizes may need retuning. PPO, which already runs many environments at
|
|
142
|
+
once, is the natural fit.
|
|
143
|
+
|
|
144
|
+
## Deploy without a chip
|
|
145
|
+
|
|
146
|
+
```python
|
|
147
|
+
import ttrl
|
|
148
|
+
|
|
149
|
+
artifact = ttrl.export_policy("runs/pong/checkpoint-best.npz", "pong.policy.npz")
|
|
150
|
+
ttrl.export_onnx(artifact, "pong.onnx") # needs the [onnx] extra
|
|
151
|
+
|
|
152
|
+
policy = ttrl.load_policy(artifact) # numpy only
|
|
153
|
+
action = policy(obs) # obs: one raw observation
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
The ONNX graph has one input, `obs`, and two outputs, `action` and `head`
|
|
157
|
+
(the Q-values or action distribution). It runs with `onnxruntime`, and the
|
|
158
|
+
Atari DQN graph also compiles unchanged with Tenstorrent's TT-Forge-ONNX.
|
|
159
|
+
|
|
160
|
+
## Your own environment
|
|
161
|
+
|
|
162
|
+
An environment is any object with `obs_spec`, `action_spec`, `episode_bound`,
|
|
163
|
+
`reset`, `step` and `close`. Nothing needs subclassing:
|
|
164
|
+
|
|
165
|
+
```python
|
|
166
|
+
import numpy as np
|
|
167
|
+
import ttrl
|
|
168
|
+
from ttrl.envs import check_env
|
|
169
|
+
from ttrl.envs.registry import register
|
|
170
|
+
from ttrl.envs.wrappers import RecordEpisodeStatistics
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
class Slider:
|
|
174
|
+
"""Move a point to the origin. Reward is the step's reduction in |x|."""
|
|
175
|
+
|
|
176
|
+
obs_spec = ttrl.ObsSpec.vector(2)
|
|
177
|
+
action_spec = ttrl.ActionSpec.discrete(3)
|
|
178
|
+
episode_bound = 64
|
|
179
|
+
|
|
180
|
+
def reset(self, *, seed=None):
|
|
181
|
+
self.rng = np.random.default_rng(seed)
|
|
182
|
+
self.x, self.t = float(self.rng.uniform(-1.0, 1.0)), 0
|
|
183
|
+
return self._obs(), {}
|
|
184
|
+
|
|
185
|
+
def _obs(self):
|
|
186
|
+
return np.array([self.x, self.t / self.episode_bound], dtype=np.float32)
|
|
187
|
+
|
|
188
|
+
def step(self, action):
|
|
189
|
+
before = abs(self.x)
|
|
190
|
+
self.x = float(np.clip(self.x + (int(action) - 1) * 0.05, -1.0, 1.0))
|
|
191
|
+
self.t += 1
|
|
192
|
+
return self._obs(), before - abs(self.x), False, self.t >= self.episode_bound, {}
|
|
193
|
+
|
|
194
|
+
def close(self):
|
|
195
|
+
pass
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
register("slider", lambda **kw: RecordEpisodeStatistics(Slider(**kw)))
|
|
199
|
+
check_env(RecordEpisodeStatistics(Slider()))
|
|
200
|
+
|
|
201
|
+
config = ttrl.TrainConfig(
|
|
202
|
+
algo="dqn",
|
|
203
|
+
total_frames=4_000,
|
|
204
|
+
eval_interval=4_000,
|
|
205
|
+
log_dir="runs/slider",
|
|
206
|
+
env=ttrl.EnvConfig(name="slider", n_envs=1),
|
|
207
|
+
algo_cfg=ttrl.DQNConfig(batch_size=64, learning_starts=500, buffer_capacity=4_000),
|
|
208
|
+
)
|
|
209
|
+
ttrl.run(config)
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
`check_env` raises on the first contract violation with a message saying what
|
|
213
|
+
was expected. `RecordEpisodeStatistics` is required: evaluation reads each
|
|
214
|
+
episode's score from it.
|
|
215
|
+
|
|
216
|
+
## Tests
|
|
217
|
+
|
|
218
|
+
```bash
|
|
219
|
+
pytest # host suite, no chip needed
|
|
220
|
+
pytest -m tt # hardware suite, needs a chip
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
## License
|
|
224
|
+
|
|
225
|
+
MIT
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "tt-rl"
|
|
7
|
+
# Single source of truth: `ttrl.__version__`. setuptools reads this statically
|
|
8
|
+
# (AST), so declaring it here does not import the package at build time.
|
|
9
|
+
dynamic = ["version"]
|
|
10
|
+
description = "Reinforcement learning on Tenstorrent, natively on TT-NN"
|
|
11
|
+
requires-python = ">=3.12,<3.13"
|
|
12
|
+
readme = "README.md"
|
|
13
|
+
license = "MIT"
|
|
14
|
+
license-files = ["LICENSE"]
|
|
15
|
+
authors = [{ name = "Antoni Bertel" }]
|
|
16
|
+
keywords = ["reinforcement-learning", "tenstorrent", "ttnn", "blackhole", "rl"]
|
|
17
|
+
classifiers = [
|
|
18
|
+
"Development Status :: 3 - Alpha",
|
|
19
|
+
"Intended Audience :: Science/Research",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Programming Language :: Python :: 3.12",
|
|
22
|
+
"Operating System :: POSIX :: Linux",
|
|
23
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
24
|
+
]
|
|
25
|
+
# Version policy for the two pins below.
|
|
26
|
+
#
|
|
27
|
+
# ttnn is pinned to a single minor, `>=0.80.0,<0.81`. ttnn publishes one
|
|
28
|
+
# release per minor (0.65 through 0.80 on PyPI, with 0.67.4, 0.70.1, 0.71.2
|
|
29
|
+
# and 0.73.1 the only patches), so its minor is its release channel and it
|
|
30
|
+
# carries breaking C++ and Python API changes inside it. ttrl builds on the
|
|
31
|
+
# parts of ttnn that move most: the autograd-free op surface, device trace
|
|
32
|
+
# capture, the mesh and cluster descriptors, and the conv kernel configs. A
|
|
33
|
+
# ttnn minor bump is therefore a porting job for us, and it ships as a ttrl
|
|
34
|
+
# minor bump: raise both bounds together, run the hardware gate, and record
|
|
35
|
+
# the ttnn version the numbers came from.
|
|
36
|
+
# A range spanning minors would let pip pick a ttnn that ttrl has never been
|
|
37
|
+
# run against on a chip, which on this stack surfaces as a TT_FATAL inside a
|
|
38
|
+
# kernel rather than an ImportError.
|
|
39
|
+
#
|
|
40
|
+
# `numpy<2` comes from upstream. ttnn 0.80.0's own metadata declares
|
|
41
|
+
# `numpy<2,>=1.24.4`, so 1.26.4, the last of the 1.x line, is the ceiling the
|
|
42
|
+
# whole tree is held to. Stating it here makes the resolution failure legible
|
|
43
|
+
# at install time instead of mid-backtrack. It also caps
|
|
44
|
+
# `opencv-python-headless` at 4.11.x, the last release that still accepts
|
|
45
|
+
# numpy 1.x. This bound lifts when ttnn's does and not before.
|
|
46
|
+
#
|
|
47
|
+
# The env plumbing (gymnasium / ale-py / cv2 / mujoco) is resolved at call
|
|
48
|
+
# time by `ttrl.envs`, so a bare install imports and runs without any
|
|
49
|
+
# environment suite and each suite is an extra.
|
|
50
|
+
dependencies = [
|
|
51
|
+
"ttnn>=0.80.0,<0.81",
|
|
52
|
+
"numpy>=1.26,<2",
|
|
53
|
+
]
|
|
54
|
+
|
|
55
|
+
[project.optional-dependencies]
|
|
56
|
+
atari = [
|
|
57
|
+
"gymnasium[atari]>=1.4",
|
|
58
|
+
"ale-py>=0.12",
|
|
59
|
+
"opencv-python-headless>=4.11",
|
|
60
|
+
]
|
|
61
|
+
mujoco = [
|
|
62
|
+
"gymnasium[mujoco]>=1.4",
|
|
63
|
+
"mujoco>=3.17,<4",
|
|
64
|
+
# `ttrl.record_video` writes its mp4 through cv2, and watching a gait is
|
|
65
|
+
# a first-class use of this extra. Without it here, recording a
|
|
66
|
+
# locomotion policy needed the unrelated `atari` extra installed.
|
|
67
|
+
"opencv-python-headless>=4.11",
|
|
68
|
+
]
|
|
69
|
+
logging = ["tensorboard>=2.21"]
|
|
70
|
+
# The tracker sink, `ttrl.train.logging.WandbLogger`. An extra rather than a
|
|
71
|
+
# dependency: nothing on the training path imports wandb, and a run logs to
|
|
72
|
+
# JSONL without it.
|
|
73
|
+
tracker = ["wandb>=0.19"]
|
|
74
|
+
# What `python -m tools.curves` draws with. An extra rather than a
|
|
75
|
+
# dependency: the wheel trains, and nothing on the training path imports
|
|
76
|
+
# matplotlib.
|
|
77
|
+
plots = ["matplotlib>=3.9"]
|
|
78
|
+
# What `ttrl.export_onnx` writes the policy graph with. An extra rather than a
|
|
79
|
+
# dependency: `ttrl.export_policy` and `ttrl.load_policy` need numpy alone, and
|
|
80
|
+
# `onnx` is a protobuf library that no training path imports. It brings no
|
|
81
|
+
# torch and no runtime: running the graph is the consumer's business, and the
|
|
82
|
+
# parity gate in the dev extra below is the only place this repository does it.
|
|
83
|
+
onnx = ["onnx>=1.21"]
|
|
84
|
+
# Everything needed to run the non-hardware test suite: pytest, the torch
|
|
85
|
+
# reference implementations the parity tests compare against, TensorBoard,
|
|
86
|
+
# which `tests/train/test_logging.py` exercises, matplotlib, which
|
|
87
|
+
# `tests/tools/test_curves.py` exercises, and both environment suites, which
|
|
88
|
+
# the env-layer tests build real environments from.
|
|
89
|
+
#
|
|
90
|
+
# wandb is deliberately absent. `tests/train/test_trackers.py` drives that
|
|
91
|
+
# sink against a stand-in module and asserts the refusal when the real one is
|
|
92
|
+
# missing, so the suite holds it to its contract on a machine with no tracker
|
|
93
|
+
# client and without reaching a network.
|
|
94
|
+
#
|
|
95
|
+
# onnxruntime is here and not in the `onnx` extra: writing a graph needs the
|
|
96
|
+
# protobuf library, and only the parity gate
|
|
97
|
+
# (`tests/deploy/test_onnx_parity.py`) needs to run one. A policy whose ONNX
|
|
98
|
+
# file merely loads is not a validated export, so the suite executes the graph
|
|
99
|
+
# and compares actions against the numpy artifact.
|
|
100
|
+
dev = [
|
|
101
|
+
"pytest>=9",
|
|
102
|
+
"torch>=2.14",
|
|
103
|
+
"tensorboard>=2.21",
|
|
104
|
+
"matplotlib>=3.9",
|
|
105
|
+
"tt-rl[onnx]",
|
|
106
|
+
"onnxruntime>=1.20",
|
|
107
|
+
"tt-rl[atari]",
|
|
108
|
+
"tt-rl[mujoco]",
|
|
109
|
+
]
|
|
110
|
+
|
|
111
|
+
[project.urls]
|
|
112
|
+
Homepage = "https://github.com/scaleresearch/tt-rl"
|
|
113
|
+
Repository = "https://github.com/scaleresearch/tt-rl"
|
|
114
|
+
Issues = "https://github.com/scaleresearch/tt-rl/issues"
|
|
115
|
+
|
|
116
|
+
[project.scripts]
|
|
117
|
+
# The CLI is a thin argparse shell over the same public API an external
|
|
118
|
+
# script calls, so anything it can do, `import ttrl` can do too.
|
|
119
|
+
ttrl = "ttrl.cli:main"
|
|
120
|
+
|
|
121
|
+
[tool.setuptools.dynamic]
|
|
122
|
+
version = { attr = "ttrl.__version__" }
|
|
123
|
+
|
|
124
|
+
[tool.setuptools.packages.find]
|
|
125
|
+
include = ["ttrl*"]
|
|
126
|
+
|
|
127
|
+
[tool.pytest.ini_options]
|
|
128
|
+
# Only `tests/` holds tests, so a bare `pytest` at the repo root never reaches
|
|
129
|
+
# into `tools/`, which is developer tooling rather than a test suite.
|
|
130
|
+
testpaths = ["tests"]
|
|
131
|
+
# A bare `pytest` must not open a chip. The `tt` marker is what says a test
|
|
132
|
+
# needs one, and `tt`-marked tests live all over `tests/`, not only in
|
|
133
|
+
# `tests/hardware`, so deselecting the directory is not enough and a
|
|
134
|
+
# command-line `-m` still overrides this to reach them.
|
|
135
|
+
addopts = '-m "not tt"'
|
|
136
|
+
markers = [
|
|
137
|
+
"tt: requires real Tenstorrent hardware (/dev/tenstorrent/*)",
|
|
138
|
+
]
|
tt_rl-0.1.0/setup.cfg
ADDED