Skip to content

Conversation

samt1995
Copy link
Contributor

@samt1995 samt1995 commented Oct 18, 2025

Proposed change(s)

The new 2.9.0 torch version released 2 day ago results in an issue finding onnxscript. ml-agents is configured to take any version >= 2.1.1 so it will take this version. Full credits to @Nitesh-joestar for identifying the issue and the fix for this in #6250.

Adding a constraint that maximum version is 2.8.0 prevents 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\REDACTED\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\REDACTED\miniconda3\envs\mlagents\lib\site-packages\torch\onnx\__init__.py", line 282, in export
    from torch.onnx._internal.exporter import _compat
  File "C:\Users\REDACTED\miniconda3\envs\mlagents\lib\site-packages\torch\onnx\_internal\exporter\_compat.py", line 16, in <module>
    from torch.onnx._internal.exporter import (
  File "C:\Users\REDACTED\miniconda3\envs\mlagents\lib\site-packages\torch\onnx\_internal\exporter\_core.py", line 18, in <module>
    import onnxscript
ModuleNotFoundError: No module named 'onnxscript'

Useful links (Github issues, JIRA tickets, ML-Agents forum threads etc.)

#6250

Types of change(s)

  • Bug fix
  • New feature
  • Code refactor
  • Breaking change
  • Documentation update
  • Other (please describe)

Checklist

  • Added tests that prove my fix is effective or that my feature works
  • Updated the changelog (if applicable)
  • Updated the documentation (if applicable)
  • Updated the migration guide (if applicable)

Other comments

Tested with torch version 2.8.0, running training, then exiting training; and confirm file saved correctly:

[INFO] Exported results\5\Basic\Basic-269.onnx
[INFO] Copied results\5\Basic\Basic-269.onnx to results\5\Basic.onnx.

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 <module>
    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 <module>
    import onnxscript
ModuleNotFoundError: No module named 'onnxscript'
```
@CLAassistant
Copy link

CLAassistant commented Oct 18, 2025

CLA assistant check
All committers have signed the CLA.

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.
@samt1995 samt1995 changed the title Pin torch version to 2.8.0 to prevent breaking onnx changes in 2.9.0 Add torch version constraint to be equal or less than 2.8.0 to prevent breaking onnx changes in torch 2.9.0 Oct 18, 2025
@maryamziaa maryamziaa self-requested a review October 21, 2025 19:14
Copy link
Contributor

@maryamziaa maryamziaa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, Thanks for submitting the PR. Please add a change log:
c11149b

Other than that, it looks good to me!

@samt1995
Copy link
Contributor Author

No worries, have added the change log.

@maryamziaa maryamziaa merged commit 631901b into Unity-Technologies:develop Oct 22, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants