Search Unity

Question Can model layers be updated after a worker has executed the model?

Discussion in 'Barracuda' started by tri-quad, Oct 27, 2020.

  1. tri-quad

    tri-quad

    Joined:
    Feb 17, 2020
    Posts:
    2
    I am exploring NEAT and related algorithms for evolving neural networks (inspired in part by https://weightagnostic.github.io/), and am wondering if a Barracuda Model can be dynamically updated once a Worker has been created and executed the Model. Examples of dynamic updates would be adding a new layer, removing a layer, or changing parameters of an existing layer (e.g. weights and biases of a Dense layer). By looking at the source code in Barracuda/Runtime/Core/ — Model.cs and ModelBuilder.cs in particular — I can infer how to update the model, but what is unclear to me is if/how those changes can be picked up by the model's worker.

    Can a worker handle dynamic changes to its underlying model? If not, what would be the correct way to destroy the worker and instantiate a new one for the updated model?

    Thanks for the help!
    Mikey
     
  2. amirebrahimi_unity

    amirebrahimi_unity

    Joined:
    Aug 12, 2015
    Posts:
    400
    In theory, yes this should work, but some things can get precompiled down (e.g. PrecompiledComputeOps), so I'd suggest calling Dispose on your previous worker and instantiating a new one.
     
  3. alexandreribard_unity

    alexandreribard_unity

    Unity Technologies

    Joined:
    Sep 18, 2019
    Posts:
    53
    Yes, you can use the ModelBuilder to edit a existing model (add/remove layers).
    But as @amirebrahimi_unity mentioned, you'd need to re-compile the worker with the new model.