-
Notifications
You must be signed in to change notification settings - Fork 35
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
Upgrade to Sentis 2.1 #18
base: main
Are you sure you want to change the base?
Conversation
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 doesn't compile, you need to update the manifest.json and packages.json files for each updated project so it uses the correct sentis version
under dependencies there should be
"com.unity.sentis": "2.1.0"
don't forget to do this for the blaze samples too
bestMove /= redSum; | ||
|
||
var bestMoveModel = graph.Compile(boardState, bestMove); | ||
bestMoveModel.AddOutput("board_state", 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 isn't quite right, the model already has the outputs, once you do this the model has 4 outputs and the last two are indexing the wrong tensors. just delete these two lines and then later do
var bestMove = m_Engine.PeekOutput(1) as Tensor;
etc
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 can see this if you run the demo
AssertionException: Cannot peek output tensor best_move as model does not contain an output with that name
@@ -565,7 +567,6 @@ private void OnApplicationQuit() | |||
m_Engine?.Dispose(); | |||
m_MoveProbabilities.Dispose(); |
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.
if i open and close the demo then i get a crash because this can be null, you didn't add this issue but it would be good to fix it by making this
m_MoveProbabilities?.Dispose();
TensorFloat m_Data = TensorFloat.Zeros(new TensorShape(1, 1, kBoardDimension, kBoardDimension)); | ||
float[] m_LegalMoves = new float[kBoardDimension * kBoardDimension + 1]; | ||
TensorFloat m_MoveProbabilities = null; | ||
Tensor<float> m_Data = new(new TensorShape(1, 1, kBoardDimension, kBoardDimension)); |
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.
use the explicit constructor for clarity in our samples
Tensor<float> m_Data = new Tensor<float>(new TensorShape(1, 1, kBoardDimension, kBoardDimension));
|
||
m_MoveProbabilities = bestMove; | ||
m_MoveProbabilities.TakeOwnership(); | ||
m_MoveProbabilities = bestMove.ReadbackAndClone(); |
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 creates a new tensor each time ComputerMove is run, and tensors need to be disposed, which this isn't
since the shape of m_MoveProbabilities doesn't change a better pattern would be to create m_MoveProbabilities at the start and then read the values into m_MoveProbabilities from the worker
Tensor m_MoveProbabilities = ...;
.
.
.
m_Engine.CopyOutput(1, ref m_MoveProbabilities);
@@ -13,8 +13,7 @@ public class Othello : MonoBehaviour | |||
{ | |||
// Sentis |
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 get a warning for this project like:
Assets/Scenes/Garden/Scripts/Runtime/WashiLightController.cs(182,21): warning CS0618: 'Object.FindObjectsOfType(bool)' is obsolete: 'Object.FindObjectsOfType has been deprecated. Use Object.FindObjectsByType instead which lets you decide whether you need the results sorted or not. FindObjectsOfType sorts the results by InstanceID but if you do not need this using FindObjectSortMode.None is considerably faster.'
i know it's not your code but we should clean things up so our samples aren't throwing warnings
@@ -25,6 +25,6 @@ void OnControllerColliderHit(ControllerColliderHit hit) | |||
} | |||
|
|||
Vector3 pushDir = new Vector3(hit.moveDirection.x, 0, hit.moveDirection.z); | |||
body.velocity = pushDir * pushPower; | |||
body.linearVelocity = pushDir * pushPower; |
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 doesn't compile for me in unity 2023.2
@@ -3,25 +3,21 @@ | |||
|
|||
public class Gravity : MonoBehaviour |
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 get undisposed tensors when i run this demo, please track them down :)
TensorFloat x = TensorFloat.AllocZeros(new TensorShape(1, N, 3)); // positions | ||
TensorFloat p = TensorFloat.AllocZeros(new TensorShape(N, 3)); // momentum (= mass * velocity) | ||
TensorFloat m = TensorFloat.AllocZeros(new TensorShape(N)); // mass | ||
Tensor<float> x = new (new TensorShape(1, N, 3)); // positions |
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: use the explicit constructor
} | ||
|
||
void Update() | ||
{ | ||
worker.SetInput("input_0", x); | ||
worker.SetInput("input_1", m); | ||
worker.SetInput("input_2", p); | ||
worker.Execute(); | ||
worker.Schedule(); |
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: rewrite as
worker.Schedule(x, m, p);
it's cleaner
|
||
backend.MemCopy(p_n, p); | ||
backend.MemCopy(x_n, x); | ||
p = p_n.ReadbackAndClone(); |
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 these aren't being disposed every frame, it would be better to preallocate them once and then use the
worker.CopyOutput method
@@ -1,16 +1,17 @@ | |||
{ | |||
"dependencies": { | |||
"com.unity.ai.navigation": "2.0.0", | |||
"com.unity.collab-proxy": "2.4.4", | |||
"com.unity.ai.navigation": "2.0.5", |
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.
just change the sentis version please
No description provided.