Search Unity

Stepping One Agent per FixedUpdate During Runtime?

Discussion in 'ML-Agents' started by airoll, Nov 29, 2021.

  1. airoll

    airoll

    Joined:
    Jan 12, 2021
    Posts:
    37
    Hello, is it possible to step one agent per FixedUpdate during runtime? Specifically I am talking about after the agent has been trained and is using a model as inference.

    I currently have 8 agents, each which a vector observation space of 583. Currently, if I call Academy.Instance.EnvironmentStep(), it will collect all the observations in the same frame. However, I'm using a mobile device and after profiling, this takes up 1 ms of time, which is problematic given the target of 90 fps. I would like to make it such that one agent steps each FixedUpdate. It looks like I can do this by creating my own management that calls each of the functions in EnvironmentStep() for an individual agent.

    I was wondering if there's any downside or unintended consequence of doing this. Or if there's an alternative way to divide up the workload (by having things calculate on a background thread or something)?
     
  2. m4l4

    m4l4

    Joined:
    Jul 28, 2020
    Posts:
    81
    you could use a simple counter with modulus 8, and in fixed update just put
    counter++
    agent[counter].Step

    (don't mind syntax, i don't remember it ;P)

    but i see a couple of problems. Fixed update is called a fixed amount of times per second, the agent can be set to either: do nothing in between decisions, or to repeat the last action till next decision is taken.
    if your fixed update is called 4 times per second, then each agent will take a decision every 2 seconds, and it looks like way too much time to react to environmental changes.
    I would check how often Fixed update is called per second, then think about if it's reasonable for them to act with such delay.
     
  3. airoll

    airoll

    Joined:
    Jan 12, 2021
    Posts:
    37
    Does Agent actually have a Step() function? It seems like I would have to modify the Agent methods that are currently private currently to run one agent step per fixed update.

    Our FixedUpdate will run at 90 Hz and we've accounted for the fact that they will make decisions every N ms.
     
  4. m4l4

    m4l4

    Joined:
    Jul 28, 2020
    Posts:
    81
    there's no Step(), the function is called RequestDecision(), is called automatically by the decision requester every x frame. You could disable the decision requester component and call the function manually when needed