Skip to content

Conversation

vincentpierre
Copy link
Contributor

@vincentpierre vincentpierre commented Feb 27, 2021

Proposed change(s)

Before :
Screen Shot 2021-02-26 at 16 03 43
And after :
Screen Shot 2021-02-26 at 16 03 52

This should not be a breaking change since the model uses the Barracuda implicit input and output names. This will be useful when Barracuda will allow us to use named tensors for LSTM.

EDIT:
Some context. Currently, Barracuda creates new names for inputs and outputs of the LSTM (see here https://github.com/Unity-Technologies/ml-agents/blob/main/com.unity.ml-agents/Runtime/Inference/TensorApplier.cs#L79) and we use these at inference. This means that neither RecurrentOutput nor RecurrentOutputH/C are used at all. When Barracuda switches to use the names of the ONNX model, we need to make sure that there are appropriately named inputs and outputs to the LSTM.

Useful links (Github issues, JIRA tickets, ML-Agents forum threads etc.)

Slack message : https://unity.slack.com/archives/C8FECS6L9/p1614370112116900
JIRA : MLA-1807

Types of change(s)

  • Bug fix
  • New feature
  • Code refactor
  • Breaking change
  • Documentation update
  • Other (please describe)

Checklist

  • Added tests that prove my fix is effective or that my feature works
  • Updated the changelog (if applicable)
  • Updated the documentation (if applicable)
  • Updated the migration guide (if applicable)

Other comments

@vincentpierre vincentpierre self-assigned this Feb 27, 2021
@vincentpierre vincentpierre marked this pull request as ready for review March 1, 2021 17:22
@@ -40,6 +40,36 @@ def is_exporting():
return exporting_to_onnx._local_data._is_exporting


class TensorNames:
BatchSizePlaceholder = "batch_size"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please follow python naming conventions for these. I understand that you probably wanted to copy-paste the C# code here, but it makes the resulting python code stick out.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, will do.
Just to make sure, are we okay with this approach of having a class with static strings or is there a more Pythonic way to do this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could do it as a enum too (python enums aren't constrained to integer values) - see BufferKey in buffer.py, but there's not much advantage to doing that here (and you'd have to write a bit more code to cast to strings).

You could also add methods to the class for combining the prefix + index, like TensorNames.get_visual_observation_name(i)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to have as much as possible the same code between C# and Python for the TensorNames, but I think adding helper methods would help.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think adding helper methods would help.

It's right there in the name :)

Fee free to add to C# too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines 58 to 59
recurrentOutputH = "recurrent_out_h"
recurrentOutputC = "recurrent_out_c"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these used anywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, but I think there is a benefit in having symmetry with the C# code that does the same thing. I can remove them if someone disagrees strongly with it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct me if I'm wrong but seems like in C# recurrentOutputH and recurrentOutputC are not used either.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are. They are actually the only ones used. recurrentOutput is not used.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TensorGenerator and TensorApplier are both using TensorNames.RecurrentOutput but I don't see where they're using recurrentOutputH? same for recurrent input

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To clarify, the names used are recurrent_out_h and recurrent_out_c but these are not grabbed from the TensorNames but directly from Barracuda. But you are right, it does not make sense to keep them explicitly here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for clarifying, that makes sense to me now.

@vincentpierre vincentpierre merged commit 484908d into main Mar 2, 2021
@delete-merged-branch delete-merged-branch bot deleted the develop-use-correct-names-for-recurrent-inputs-and-outputs branch March 2, 2021 19:34
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 2, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants