Skip to content

fix: Return the local result of a streaming serving from a distributed batched_run - #1902

Closed
georgeguimaraes wants to merge 1 commit into
elixir-nx:mainfrom
georgeguimaraes:distributed-stream-result
Closed

georgeguimaraes wants to merge 1 commit into
elixir-nx:mainfrom
georgeguimaraes:distributed-stream-result

Conversation

@georgeguimaraes

Copy link
Copy Markdown
Member

A distributed batched_run of a streaming serving always returns a stream. The remote node enumerates the result of client_postprocessing and sends each element. When client_postprocessing collects the stream into a map, a local call returns the map, but a distributed call returns a stream that enumerates to a keyword list.

Example: a serving uses Nx.Serving.streaming/1 because the outputs of its batches have different shapes, and its client_postprocessing returns %{results: [...]}. On another node, batched_run returns a stream of {:results, [...]}.

This change streams the result only when client_postprocessing returns a stream or a function. Other results go to the caller as one value, as in :execute mode. The behavior of :execute mode does not change.

The test fails on main: the caller gets a Stream.resource/3 function instead of the map.

…ched_run

A distributed call of a streaming serving always returned a stream of the elements of the client postprocessing result. When the postprocessing returned a map, the caller got a keyword list. A local call returns the map.

Now the remote node streams the result only when the client postprocessing returns a stream. Otherwise it sends the result as one value.
@georgeguimaraes

Copy link
Copy Markdown
Member Author

I close this PR. The docs of streaming/2 say that run/2 and batched_run/2 return a stream for a streaming serving, so the distributed result follows the contract. The problem is in my library: it uses streaming/2 only so that Nx does not join batches of different shapes, and its client postprocessing returns a map. I will fix this in the library with :execute mode.

@georgeguimaraes

Copy link
Copy Markdown
Member Author

sorry, this should not be opened =/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant