From efd1b0ace85645ee2ec592dafb570d110a5767b1 Mon Sep 17 00:00:00 2001 From: samt1995 Date: Sat, 18 Oct 2025 15:25:46 +1000 Subject: [PATCH 1/3] Pin torch version to 2.8.0 to prevent breaking onnx changes in 2.9.0 The ` 2.9.0` version results in an issue finding `onnxscript`. Pinning the `2.8.0` prevent this error. I'm not exactly of the exact root cause but it seems there were some backwards incompatible changes to onnx: https://github.com/pytorch/pytorch/releases/tag/v2.9.0#backwards-incompatible-changes. Stack trace on exiting training: ``` File "C:\Users\Samuel\miniconda3\envs\mlagents\lib\site-packages\mlagents\trainers\torch_entities\model_serialization.py", line 164, in export_policy_model torch.onnx.export( File "C:\Users\Samuel\miniconda3\envs\mlagents\lib\site-packages\torch\onnx\__init__.py", line 282, in export from torch.onnx._internal.exporter import _compat File "C:\Users\Samuel\miniconda3\envs\mlagents\lib\site-packages\torch\onnx\_internal\exporter\_compat.py", line 16, in from torch.onnx._internal.exporter import ( File "C:\Users\Samuel\miniconda3\envs\mlagents\lib\site-packages\torch\onnx\_internal\exporter\_core.py", line 18, in import onnxscript ModuleNotFoundError: No module named 'onnxscript' ``` --- ml-agents/setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ml-agents/setup.py b/ml-agents/setup.py index 16be25d8b3..3c5d9cc3bd 100644 --- a/ml-agents/setup.py +++ b/ml-agents/setup.py @@ -62,7 +62,7 @@ def run(self): "Pillow>=4.2.1", "protobuf>=3.6,<3.21", "pyyaml>=3.1.0", - "torch>=2.1.1", + "torch==2.8.0", "tensorboard>=2.14", # adding six explicit dependency since tensorboard needs it but doesn't declare it as a dep "six>=1.16", From 71da0cb76518fda0f104cbde14f77a8d10a0129b Mon Sep 17 00:00:00 2001 From: samt1995 Date: Sat, 18 Oct 2025 15:46:12 +1000 Subject: [PATCH 2/3] Add torch version constraint to be equal or less than 2.8.0 Previously commit forced only 2.8.0, however adding this constraint is a bit nicer, as I see in some of installation docs sometimes torch 2.2.0 is installed: https://github.com/Unity-Technologies/ml-agents/blob/release_22_docs/docs/Installation.md. --- ml-agents/setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ml-agents/setup.py b/ml-agents/setup.py index 3c5d9cc3bd..2aec4e2cd6 100644 --- a/ml-agents/setup.py +++ b/ml-agents/setup.py @@ -62,7 +62,7 @@ def run(self): "Pillow>=4.2.1", "protobuf>=3.6,<3.21", "pyyaml>=3.1.0", - "torch==2.8.0", + "torch>=2.1.1,<=2.8.0", "tensorboard>=2.14", # adding six explicit dependency since tensorboard needs it but doesn't declare it as a dep "six>=1.16", From 31fccddad5d5c764887b2cc9c132e7ce8aaa39bb Mon Sep 17 00:00:00 2001 From: samt1995 Date: Wed, 22 Oct 2025 10:45:19 +1000 Subject: [PATCH 3/3] Update CHANGELOG.md --- com.unity.ml-agents/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/com.unity.ml-agents/CHANGELOG.md b/com.unity.ml-agents/CHANGELOG.md index 0efa435bc7..ae88dd1744 100755 --- a/com.unity.ml-agents/CHANGELOG.md +++ b/com.unity.ml-agents/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to - Fixed tensor indexing to use correct CHW layout (#6239) #### ml-agents / ml-agents-envs +- Set the Torch version constraint to 2.8 (#6251) - Fixed CUDA/CPU mismatch in threaded training (#6245) ## [4.0.0] - 2025-08-15