-
Notifications
You must be signed in to change notification settings - Fork 25k
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
[ML] Fix loss of context in the inference API for streaming APIs #118999
Merged
jonathan-buttner
merged 6 commits into
elastic:main
from
jonathan-buttner:ml-streaming-lost-context
Dec 23, 2024
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b0f2b4f
Adding context preserving fix
jonathan-buttner dc42a3d
Update docs/changelog/118999.yaml
jonathan-buttner 6623daa
Update docs/changelog/118999.yaml
jonathan-buttner 6a986d8
Using a setonce and adding a test
jonathan-buttner 118397b
Updating the changelog
jonathan-buttner 34cbecb
Merge branch 'main' of github.com:elastic/elasticsearch into ml-strea…
jonathan-buttner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
pr: 118999 | ||
summary: Fix loss of context in the inference API for streaming APIs | ||
area: Machine Learning | ||
type: bug | ||
issues: | ||
- 119000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
package org.elasticsearch.xpack.inference; | ||
|
||
import org.apache.http.util.EntityUtils; | ||
import org.elasticsearch.client.Response; | ||
import org.elasticsearch.client.ResponseException; | ||
import org.elasticsearch.common.Strings; | ||
import org.elasticsearch.common.settings.Settings; | ||
|
@@ -28,6 +29,7 @@ | |
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.Set; | ||
import java.util.function.Consumer; | ||
import java.util.function.Function; | ||
import java.util.stream.IntStream; | ||
import java.util.stream.Stream; | ||
|
@@ -37,9 +39,15 @@ | |
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.Matchers.equalToIgnoringCase; | ||
import static org.hamcrest.Matchers.hasSize; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
public class InferenceCrudIT extends InferenceBaseRestTest { | ||
|
||
private static final Consumer<Response> VALIDATE_ELASTIC_PRODUCT_HEADER_CONSUMER = (r) -> assertThat( | ||
r.getHeader("X-elastic-product"), | ||
is("Elasticsearch") | ||
); | ||
|
||
@SuppressWarnings("unchecked") | ||
public void testCRUD() throws IOException { | ||
for (int i = 0; i < 5; i++) { | ||
|
@@ -442,7 +450,7 @@ public void testUnsupportedStream() throws Exception { | |
assertEquals(TaskType.SPARSE_EMBEDDING.toString(), singleModel.get("task_type")); | ||
|
||
try { | ||
var events = streamInferOnMockService(modelId, TaskType.SPARSE_EMBEDDING, List.of(randomUUID())); | ||
var events = streamInferOnMockService(modelId, TaskType.SPARSE_EMBEDDING, List.of(randomUUID()), null); | ||
assertThat(events.size(), equalTo(2)); | ||
events.forEach(event -> { | ||
switch (event.name()) { | ||
|
@@ -469,7 +477,7 @@ public void testSupportedStream() throws Exception { | |
|
||
var input = IntStream.range(1, 2 + randomInt(8)).mapToObj(i -> randomAlphanumericOfLength(5)).toList(); | ||
try { | ||
var events = streamInferOnMockService(modelId, TaskType.COMPLETION, input); | ||
var events = streamInferOnMockService(modelId, TaskType.COMPLETION, input, VALIDATE_ELASTIC_PRODUCT_HEADER_CONSUMER); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately, even if I remove my change this test still passes. I opted for keeping these tests just in case something really goes wrong in the future but they wouldn't have caught the original issue 😞 |
||
|
||
var expectedResponses = Stream.concat( | ||
input.stream().map(s -> s.toUpperCase(Locale.ROOT)).map(str -> "{\"completion\":[{\"delta\":\"" + str + "\"}]}"), | ||
|
@@ -496,7 +504,7 @@ public void testUnifiedCompletionInference() throws Exception { | |
|
||
var input = IntStream.range(1, 2 + randomInt(8)).mapToObj(i -> randomAlphanumericOfLength(5)).toList(); | ||
try { | ||
var events = unifiedCompletionInferOnMockService(modelId, TaskType.COMPLETION, input); | ||
var events = unifiedCompletionInferOnMockService(modelId, TaskType.COMPLETION, input, VALIDATE_ELASTIC_PRODUCT_HEADER_CONSUMER); | ||
var expectedResponses = expectedResultsIterator(input); | ||
assertThat(events.size(), equalTo((input.size() + 1) * 2)); | ||
events.forEach(event -> { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
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.
Adding a way to get the response so we can check the headers