[17/n] Pass monarch tensors to actor endpoints, part 2, actor messages sent in order #539
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Stack from ghstack (oldest at bottom):
When you send a monarch.Tensor to an actor, what actually happens is that you instruct the stream managing the tensor to send the tensor to the actor.
In part 1, that stream directly told the actor what method to call, and where to send the result. The issue with that is ordering: from the perspective of the original caller it is as if we are sending a message to the actor directly. If the stream sends the message it is possible that it arrives out of order with respect to a message that goes directly to the actor (e.g. a message that contains no monarch.Tensors).
This resolves ordering issue: now the client sends a message to the actor 'CallMethodIndirect' that provides the pickled args/kwargs and method to invoke.
The local python values of the torch.Tensors still need to come from Stream actor, so CallMethodIndirect looks them up by messaging the (new) LocalStateBrokerActor which can transfer PyObjects between local actors without serialization.
Ordering is guarenteed for both tensors and actors because a message is sent to both the receiving actor and the stream actor at the same time.
Differential Revision: D78314012