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

[ML] deprecate estimated_heap_memory_usage_bytes and replace with model_size_bytes #80554

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 @@ -45,7 +45,9 @@ public class TrainedModelConfig implements ToXContentObject {
public static final ParseField TAGS = new ParseField("tags");
public static final ParseField METADATA = new ParseField("metadata");
public static final ParseField INPUT = new ParseField("input");
@Deprecated
public static final ParseField ESTIMATED_HEAP_MEMORY_USAGE_BYTES = new ParseField("estimated_heap_memory_usage_bytes");
public static final ParseField MODEL_SIZE_BYTES = new ParseField("model_size_bytes", "estimated_heap_memory_usage_bytes");
public static final ParseField ESTIMATED_OPERATIONS = new ParseField("estimated_operations");
public static final ParseField LICENSE_LEVEL = new ParseField("license_level");
public static final ParseField DEFAULT_FIELD_MAP = new ParseField("default_field_map");
Expand All @@ -70,7 +72,7 @@ public class TrainedModelConfig implements ToXContentObject {
PARSER.declareStringArray(TrainedModelConfig.Builder::setTags, TAGS);
PARSER.declareObject(TrainedModelConfig.Builder::setMetadata, (p, c) -> p.map(), METADATA);
PARSER.declareObject(TrainedModelConfig.Builder::setInput, (p, c) -> TrainedModelInput.fromXContent(p), INPUT);
PARSER.declareLong(TrainedModelConfig.Builder::setEstimatedHeapMemory, ESTIMATED_HEAP_MEMORY_USAGE_BYTES);
PARSER.declareLong(TrainedModelConfig.Builder::setModelSize, MODEL_SIZE_BYTES);
PARSER.declareLong(TrainedModelConfig.Builder::setEstimatedOperations, ESTIMATED_OPERATIONS);
PARSER.declareString(TrainedModelConfig.Builder::setLicenseLevel, LICENSE_LEVEL);
PARSER.declareObject(TrainedModelConfig.Builder::setDefaultFieldMap, (p, c) -> p.mapStrings(), DEFAULT_FIELD_MAP);
Expand Down Expand Up @@ -101,7 +103,7 @@ public static TrainedModelConfig fromXContent(XContentParser parser) throws IOEx
private final List<String> tags;
private final Map<String, Object> metadata;
private final TrainedModelInput input;
private final Long estimatedHeapMemory;
private final Long modelSize;
private final Long estimatedOperations;
private final String licenseLevel;
private final Map<String, String> defaultFieldMap;
Expand All @@ -120,7 +122,7 @@ public static TrainedModelConfig fromXContent(XContentParser parser) throws IOEx
List<String> tags,
Map<String, Object> metadata,
TrainedModelInput input,
Long estimatedHeapMemory,
Long modelSize,
Long estimatedOperations,
String licenseLevel,
Map<String, String> defaultFieldMap,
Expand All @@ -138,7 +140,7 @@ public static TrainedModelConfig fromXContent(XContentParser parser) throws IOEx
this.tags = tags == null ? null : Collections.unmodifiableList(tags);
this.metadata = metadata == null ? null : Collections.unmodifiableMap(metadata);
this.input = input;
this.estimatedHeapMemory = estimatedHeapMemory;
this.modelSize = modelSize;
this.estimatedOperations = estimatedOperations;
this.licenseLevel = licenseLevel;
this.defaultFieldMap = defaultFieldMap == null ? null : Collections.unmodifiableMap(defaultFieldMap);
Expand Down Expand Up @@ -195,16 +197,36 @@ public TrainedModelInput getInput() {
return input;
}

/**
* @deprecated use {@link TrainedModelConfig#getModelSize()} instead
* @return the {@link ByteSizeValue} of the model size if available.
*/
@Deprecated
public ByteSizeValue getEstimatedHeapMemory() {
return estimatedHeapMemory == null ? null : new ByteSizeValue(estimatedHeapMemory);
return modelSize == null ? null : new ByteSizeValue(modelSize);
}

/**
* @deprecated use {@link TrainedModelConfig#getModelSizeBytes()} instead
* @return the model size in bytes if available.
*/
@Deprecated
public Long getEstimatedHeapMemoryBytes() {
return estimatedHeapMemory;
return modelSize;
}

public Long getEstimatedOperations() {
return estimatedOperations;
/**
* @return the {@link ByteSizeValue} of the model size if available.
*/
public ByteSizeValue getModelSize() {
return modelSize == null ? null : new ByteSizeValue(modelSize);
}

/**
* @return the model size in bytes if available.
*/
public Long getModelSizeBytes() {
return modelSize;
}

public String getLicenseLevel() {
Expand Down Expand Up @@ -256,8 +278,8 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
if (input != null) {
builder.field(INPUT.getPreferredName(), input);
}
if (estimatedHeapMemory != null) {
builder.field(ESTIMATED_HEAP_MEMORY_USAGE_BYTES.getPreferredName(), estimatedHeapMemory);
if (modelSize != null) {
builder.field(MODEL_SIZE_BYTES.getPreferredName(), modelSize);
}
if (estimatedOperations != null) {
builder.field(ESTIMATED_OPERATIONS.getPreferredName(), estimatedOperations);
Expand Down Expand Up @@ -301,7 +323,7 @@ public boolean equals(Object o) {
&& Objects.equals(compressedDefinition, that.compressedDefinition)
&& Objects.equals(tags, that.tags)
&& Objects.equals(input, that.input)
&& Objects.equals(estimatedHeapMemory, that.estimatedHeapMemory)
&& Objects.equals(modelSize, that.modelSize)
&& Objects.equals(estimatedOperations, that.estimatedOperations)
&& Objects.equals(licenseLevel, that.licenseLevel)
&& Objects.equals(defaultFieldMap, that.defaultFieldMap)
Expand All @@ -322,7 +344,7 @@ public int hashCode() {
compressedDefinition,
description,
tags,
estimatedHeapMemory,
modelSize,
estimatedOperations,
metadata,
licenseLevel,
Expand All @@ -346,7 +368,7 @@ public static class Builder {
private TrainedModelDefinition definition;
private String compressedDefinition;
private TrainedModelInput input;
private Long estimatedHeapMemory;
private Long modelSize;
private Long estimatedOperations;
private String licenseLevel;
private Map<String, String> defaultFieldMap;
Expand Down Expand Up @@ -431,8 +453,8 @@ public Builder setInput(TrainedModelInput input) {
return this;
}

private Builder setEstimatedHeapMemory(Long estimatedHeapMemory) {
this.estimatedHeapMemory = estimatedHeapMemory;
private Builder setModelSize(Long modelSize) {
this.modelSize = modelSize;
return this;
}

Expand Down Expand Up @@ -469,7 +491,7 @@ public TrainedModelConfig build() {
tags,
metadata,
input,
estimatedHeapMemory,
modelSize,
estimatedOperations,
licenseLevel,
defaultFieldMap,
Expand Down
12 changes: 6 additions & 6 deletions docs/reference/ml/df-analytics/apis/get-trained-models.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ The time when the trained model was created.

`default_field_map` :::
(object)
A string object that contains the default field map to use when inferring
against the model. For example, {dfanalytics} may train the model on a specific
multi-field `foo.keyword`. The analytics job would then supply a default field
A string object that contains the default field map to use when inferring
against the model. For example, {dfanalytics} may train the model on a specific
multi-field `foo.keyword`. The analytics job would then supply a default field
map entry for `"foo" : "foo.keyword"`.
+
Any field map described in the inference configuration takes precedence.
Expand All @@ -120,9 +120,9 @@ Any field map described in the inference configuration takes precedence.
(string)
The free-text description of the trained model.

`estimated_heap_memory_usage_bytes`:::
`model_size_bytes`:::
(integer)
The estimated heap usage in bytes to keep the trained model in memory.
The estimated model size in bytes to keep the trained model in memory.

`estimated_operations`:::
(integer)
Expand All @@ -131,7 +131,7 @@ The estimated number of operations to use the trained model.
`inference_config`:::
(object)
The default configuration for inference. This can be either a `regression`
or `classification` configuration. It must match the `target_type` of the
or `classification` configuration. It must match the `target_type` of the
underlying `definition.trained_model`.
+
.Properties of `inference_config`
Expand Down
13 changes: 8 additions & 5 deletions docs/reference/ml/df-analytics/apis/put-trained-models.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=model-id]
(Optional, boolean)
If set to `true` and a `compressed_definition` is provided, the request defers
definition decompression and skips relevant validations.
This deferral is useful for systems or users that know a good JVM heap size estimate for their
This deferral is useful for systems or users that know a good byte size estimate for their
model and know that their model is valid and likely won't fail during inference.


Expand Down Expand Up @@ -373,10 +373,7 @@ An array of `trained_model` objects. Supported trained models are `tree` and
A human-readable description of the {infer} trained model.

`estimated_heap_memory_usage_bytes`::
(Optional, integer)
The estimated heap usage in bytes to keep the trained model in memory. This
property is supported only if `defer_definition_decompression` is `true` or the
model definition is not supplied.
(Optional, integer) deprecated:[7.16.0,Replaced by `model_size_bytes`]

`estimated_operations`::
(Optional, integer)
Expand Down Expand Up @@ -743,6 +740,12 @@ empty as the index for storing model definitions is configured automatically.
(Optional, object)
An object map that contains metadata about the model.

`model_size_bytes`::
(Optional, integer)
The estimated memory usage in bytes to keep the trained model in memory. This
property is supported only if `defer_definition_decompression` is `true` or the
model definition is not supplied.

`model_type`::
(Optional, string)
The created model type. By default the model type is `tree_ensemble`.
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/rest-api/usage.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ GET /_xpack/usage
"prepackaged": 1,
"other": 0
},
"estimated_heap_memory_usage_bytes": {
"model_size_bytes": {
"min": 0.0,
"max": 0.0,
"avg": 0.0,
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ tasks.named("yamlRestTestV7CompatTransform").configure{ task ->
task.skipTest("indices.freeze/10_basic/Basic", "#70192 -- the freeze index API is removed from 8.0")
task.skipTest("indices.freeze/10_basic/Test index options", "#70192 -- the freeze index API is removed from 8.0")
task.skipTest("ml/categorization_agg/Test categorization aggregation with poor settings", "https://github.com/elastic/elasticsearch/pull/79586")
task.skipTest("ml/inference_crud/Test put with defer_definition_decompression with invalid compression definition and no memory estimate", "https://github.com/elastic/elasticsearch/pull/80554")
task.skipTest("ml/inference_crud/Test put with defer_definition_decompression with invalid compressed definition", "https://github.com/elastic/elasticsearch/pull/80554")

task.replaceValueInMatch("_type", "_doc")
task.addAllowedWarningRegex("\\[types removal\\].*")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import java.io.IOException;
import java.util.Objects;

import static org.elasticsearch.xpack.core.ml.inference.TrainedModelConfig.ESTIMATED_HEAP_MEMORY_USAGE_BYTES;
import static org.elasticsearch.xpack.core.ml.inference.TrainedModelConfig.MODEL_SIZE_BYTES;

public class PutTrainedModelAction extends ActionType<PutTrainedModelAction.Response> {

Expand Down Expand Up @@ -77,13 +77,13 @@ public TrainedModelConfig getTrainedModelConfig() {

@Override
public ActionRequestValidationException validate() {
if (deferDefinitionDecompression && config.getEstimatedHeapMemory() == 0 && config.getCompressedDefinitionIfSet() != null) {
if (deferDefinitionDecompression && config.getModelSize() == 0 && config.getCompressedDefinitionIfSet() != null) {
ActionRequestValidationException validationException = new ActionRequestValidationException();
validationException.addValidationError(
"when ["
+ DEFER_DEFINITION_DECOMPRESSION
+ "] is true and a compressed definition is provided, "
+ ESTIMATED_HEAP_MEMORY_USAGE_BYTES
+ MODEL_SIZE_BYTES
+ " must be set"
);
return validationException;
Expand Down
Loading