Skip to content
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

Fix scale up for model allocations #115189

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public boolean isEmpty() {
return anomalyDetectionTasks.isEmpty()
&& snapshotUpgradeTasks.isEmpty()
&& dataframeAnalyticsTasks.isEmpty()
&& modelAssignments.values().stream().allMatch(assignment -> assignment.totalTargetAllocations() == 0);
&& modelAssignments.values().stream().allMatch(assignment -> assignment.getTaskParams().getNumberOfAllocations() == 0);
Copy link
Contributor Author

@jan-elastic jan-elastic Oct 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is so confusing...

Anyway, assignment.totalTargetAllocations() is the number of allocations assigned to ML nodes, but if there are no nodes, there are no assigned allocations. assignment.getTaskParams().getNumberOfAllocations() is the number that's wanted.

I've also added a test for this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh because if there are no ml nodes in the cluster assignment.totalTargetAllocations() == 0 even if assignment.getTaskParams().getNumberOfAllocations() > 0

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, indeed

}

public List<String> findPartiallyAllocatedModels() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import static org.elasticsearch.xpack.ml.utils.NativeMemoryCalculator.STATIC_JVM_UPPER_THRESHOLD;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
import static org.mockito.ArgumentMatchers.any;
Expand Down Expand Up @@ -331,6 +332,53 @@ public void testScale_GivenModelWithZeroAllocations() {
assertThat(result.requiredCapacity().node().memory().getBytes(), equalTo(0L));
}

public void testScale_GivenTrainedModelAllocationAndNoMlNode() {
MlAutoscalingDeciderService service = buildService();
service.onMaster();

ClusterState clusterState = new ClusterState.Builder(new ClusterName("cluster")).metadata(
Metadata.builder()
.putCustom(
TrainedModelAssignmentMetadata.NAME,
new TrainedModelAssignmentMetadata(
Map.of(
"model",
TrainedModelAssignment.Builder.empty(
new StartTrainedModelDeploymentAction.TaskParams(
"model",
"model-deployment",
400,
1,
2,
100,
null,
Priority.NORMAL,
0L,
0L
),
new AdaptiveAllocationsSettings(true, 0, 4)
).setAssignmentState(AssignmentState.STARTING).build()
)
)
)
.build()
).build();

AutoscalingDeciderResult result = service.scale(
Settings.EMPTY,
new DeciderContext(
clusterState,
new AutoscalingCapacity(AutoscalingCapacity.AutoscalingResources.ZERO, AutoscalingCapacity.AutoscalingResources.ZERO)
)
);

assertThat(result.reason().summary(), containsString("requesting scale up"));
assertThat(result.requiredCapacity().total().memory().getBytes(), greaterThan(TEST_JOB_SIZE));
assertThat(result.requiredCapacity().total().processors().count(), equalTo(2.0));
assertThat(result.requiredCapacity().node().memory().getBytes(), greaterThan(TEST_JOB_SIZE));
assertThat(result.requiredCapacity().node().processors().count(), equalTo(2.0));
}

private DiscoveryNode buildNode(String id, ByteSizeValue machineMemory, int allocatedProcessors) {
return DiscoveryNodeUtils.create(
id,
Expand Down
Loading