-
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
V2 staging new model version #5080
Conversation
com.unity.ml-agents/Runtime/Inference/BarracudaModelParamLoader.cs
Outdated
Show resolved
Hide resolved
/// <param name="sensors">Attached sensors</param> | ||
/// <param name="observableAttributeTotalSize">Sum of the sizes of all ObservableAttributes.</param> | ||
/// <returns>The list the error messages of the checks that failed</returns> | ||
static IEnumerable<FailedCheck> CheckInputTensorShape( |
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.
Can you reuse any of the code between this and CheckInputTensorShapeLegacy? I haven't done a side-by-side diff, but looks like it might be cleaner to make legacy an argument instead.
Same comments apply to CheckInputTensorPresence/CheckInputTensorPresenceLegacy
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 was thinking reusing code, but I think I still prefer having separate methods (even if it duplicates a lot of the code). My thinking is that is will make it easier to deprecate or isolate this code later and make it easier to test 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.
No major objections, but I think it needs some cleanup.
{ | ||
if (!tensorTester.ContainsKey(tensor.name)) | ||
{ | ||
failedModelChecks.Add(FailedCheck.Warning("Model requires an unknown input named : " + tensor.name |
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.
The presence of legacy tensors names will be checked here.
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.
Not sure the warning message makes sense then. Should it be something like $"Model contains an unexpected input named: {tensor.name}"
com.unity.ml-agents/Runtime/Inference/BarracudaModelParamLoader.cs
Outdated
Show resolved
Hide resolved
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.
One more thing would be nice to do in PR is to export an array of branch sizes instead of a sum for discrete action sizes, and also update the model loader checks.
@dongruoping Please review this PR that will do what you suggested : #5092 |
} | ||
else | ||
{ | ||
int result = 0; |
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.
This is a behavior change for legacy models, right? Is it correct?
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.
It is not. (Unless I messed it up)
Because discreteOutputShape is currently a tensor of shape 1 ([sum_of_branches]) and will be changed to be ([branh0_size, branch1_size, ...]). So doing the sum does the same thing wether it is legacy or new.
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.
OK, thanks. Could you leave that as a comment here for the future readers?
@@ -58,47 +89,68 @@ internal class BarracudaModelParamLoader | |||
return failedModelChecks; | |||
} | |||
|
|||
var modelApiVersion = (int)model.GetTensorByName(TensorNames.VersionNumber)[0]; | |||
var modelApiVersion = model.GetVersion(); |
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.
Can this actually return -1? Doesn't look like it from https://github.com/Unity-Technologies/ml-agents/pull/5080/files#diff-bf1591d220fea33b1512200891dc1d8000f844664308187d2beaaaff8feb657aR49-R52 (unless that's the actual value).
Seems like this could be combined with the one below.
return failedModelChecks; | ||
} | ||
|
||
var modelVersion = model.GetVersion(); |
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.
nit: you already have modelApiVersion
above.
com.unity.ml-agents/Runtime/Inference/BarracudaModelParamLoader.cs
Outdated
Show resolved
Hide resolved
@@ -63,8 +63,7 @@ static List<TestAgent> GetFakeAgents(ObservableAttributeOptions observableAttrib | |||
return agents; | |||
} | |||
|
|||
[Test] | |||
public void Construction() | |||
public void Construction(int apiVersion) |
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.
What's going on here? It will no longer be called as a test, and doesn't look like it's called anywhere else (at least not in this file).
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.
You are right, this is unit test was not being used properly, I modified t back so it will run (There was another test in a similar situation that I also changed)
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.
Some small extra feedback but looks good.
…r.cs Co-authored-by: Chris Elion <[email protected]>
* Make modelCheck have flavors of error messages * ONNX exporter v3 * Using a better CheckType and a switch statement * Removing unused message * More tests * Use an enum for valid versions and use GetVersion on model directly * Maybe the model export version a static constant in Python * Use static constructor for FailedCheck * Use static constructor for FailedCheck * Modifying the docstrings * renaming LegacyDiscreteActionOutputApplier * removing testing code * better warning message * Nest the CheckTypeEnum into the FailedCheck class * Update com.unity.ml-agents/Runtime/Inference/BarracudaModelParamLoader.cs * Adding a line explaining that legacy tensor checks are for versions 1.X only * Modifying the changelog * Exporting all the branches size instead of omly the sum (#5092) * addressing comments * Update com.unity.ml-agents/Runtime/Inference/BarracudaModelParamLoader.cs Co-authored-by: Chris Elion <[email protected]> * readding tests * Adding a comment around the new DiscreteOutputSize method * Clearer warning : Model contains unexpected input > Model requires unknown input * Fixing a bug in the case where the discrete action tensor does not exist Co-authored-by: Chris Elion <[email protected]>
* Make modelCheck have flavors of error messages * ONNX exporter v3 * Using a better CheckType and a switch statement * Removing unused message * More tests * Use an enum for valid versions and use GetVersion on model directly * Maybe the model export version a static constant in Python * Use static constructor for FailedCheck * Use static constructor for FailedCheck * Modifying the docstrings * renaming LegacyDiscreteActionOutputApplier * removing testing code * better warning message * Nest the CheckTypeEnum into the FailedCheck class * Update com.unity.ml-agents/Runtime/Inference/BarracudaModelParamLoader.cs * Adding a line explaining that legacy tensor checks are for versions 1.X only * Modifying the changelog * Exporting all the branches size instead of omly the sum (#5092) * addressing comments * Update com.unity.ml-agents/Runtime/Inference/BarracudaModelParamLoader.cs Co-authored-by: Chris Elion <[email protected]> * readding tests * Adding a comment around the new DiscreteOutputSize method * Clearer warning : Model contains unexpected input > Model requires unknown input * Fixing a bug in the case where the discrete action tensor does not exist Co-authored-by: Chris Elion <[email protected]>
Proposed change(s)
BREAKING: Models trained with the latest Python will no longer work with pre 2.0 Unity package.
Need some changes to the changelog
Useful links (Github issues, JIRA tickets, ML-Agents forum threads etc.)
Slack messages
JIRA : 1319 and 1626
Types of change(s)
Checklist
Other comments