-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ML] Add option to disable inference process cache by default (#108784)
* Add option to disable inference process cache by default * Add test * improve tests * Update docs and improve code --------- Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
- Loading branch information
1 parent
a7e4423
commit a2008bd
Showing
5 changed files
with
96 additions
and
8 deletions.
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
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
70 changes: 70 additions & 0 deletions
70
...org/elasticsearch/xpack/ml/rest/inference/RestStartTrainedModelDeploymentActionTests.java
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,70 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.ml.rest.inference; | ||
|
||
import org.apache.lucene.util.SetOnce; | ||
import org.elasticsearch.common.unit.ByteSizeValue; | ||
import org.elasticsearch.rest.RestRequest; | ||
import org.elasticsearch.test.rest.FakeRestRequest; | ||
import org.elasticsearch.test.rest.RestActionTestCase; | ||
import org.elasticsearch.xpack.core.ml.action.CreateTrainedModelAssignmentAction; | ||
import org.elasticsearch.xpack.core.ml.action.StartTrainedModelDeploymentAction; | ||
import org.elasticsearch.xpack.core.ml.inference.assignment.TrainedModelAssignmentTests; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.Matchers.instanceOf; | ||
|
||
public class RestStartTrainedModelDeploymentActionTests extends RestActionTestCase { | ||
|
||
public void testCacheDisabled() { | ||
final boolean disableInferenceProcessCache = true; | ||
controller().registerHandler(new RestStartTrainedModelDeploymentAction(disableInferenceProcessCache)); | ||
SetOnce<Boolean> executeCalled = new SetOnce<>(); | ||
verifyingClient.setExecuteVerifier(((actionType, actionRequest) -> { | ||
assertThat(actionRequest, instanceOf(StartTrainedModelDeploymentAction.Request.class)); | ||
|
||
var request = (StartTrainedModelDeploymentAction.Request) actionRequest; | ||
assertThat(request.getCacheSize(), is(ByteSizeValue.ZERO)); | ||
|
||
executeCalled.set(true); | ||
return createResponse(); | ||
})); | ||
|
||
RestRequest inferenceRequest = new FakeRestRequest.Builder(xContentRegistry()).withMethod(RestRequest.Method.POST) | ||
.withPath("_ml/trained_models/test_id/deployment/_start") | ||
.build(); | ||
dispatchRequest(inferenceRequest); | ||
assertThat(executeCalled.get(), equalTo(true)); | ||
} | ||
|
||
public void testCacheEnabled() { | ||
final boolean disableInferenceProcessCache = false; | ||
controller().registerHandler(new RestStartTrainedModelDeploymentAction(disableInferenceProcessCache)); | ||
SetOnce<Boolean> executeCalled = new SetOnce<>(); | ||
verifyingClient.setExecuteVerifier(((actionType, actionRequest) -> { | ||
assertThat(actionRequest, instanceOf(StartTrainedModelDeploymentAction.Request.class)); | ||
|
||
var request = (StartTrainedModelDeploymentAction.Request) actionRequest; | ||
assertNull(request.getCacheSize()); | ||
|
||
executeCalled.set(true); | ||
return createResponse(); | ||
})); | ||
|
||
RestRequest inferenceRequest = new FakeRestRequest.Builder(xContentRegistry()).withMethod(RestRequest.Method.POST) | ||
.withPath("_ml/trained_models/test_id/deployment/_start") | ||
.build(); | ||
dispatchRequest(inferenceRequest); | ||
assertThat(executeCalled.get(), equalTo(true)); | ||
} | ||
|
||
private static CreateTrainedModelAssignmentAction.Response createResponse() { | ||
return new CreateTrainedModelAssignmentAction.Response(TrainedModelAssignmentTests.randomInstance()); | ||
} | ||
} |