Skip to content

Commit

Permalink
[ML] Assume ELSER v2 has the same memory requirement as ELSER v1
Browse files Browse the repository at this point in the history
While we wait for our improved memory estimation functionality
we can continue to use the same hardcoded ELSER memory requirement
for v2 that we used for v1. The hardcoded value is likely an
overestimate, but we don't have time to do anything better for
the current release.
  • Loading branch information
droberts195 committed Sep 20, 2023
1 parent 0ad8aba commit 6fae9ac
Showing 1 changed file with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ public class StartTrainedModelDeploymentAction extends ActionType<CreateTrainedM
private static final ByteSizeValue MEMORY_OVERHEAD = ByteSizeValue.ofMb(240);

/**
* The ELSER model turned out to use more memory then what we usually estimate.
* We overwrite the estimate with this static value for ELSER V1 for now. Soon to be
* replaced with a better estimate provided by the model.
* The ELSER model turned out to use more memory than what we usually estimate.
* We overwrite the estimate with this static value for ELSER v1 and v2 for now.
* Soon to be replaced with a better estimate provided by the model.
*/
private static final ByteSizeValue ELSER_1_MEMORY_USAGE = ByteSizeValue.ofMb(2004);
private static final ByteSizeValue ELSER_1_OR_2_MEMORY_USAGE = ByteSizeValue.ofMb(2004);

public StartTrainedModelDeploymentAction() {
super(NAME, CreateTrainedModelAssignmentAction.Response::new);
Expand Down Expand Up @@ -713,14 +713,14 @@ public static long estimateMemoryUsageBytes(
) {
// While loading the model in the process we need twice the model size.

// 1. If ELSER v1 then 2004MB
// 1. If ELSER v1 or v2 then 2004MB
// 2. If static memory and dynamic memory are not set then 240MB + 2 * model size
// 3. Else static memory + dynamic memory * allocations + model size

// The model size is still added in option 3 to account for the temporary requirement to hold the zip file in memory
// in `pytorch_inference`.
if (isElserV1Model(modelId)) {
return ELSER_1_MEMORY_USAGE.getBytes();
// in `pytorch_inference`.
if (isElserV1Or2Model(modelId)) {
return ELSER_1_OR_2_MEMORY_USAGE.getBytes();
} else {
long baseSize = MEMORY_OVERHEAD.getBytes() + 2 * totalDefinitionLength;
if (perDeploymentMemoryBytes == 0 && perAllocationMemoryBytes == 0) {
Expand All @@ -734,7 +734,7 @@ public static long estimateMemoryUsageBytes(
}
}

private static boolean isElserV1Model(String modelId) {
return modelId.startsWith(".elser_model_1");
private static boolean isElserV1Or2Model(String modelId) {
return modelId.startsWith(".elser_model_1") || modelId.startsWith(".elser_model_2");
}
}

0 comments on commit 6fae9ac

Please sign in to comment.