Search Unity

Resolved How much overhead does ML-Agents have in inference in comparison to Barracuda only

Discussion in 'ML-Agents' started by Creaturtle, Feb 22, 2021.

  1. Creaturtle

    Creaturtle

    Joined:
    Jan 24, 2018
    Posts:
    33
    I am using a pre-trained model (trained using ML Agents in a different project) for a build, and want to know if there are any advantages to using Barracuda only for implementing the NN inference.

    So far it looks like it's going to be more work for implementing the input, and I'd like to know if it would be worth it.
     
    Last edited: Feb 22, 2021
  2. andrewcoh_unity

    andrewcoh_unity

    Unity Technologies

    Joined:
    Sep 5, 2019
    Posts:
    162
    Hi @Creaturtle

    You should use ML-Agents only if you want to retrain your model. The output of ML-Agents is an onnx model that Barracuda will use to run in inference. ML-Agents and Barracuda do not compete with each other; ML-Agents is designed so that the learned models can be used by Barracuda for inference.

    Hope this helps.
     
  3. Creaturtle

    Creaturtle

    Joined:
    Jan 24, 2018
    Posts:
    33
    So if I want to only use inference, I should not download ML-Agents, and only use Barracuda?
     
  4. andrewcoh_unity

    andrewcoh_unity

    Unity Technologies

    Joined:
    Sep 5, 2019
    Posts:
    162
    Yes, if you do not want to retrain your model, you do not need ML-Agents. Barracuda will be sufficient.
     
  5. Creaturtle

    Creaturtle

    Joined:
    Jan 24, 2018
    Posts:
    33
    Is there a guide somewhere on implementing an ML-Agents generated onnx using Barracuda? In the Barracuda documentation, it indicates that the inputs need to be fed with names. Where do I find these?

    Also, how should I be handling stacked vector observations?

    If you could point me to a guide that has this information, I would greatly appreciate it.
     
  6. andrewcoh_unity

    andrewcoh_unity

    Unity Technologies

    Joined:
    Sep 5, 2019
    Posts:
    162
    Sorry, I misread your initial comment; I did not realize that the onnx model you had was trained with ML-Agents in a different project. I thought this was an onnx model generated somewhere else entirely and that you were looking for a way to use it in Unity. ML-Agents has its own ModelRunner class built to run onnx models generated by ML-Agents using Barracuda in Unity environments.

    If you want to run this model in inference, you can take your agent from the old project, drop it into the new project and switch the BehaviorType to 'Inference' in the Behavior Parameters script.

    To answer some of your original questions,

    We have put significant effort into our ModelRunner. We are not aware of any advantages and if we found any, we would incorporate them into our own ModelRunner.

    You should use the ML-Agents package (com.unity.ml-agents)

    Again, I apologize for this. It's totally my fault for not realizing you were already using ML-Agents. I hope you didn't spend too much time on this (I see you have another post here).
     
  7. Creaturtle

    Creaturtle

    Joined:
    Jan 24, 2018
    Posts:
    33
    Oof.

    It's alright, I guess I got to learn more about what goes on behind the scenes...