Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Question Need help with MLAgents

Discussion in 'ML-Agents' started by jjejj87, Feb 18, 2023.

  1. jjejj87

    jjejj87

    Joined:
    Feb 2, 2013
    Posts:
    935
    Hi. I am trying to get the ML agents examples scene setup and ran into something - it doesn't work. I have zero python/ml history so I was just following a tutorial. Can someone kindly tell me what I am doing wrong?

    So, here is what I did

    • Downloaded and installed Anaconda, created env
    conda create -n mlagents python=3.8
    conda activate mlagents
    pip3 install torch -f https://download.pytorch.org/whl/torch_stable.html
    pip3 install -e ./ml-agents-envs
    pip3 install -e ./ml-agents
    • Started a new project on 2021.3.18, added Newtonsoft Json package
    • Added package in disk Release 19 ML package
    • Copied the downloaded package (the ML-Agents folder)
    • Then when I enter this in Anaconda (to begin training), mlagents-learn config/ppo/PushBlock.yaml --run-id=push_block_test_01
    I get this, I've tried Release 20, different versions of Unity, python=3.9
    Can someone kindly help?

    (mlagents19) C:\Users\temp\Documents\mlAgents19\ml-agents-release_19>mlagents-learn config/ppo/PushBlock.yaml --run-id=push_block_test_01
    Traceback (most recent call last):
    File "C:\Users\temp\anaconda3\envs\mlagents19\Scripts\mlagents-learn-script.py", line 33, in <module>
    sys.exit(load_entry_point('mlagents', 'console_scripts', 'mlagents-learn')())
    File "C:\Users\temp\anaconda3\envs\mlagents19\Scripts\mlagents-learn-script.py", line 25, in importlib_load_entry_point
    return next(matches).load()
    File "C:\Users\temp\anaconda3\envs\mlagents19\lib\importlib\metadata.py", line 77, in load
    module = import_module(match.group('module'))
    File "C:\Users\temp\anaconda3\envs\mlagents19\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
    File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
    File "<frozen importlib._bootstrap>", line 991, in _find_and_load
    File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
    File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
    File "<frozen importlib._bootstrap_external>", line 843, in exec_module
    File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
    File "c:\users\temp\documents\mlagents19\ml-agents-release_19\ml-agents\mlagents\trainers\learn.py", line 2, in <module>
    from mlagents import torch_utils
    File "c:\users\temp\documents\mlagents19\ml-agents-release_19\ml-agents\mlagents\torch_utils\__init__.py", line 1, in <module>
    from mlagents.torch_utils.torch import torch as torch # noqa
    File "c:\users\temp\documents\mlagents19\ml-agents-release_19\ml-agents\mlagents\torch_utils\torch.py", line 6, in <module>
    from mlagents.trainers.settings import TorchSettings
    File "c:\users\temp\documents\mlagents19\ml-agents-release_19\ml-agents\mlagents\trainers\settings.py", line 25, in <module>
    from mlagents.trainers.cli_utils import StoreConfigFile, DetectDefault, parser
    File "c:\users\temp\documents\mlagents19\ml-agents-release_19\ml-agents\mlagents\trainers\cli_utils.py", line 5, in <module>
    from mlagents_envs.environment import UnityEnvironment
    File "c:\users\temp\documents\mlagents19\ml-agents-release_19\ml-agents-envs\mlagents_envs\environment.py", line 12, in <module>
    from mlagents_envs.side_channel.side_channel import SideChannel
    File "c:\users\temp\documents\mlagents19\ml-agents-release_19\ml-agents-envs\mlagents_envs\side_channel\__init__.py", line 5, in <module>
    from mlagents_envs.side_channel.default_training_analytics_side_channel import ( # noqa
    File "c:\users\temp\documents\mlagents19\ml-agents-release_19\ml-agents-envs\mlagents_envs\side_channel\default_training_analytics_side_channel.py", line 7, in <module>
    from mlagents_envs.communicator_objects.training_analytics_pb2 import (
    File "c:\users\temp\documents\mlagents19\ml-agents-release_19\ml-agents-envs\mlagents_envs\communicator_objects\training_analytics_pb2.py", line 35, in <module>
    _descriptor.FieldDescriptor(
    File "C:\Users\temp\anaconda3\envs\mlagents19\lib\site-packages\google\protobuf\descriptor.py", line 561, in __new__
    _message.Message._CheckCalledFromGeneratedFile()
    TypeError: Descriptors cannot not be created directly.
    If this call came from a _pb2.py file, your generated code is out of date and must be regenerated with protoc >= 3.19.0.
    If you cannot immediately regenerate your protos, some other possible workarounds are:
    1. Downgrade the protobuf package to 3.20.x or lower.
    2. Set PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python (but this will use pure-Python parsing and will be much slower).

    More information: https://developers.google.com/protocol-buffers/docs/news/2022-05-06#python-updates
     
  2. jjejj87

    jjejj87

    Joined:
    Feb 2, 2013
    Posts:
    935
    Sorry if this is noob question. I just don't know what to do :)
    If anyone can help, it will be really appreciated. I have zero idea what is going on or what to do.
     
  3. hughperkins

    hughperkins

    Joined:
    Dec 3, 2022
    Posts:
    176
    downgrade protobuf

    Code (csharp):
    1.  
    2. pip install protobuf==3.20.3
    3.  
    (I suspect that you installed the packages in the reverse order, and creating a fresh env, and installgin simply

    Code (csharp):
    1.  
    2. conda create -n mlagents python=3.8
    3. conda activate mlagents
    4. pip3 install -e ./ml-agents
    5.  
    .... will work better actually... )
     
    ericiba likes this.
  4. jjejj87

    jjejj87

    Joined:
    Feb 2, 2013
    Posts:
    935
    Thank you! I will give it a try!
     
    hughperkins likes this.
  5. jjejj87

    jjejj87

    Joined:
    Feb 2, 2013
    Posts:
    935
    It worked!!!!!!!

    just one last question. If I want to start again, let's say after a pc reboot. I am guessing
    conda activate mlagents

    and then

    mlagents-learn config/ppo/PushBlock.yaml --run-id=push_block_test_01

    to begin training again, correct? (no need to install things again)

    Sorry if this is a noob question.
     
  6. hughperkins

    hughperkins

    Joined:
    Dec 3, 2022
    Posts:
    176
    That sounds correct, yes :)
     
    jjejj87 likes this.
  7. jjejj87

    jjejj87

    Joined:
    Feb 2, 2013
    Posts:
    935
    Also, if I am starting a fresh project, so 1 mlagents sample at the moment, and 2 or three new projects, do I need to create a separate environment and all files (so repeating the whole process for each project) or can I just leave the python files and create multiple projects? (provided they all use the same versions)
     
  8. hughperkins

    hughperkins

    Joined:
    Dec 3, 2022
    Posts:
    176
    Reusing the python environment is fine.