Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Onnx error when saving model. #6115

Closed
Haradai opened this issue May 18, 2024 · 5 comments
Closed

Onnx error when saving model. #6115

Haradai opened this issue May 18, 2024 · 5 comments
Labels
bug Issue describes a potential bug in ml-agents. stale Issues that have been idle for a while. Automatically closed by a bot if idle for too long.

Comments

@Haradai
Copy link

Haradai commented May 18, 2024

Describe the bug
I was following the initial example tutorial and managed to train a model. When I stop the training it cannot save the model because of issues with onnx. It looks like torch is unable to find onnx? But I have it installed and which the correct version.

Console logs / stack traces
^C[INFO] Learning was interrupted. Please wait while the graph is generated.
Traceback (most recent call last):
File "/Users/haradai/miniconda3/envs/mlagents/lib/python3.10/site-packages/torch/onnx/_internal/onnx_proto_utils.py", line 219, in _add_onnxscript_fn
import onnx
File "/Users/haradai/miniconda3/envs/mlagents/lib/python3.10/site-packages/onnx/init.py", line 6, in
from onnx.external_data_helper import load_external_data_for_model, write_external_data_tensors, convert_model_to_external_data
File "/Users/haradai/miniconda3/envs/mlagents/lib/python3.10/site-packages/onnx/external_data_helper.py", line 9, in
from .onnx_pb import TensorProto, ModelProto, AttributeProto, GraphProto
File "/Users/haradai/miniconda3/envs/mlagents/lib/python3.10/site-packages/onnx/onnx_pb.py", line 4, in
from .onnx_ml_pb2 import * # noqa
File "/Users/haradai/miniconda3/envs/mlagents/lib/python3.10/site-packages/onnx/onnx_ml_pb2.py", line 5, in
from google.protobuf.internal import builder as _builder
ImportError: cannot import name 'builder' from 'google.protobuf.internal' (/Users/haradai/miniconda3/envs/mlagents/lib/python3.10/site-packages/google/protobuf/internal/init.py)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/Users/haradai/miniconda3/envs/mlagents/bin/mlagents-learn", line 8, in
sys.exit(main())
File "/Users/haradai/miniconda3/envs/mlagents/lib/python3.10/site-packages/mlagents/trainers/learn.py", line 267, in main
run_cli(parse_command_line())
File "/Users/haradai/miniconda3/envs/mlagents/lib/python3.10/site-packages/mlagents/trainers/learn.py", line 263, in run_cli
run_training(run_seed, options, num_areas)
File "/Users/haradai/miniconda3/envs/mlagents/lib/python3.10/site-packages/mlagents/trainers/learn.py", line 137, in run_training
tc.start_learning(env_manager)
File "/Users/haradai/miniconda3/envs/mlagents/lib/python3.10/site-packages/mlagents_envs/timers.py", line 305, in wrapped
return func(*args, **kwargs)
File "/Users/haradai/miniconda3/envs/mlagents/lib/python3.10/site-packages/mlagents/trainers/trainer_controller.py", line 200, in start_learning
self._save_models()
File "/Users/haradai/miniconda3/envs/mlagents/lib/python3.10/site-packages/mlagents_envs/timers.py", line 305, in wrapped
return func(*args, **kwargs)
File "/Users/haradai/miniconda3/envs/mlagents/lib/python3.10/site-packages/mlagents/trainers/trainer_controller.py", line 80, in _save_models
self.trainers[brain_name].save_model()
File "/Users/haradai/miniconda3/envs/mlagents/lib/python3.10/site-packages/mlagents/trainers/trainer/rl_trainer.py", line 172, in save_model
model_checkpoint = self._checkpoint()
File "/Users/haradai/miniconda3/envs/mlagents/lib/python3.10/site-packages/mlagents_envs/timers.py", line 305, in wrapped
return func(*args, **kwargs)
File "/Users/haradai/miniconda3/envs/mlagents/lib/python3.10/site-packages/mlagents/trainers/trainer/rl_trainer.py", line 144, in _checkpoint
export_path, auxillary_paths = self.model_saver.save_checkpoint(
File "/Users/haradai/miniconda3/envs/mlagents/lib/python3.10/site-packages/mlagents/trainers/model_saver/torch_model_saver.py", line 60, in save_checkpoint
self.export(checkpoint_path, behavior_name)
File "/Users/haradai/miniconda3/envs/mlagents/lib/python3.10/site-packages/mlagents/trainers/model_saver/torch_model_saver.py", line 65, in export
self.exporter.export_policy_model(output_filepath)
File "/Users/haradai/miniconda3/envs/mlagents/lib/python3.10/site-packages/mlagents/trainers/torch_entities/model_serialization.py", line 164, in export_policy_model
torch.onnx.export(
File "/Users/haradai/miniconda3/envs/mlagents/lib/python3.10/site-packages/torch/onnx/utils.py", line 516, in export
_export(
File "/Users/haradai/miniconda3/envs/mlagents/lib/python3.10/site-packages/torch/onnx/utils.py", line 1686, in _export
proto = onnx_proto_utils._add_onnxscript_fn(
File "/Users/haradai/miniconda3/envs/mlagents/lib/python3.10/site-packages/torch/onnx/_internal/onnx_proto_utils.py", line 221, in _add_onnxscript_fn
raise errors.OnnxExporterError("Module onnx is not installed!") from e
torch.onnx.errors.OnnxExporterError: Module onnx is not installed!

Environment (please complete the following information):

  • Unity Version: [e.g. Unity 2022.3.29f1]
  • OS + version: [Mac M1, Macos Sonoma 14.5]
  • ML-Agents version: release 21
  • Torch version: 2.3.0
  • Protobuf version: 3.19.6
  • Onnx version: 1.12.0

NOTE:
I found this issue where seems that in newer versions of onnx the error has been fixed but I cannot upgrade as mlagents needs onnx==1.12.0.

@Haradai Haradai added the bug Issue describes a potential bug in ml-agents. label May 18, 2024
@Astronog
Copy link

pip install onnx

@onurkrsrml
Copy link

I also trying to install on M1 Mac ml agents release 21. I have issue with onnx on the this step(python -m pip install ./ml-agents). can you help me to fix it.

@Haradai
Copy link
Author

Haradai commented Jun 5, 2024

pip install onnx

Not recognizing the package. I even tried installing it through brew and no luck

Copy link

github-actions bot commented Jul 6, 2024

This issue is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale Issues that have been idle for a while. Automatically closed by a bot if idle for too long. label Jul 6, 2024
Copy link

This issue was closed because it has been inactive for 14 days since being marked as stale. Please open a new issue for related bugs.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jul 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue describes a potential bug in ml-agents. stale Issues that have been idle for a while. Automatically closed by a bot if idle for too long.
Projects
None yet
Development

No branches or pull requests

3 participants