Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

Training stops immediately with error: SubprocessEnvManager had workers that didn't signal shutdown

Discussion in 'ML-Agents' started by Hjalte, Mar 23, 2022.

  1. Hjalte

    Hjalte

    Joined:
    Apr 4, 2014
    Posts:
    3
    Hi,

    When I run 'mlagents-learn --force', I get the Unity logo as expected, but once I press play, it loads for a couple seconds and gives me an error (see full printout below).

    I am using the 'ML Agents 2.2.1-exp1' package.

    Full printout:
    Code (CSharp):
    1. (venv) C:\Users\hjalte\Desktop\Szrot\Szrot ML>mlagents-learn --force
    2.  
    3.             ┐  ╖
    4.         ╓╖╬│╡  ││╬╖╖
    5.     ╓╖╬│││││┘  ╬│││││╬╖
    6. ╖╬│││││╬╜        ╙╬│││││╖╖                               ╗╗╗
    7. ╬╬╬╬╖││╦╖        ╖╬││╗╣╣╣╬      ╟╣╣╬    ╟╣╣╣             ╜╜╜  ╟╣╣
    8. ╬╬╬╬╬╬╬╬╖│╬╖╖╓╬╪│╓╣╣╣╣╣╣╣╬      ╟╣╣╬    ╟╣╣╣ ╒╣╣╖╗╣╣╣╗   ╣╣╣ ╣╣╣╣╣╣ ╟╣╣╖   ╣╣╣
    9. ╬╬╬╬┐  ╙╬╬╬╬│╓╣╣╣╝╜  ╫╣╣╣╬      ╟╣╣╬    ╟╣╣╣ ╟╣╣╣╙ ╙╣╣╣  ╣╣╣ ╙╟╣╣╜╙  ╫╣╣  ╟╣╣
    10. ╬╬╬╬┐     ╙╬╬╣╣      ╫╣╣╣╬      ╟╣╣╬    ╟╣╣╣ ╟╣╣╬   ╣╣╣  ╣╣╣  ╟╣╣     ╣╣╣┌╣╣╜
    11. ╬╬╬╜       ╬╬╣╣      ╙╝╣╣╬      ╙╣╣╣╗╖╓╗╣╣╣╜ ╟╣╣╬   ╣╣╣  ╣╣╣  ╟╣╣╦╓    ╣╣╣╣╣
    12. ╙   ╓╦╖    ╬╬╣╣   ╓╗╗╖            ╙╝╣╣╣╣╝╜   ╘╝╝╜   ╝╝╝  ╝╝╝   ╙╣╣╣    ╟╣╣╣
    13.    ╩╬╬╬╬╬╬╦╦╬╬╣╣╗╣╣╣╣╣╣╣╝                                             ╫╣╣╣╣
    14.       ╙╬╬╬╬╬╬╬╣╣╣╣╣╣╝╜
    15.           ╙╬╬╬╣╣╣╜
    16.              ╙
    17.  
    18. Version information:
    19.   ml-agents: 0.28.0,
    20.   ml-agents-envs: 0.28.0,
    21.   Communicator API: 1.5.0,
    22.   PyTorch: 1.7.1+cu110
    23. [INFO] Listening on port 5004. Start training by pressing the Play button in the Unity Editor.
    24. [INFO] Connected to Unity environment with package version 2.2.1-exp.1 and communication version 1.5.0
    25. [INFO] Connected new brain: MoveToGoal?team=0
    26. [WARNING] Behavior name MoveToGoal does not match any behaviors specified in the trainer configuration file. A default configuration will be used.
    27. [WARNING] Deleting TensorBoard data events.out.tfevents.1648050845.DESKTOP-FHQ6GMJ.25336.0 that was left over from a previous run.
    28. [INFO] Hyperparameters for behavior name MoveToGoal:
    29.         trainer_type:   ppo
    30.         hyperparameters:
    31.           batch_size:   1024
    32.           buffer_size:  10240
    33.           learning_rate:        0.0003
    34.           beta: 0.005
    35.           epsilon:      0.2
    36.           lambd:        0.95
    37.           num_epoch:    3
    38.           learning_rate_schedule:       linear
    39.           beta_schedule:        linear
    40.           epsilon_schedule:     linear
    41.         network_settings:
    42.           normalize:    False
    43.           hidden_units: 128
    44.           num_layers:   2
    45.           vis_encode_type:      simple
    46.           memory:       None
    47.           goal_conditioning_type:       hyper
    48.           deterministic:        False
    49.         reward_signals:
    50.           extrinsic:
    51.             gamma:      0.99
    52.             strength:   1.0
    53.             network_settings:
    54.               normalize:        False
    55.               hidden_units:     128
    56.               num_layers:       2
    57.               vis_encode_type:  simple
    58.               memory:   None
    59.               goal_conditioning_type:   hyper
    60.               deterministic:    False
    61.         init_path:      None
    62.         keep_checkpoints:       5
    63.         checkpoint_interval:    500000
    64.         max_steps:      500000
    65.         time_horizon:   64
    66.         summary_freq:   50000
    67.         threaded:       False
    68.         self_play:      None
    69.         behavioral_cloning:     None
    70. [INFO] Exported results\ppo\MoveToGoal\MoveToGoal-0.onnx
    71. [INFO] Copied results\ppo\MoveToGoal\MoveToGoal-0.onnx to results\ppo\MoveToGoal.onnx.
    72. [ERROR] SubprocessEnvManager had workers that didn't signal shutdown
    73. [ERROR] A SubprocessEnvManager worker did not shut down correctly so it was forcefully terminated.
    74. Traceback (most recent call last):
    75.  File "C:\Users\hjalte\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 193, in _run_module_as_main
    76.    "__main__", mod_spec)
    77.  File "C:\Users\hjalte\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 85, in _run_code
    78.    exec(code, run_globals)
    79.  File "C:\Users\hjalte\Desktop\Szrot\Szrot ML\venv\Scripts\mlagents-learn.exe\__main__.py", line 7, in <module>
    80.  File "C:\Users\hjalte\Desktop\Szrot\Szrot ML\venv\lib\site-packages\mlagents\trainers\learn.py", line 260, in main
    81.    run_cli(parse_command_line())
    82.  File "C:\Users\hjalte\Desktop\Szrot\Szrot ML\venv\lib\site-packages\mlagents\trainers\learn.py", line 256, in run_cli
    83.    run_training(run_seed, options, num_areas)
    84.  File "C:\Users\hjalte\Desktop\Szrot\Szrot ML\venv\lib\site-packages\mlagents\trainers\learn.py", line 132, in run_training
    85.    tc.start_learning(env_manager)
    86.  File "C:\Users\hjalte\Desktop\Szrot\Szrot ML\venv\lib\site-packages\mlagents_envs\timers.py", line 305, in wrapped
    87.    return func(*args, **kwargs)
    88.  File "C:\Users\hjalte\Desktop\Szrot\Szrot ML\venv\lib\site-packages\mlagents\trainers\trainer_controller.py", line 176, in start_learning
    89.    n_steps = self.advance(env_manager)
    90.  File "C:\Users\hjalte\Desktop\Szrot\Szrot ML\venv\lib\site-packages\mlagents_envs\timers.py", line 305, in wrapped
    91.    return func(*args, **kwargs)
    92.  File "C:\Users\hjalte\Desktop\Szrot\Szrot ML\venv\lib\site-packages\mlagents\trainers\trainer_controller.py", line 234, in advance
    93.    new_step_infos = env_manager.get_steps()
    94.  File "C:\Users\hjalte\Desktop\Szrot\Szrot ML\venv\lib\site-packages\mlagents\trainers\env_manager.py", line 124, in get_steps
    95.    new_step_infos = self._step()
    96.  File "C:\Users\hjalte\Desktop\Szrot\Szrot ML\venv\lib\site-packages\mlagents\trainers\subprocess_env_manager.py", line 417, in _step
    97.    step: EnvironmentResponse = self.step_queue.get_nowait()
    98.  File "C:\Users\hjalte\AppData\Local\Programs\Python\Python37\lib\multiprocessing\queues.py", line 126, in get_nowait
    99.    return self.get(False)
    100.  File "C:\Users\hjalte\AppData\Local\Programs\Python\Python37\lib\multiprocessing\queues.py", line 109, in get
    101.    self._sem.release()
    102. ValueError: semaphore or lock released too many times
    I had some issues in the past, so I erased all my python, mlagents etc. This should be a perfectly clean install and even entirely new project.

    This is the agent, I'm trying to train (It worked perfectly with MLAgents 16.0):

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using Unity.MLAgents;
    4. using Unity.MLAgents.Actuators;
    5. using Unity.MLAgents.Sensors;
    6. using UnityEngine;
    7.  
    8. public class TestAgent : Agent
    9. {
    10.     public Transform target;
    11.     public float speed = 5f;
    12.  
    13.     private MeshRenderer floorRender;
    14.     private MaterialPropertyBlock mpb;
    15.  
    16.     private void Start()
    17.     {
    18.         floorRender = transform.parent.Find("Ground").GetComponent<MeshRenderer>();
    19.         mpb = new MaterialPropertyBlock();
    20.     }
    21.  
    22.     public override void OnEpisodeBegin()
    23.     {
    24.         base.OnEpisodeBegin();
    25.  
    26.         transform.localPosition = new Vector3(Random.Range(-3f, 3f), 0, Random.Range(-3f, 3f));
    27.         target.localPosition    = new Vector3(Random.Range(-3f, 3f), 0, Random.Range(-3f, 3f));
    28.     }
    29.  
    30.     public override void CollectObservations(VectorSensor sensor)
    31.     {
    32.         base.CollectObservations(sensor);
    33.  
    34.         sensor.AddObservation(transform.localPosition);
    35.         sensor.AddObservation(target.localPosition);
    36.     }
    37.  
    38.     public override void OnActionReceived(ActionBuffers actions)
    39.     {
    40.         base.OnActionReceived(actions);
    41.  
    42.         float moveX = actions.ContinuousActions[0];
    43.         float moveZ = actions.ContinuousActions[1];
    44.  
    45.         transform.localPosition += new Vector3(moveX, 0, moveZ) * Time.deltaTime * speed;
    46.     }
    47.  
    48.     public override void Heuristic(in ActionBuffers actionsOut)
    49.     {
    50.         base.Heuristic(actionsOut);
    51.  
    52.         ActionSegment<float> contActions = actionsOut.ContinuousActions;
    53.         contActions[0] = Input.GetAxisRaw("Horizontal");
    54.         contActions[1] = Input.GetAxisRaw("Vertical");
    55.     }
    56.  
    57.     private void OnTriggerEnter(Collider other)
    58.     {
    59.         if (other.CompareTag("Wall"))
    60.         {
    61.             SetReward(-1f);
    62.             mpb.SetColor("_Color", Color.red);
    63.             floorRender.SetPropertyBlock(mpb);
    64.             EndEpisode();
    65.         }
    66.         if (other.CompareTag("Goal"))
    67.         {
    68.             SetReward(1f);
    69.             mpb.SetColor("_Color", Color.green);
    70.             floorRender.SetPropertyBlock(mpb);
    71.             EndEpisode();
    72.         }
    73.     }
    74. }
    75.  
     
  2. KandepateJohnson

    KandepateJohnson

    Joined:
    Mar 4, 2022
    Posts:
    2
    any update on this ?