-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update to barracuda 1.3.3 and changes to the model inputs and outputs for LSTM #5236
Conversation
@@ -206,7 +207,16 @@ def forward( | |||
# We don't use torch.split here since it is not supported by Barracuda | |||
h0 = memories[:, :, : self.hidden_size].contiguous() | |||
c0 = memories[:, :, self.hidden_size :].contiguous() | |||
|
|||
if exporting_to_onnx.is_exporting(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the comment above about torch.split
still accurate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this corresponds to a slice operator, not a split.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually think split
was added to recent versions of Barracuda, and we could use it here if we're breaking compat with old versions anyway. https://docs.unity3d.com/Packages/com.unity.barracuda@1.3/manual/SupportedOperators.html#Split
@@ -19,8 +19,9 @@ internal enum ModelApiVersion | |||
{ | |||
MLAgents1_0 = 2, | |||
MLAgents2_0 = 3, | |||
MLAgents2_0_Recurrent = 4, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we haven't released a version that uses MLAgents2_0
, I'd be in favor of just defining MLAgents2_0
to contain the LSTM changes too.
Either way, we should describe the differences between the versions here, just for our own internal knowledge.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, you might consider calling MLAgents2_0
=> MLAgents1_9
if that is the model version that went out with the last release.
com.unity.ml-agents/Runtime/Inference/BarracudaModelParamLoader.cs
Outdated
Show resolved
Hide resolved
com.unity.ml-agents/Runtime/Inference/BarracudaModelParamLoader.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Chris Elion <chris.elion@unity3d.com>
@@ -643,6 +643,7 @@ def forward( | |||
At this moment, torch.onnx.export() doesn't accept None as tensor to be exported, | |||
so the size of return tuple varies with action spec. | |||
""" | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra line?
# This transpose is needed both at input and output of the LSTM when | ||
# exporting because ONNX will expect (sequence_len, batch, memory_size) | ||
# instead of (batch, sequence_len, memory_size) | ||
h0 = torch.transpose(h0, 0, 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should transpose it before the split into (h0, c0)
as it will be marginally faster and will be symmetrical with the transpose on the output below. But it's not a dealbreaker.
com.unity.ml-agents/CHANGELOG.md
Outdated
@@ -38,7 +39,7 @@ different sizes using the same model. For a summary of the interface changes, pl | |||
|
|||
### Minor Changes | |||
#### com.unity.ml-agents / com.unity.ml-agents.extensions (C#) | |||
- The `.onnx` models input names have changed. All input placeholders will now use the prefix `obs_` removing the distinction between visual and vector observations. Models created with this version will not be usable with previous versions of the package (#5080) | |||
- The `.onnx` models input names have changed. All input placeholders will now use the prefix `obs_` removing the distinction between visual and vector observations. Models created with this version will not be usable with previous versions of the package (#5080, #5236) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add something about LSTM as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor comments but otherwise looks fine
Proposed change(s)
In Barracuda 1.3.3-preview, the LSTM module no longer uses the
_c
and_h
special inputs and outputs. This means that we now have to manually feed the data of the LSTM like any other input/output.This PR contains :
There is a bug in 1.3.3 with Profiler.BeginSample. We would probably need to use the next version for this change.
This change would make running 1.3.2 with new models impossible. Need to address that.
Future releases of barracuda will break backwards compatibility : Meaning that old LSTM models will no longer run with latest barracuda (and ML-Agents).
It seems the next release would need to break compatibility both ways : New models old C# and new C# old models.
This table summarizes the compatibility between barracuda and ml-agents :
KNOWN ISSUE : Updating to barracuda 1.3.3 will generate spam error messages in the console when using LSTM. This issue will be resolved in 1.4.0. We need to update to barracuda 1.4.0 BEFORE the next release.
Useful links (Github issues, JIRA tickets, ML-Agents forum threads etc.)
Types of change(s)
Checklist
Other comments