Skip to content

Commit f36ff2e

Browse files
authored
[ML] Fix PyTorchModelIT::testDeploymentStats (#81161) (#81202)
Adjusts the test's expectations about the information available when deployments are in the `starting` state
1 parent c90bc77 commit f36ff2e

File tree

1 file changed

+21
-11
lines changed
  • x-pack/plugin/ml/qa/native-multi-node-tests/src/javaRestTest/java/org/elasticsearch/xpack/ml/integration

1 file changed

+21
-11
lines changed

x-pack/plugin/ml/qa/native-multi-node-tests/src/javaRestTest/java/org/elasticsearch/xpack/ml/integration/PyTorchModelIT.java

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -241,22 +241,32 @@ public void testDeploymentStats() throws IOException {
241241
CheckedBiConsumer<String, AllocationStatus.State, IOException> assertAtLeast = (modelId, state) -> {
242242
startDeployment(modelId, state.toString());
243243
Response response = getTrainedModelStats(modelId);
244-
List<Map<String, Object>> stats = (List<Map<String, Object>>) entityAsMap(response).get("trained_model_stats");
244+
var responseMap = entityAsMap(response);
245+
List<Map<String, Object>> stats = (List<Map<String, Object>>) responseMap.get("trained_model_stats");
245246
assertThat(stats, hasSize(1));
246247
String statusState = (String) XContentMapValues.extractValue("deployment_stats.allocation_status.state", stats.get(0));
247248
assertThat(stats.toString(), statusState, is(not(nullValue())));
248249
assertThat(AllocationStatus.State.fromString(statusState), greaterThanOrEqualTo(state));
249-
Integer byteSize = (Integer) XContentMapValues.extractValue("deployment_stats.model_size_bytes", stats.get(0));
250-
assertThat(byteSize, is(not(nullValue())));
251-
assertThat(byteSize, equalTo((int) RAW_MODEL_SIZE));
252250

253-
Response humanResponse = client().performRequest(new Request("GET", "/_ml/trained_models/" + modelId + "/_stats?human"));
254-
stats = (List<Map<String, Object>>) entityAsMap(humanResponse).get("trained_model_stats");
255-
assertThat(stats, hasSize(1));
256-
String stringBytes = (String) XContentMapValues.extractValue("deployment_stats.model_size", stats.get(0));
257-
assertThat(stringBytes, is(not(nullValue())));
258-
assertThat(stringBytes, equalTo("1.5kb"));
259-
stopDeployment(model);
251+
// starting models do not know their model size yet
252+
if (state.isAnyOf(AllocationStatus.State.STARTED, AllocationStatus.State.FULLY_ALLOCATED)) {
253+
Integer byteSize = (Integer) XContentMapValues.extractValue("deployment_stats.model_size_bytes", stats.get(0));
254+
assertThat(responseMap.toString(), byteSize, is(not(nullValue())));
255+
assertThat(byteSize, equalTo((int) RAW_MODEL_SIZE));
256+
257+
Response humanResponse = client().performRequest(new Request("GET", "/_ml/trained_models/" + modelId + "/_stats?human"));
258+
var humanResponseMap = entityAsMap(humanResponse);
259+
stats = (List<Map<String, Object>>) humanResponseMap.get("trained_model_stats");
260+
assertThat(stats, hasSize(1));
261+
String stringBytes = (String) XContentMapValues.extractValue("deployment_stats.model_size", stats.get(0));
262+
assertThat(
263+
"stats response: " + responseMap + " human stats response" + humanResponseMap,
264+
stringBytes,
265+
is(not(nullValue()))
266+
);
267+
assertThat(stringBytes, equalTo("1.5kb"));
268+
}
269+
stopDeployment(modelId);
260270
};
261271

262272
assertAtLeast.accept(model, AllocationStatus.State.STARTING);

0 commit comments

Comments
 (0)