-
Notifications
You must be signed in to change notification settings - Fork 24.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ML] Merge the pytorch-inference feature branch (#73660)
The feature branch contains changes to configure PyTorch models with a TrainedModelConfig and defines a format to store the binary models. The _start and _stop deployment actions control the model lifecycle and the model can be directly evaluated with the _infer endpoint. 2 Types of NLP tasks are supported: Named Entity Recognition and Fill Mask. The feature branch consists of these PRs: #73523, #72218, #71679 #71323, #71035, #71177, #70713
- Loading branch information
Showing
109 changed files
with
7,067 additions
and
373 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
24 changes: 24 additions & 0 deletions
24
...rest-high-level/src/main/java/org/elasticsearch/client/ml/inference/TrainedModelType.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,24 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.client.ml.inference; | ||
|
||
import java.util.Locale; | ||
|
||
public enum TrainedModelType { | ||
TREE_ENSEMBLE, LANG_IDENT, PYTORCH; | ||
|
||
public static TrainedModelType fromString(String name) { | ||
return valueOf(name.trim().toUpperCase(Locale.ROOT)); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return name().toLowerCase(Locale.ROOT); | ||
} | ||
} |
84 changes: 84 additions & 0 deletions
84
...level/src/main/java/org/elasticsearch/client/ml/inference/trainedmodel/IndexLocation.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,84 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.client.ml.inference.trainedmodel; | ||
|
||
import org.elasticsearch.common.ParseField; | ||
import org.elasticsearch.common.xcontent.ConstructingObjectParser; | ||
import org.elasticsearch.common.xcontent.XContentBuilder; | ||
import org.elasticsearch.common.xcontent.XContentParser; | ||
|
||
import java.io.IOException; | ||
import java.util.Objects; | ||
|
||
public class IndexLocation implements TrainedModelLocation { | ||
|
||
public static final String INDEX = "index"; | ||
private static final ParseField MODEL_ID = new ParseField("model_id"); | ||
private static final ParseField NAME = new ParseField("name"); | ||
|
||
private static final ConstructingObjectParser<IndexLocation, Void> PARSER = | ||
new ConstructingObjectParser<>(INDEX, true, a -> new IndexLocation((String) a[0], (String) a[1])); | ||
|
||
static { | ||
PARSER.declareString(ConstructingObjectParser.constructorArg(), MODEL_ID); | ||
PARSER.declareString(ConstructingObjectParser.constructorArg(), NAME); | ||
} | ||
|
||
public static IndexLocation fromXContent(XContentParser parser) throws IOException { | ||
return PARSER.parse(parser, null); | ||
} | ||
|
||
private final String modelId; | ||
private final String index; | ||
|
||
public IndexLocation(String modelId, String index) { | ||
this.modelId = Objects.requireNonNull(modelId); | ||
this.index = Objects.requireNonNull(index); | ||
} | ||
|
||
public String getModelId() { | ||
return modelId; | ||
} | ||
|
||
public String getIndex() { | ||
return index; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return INDEX; | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
builder.startObject(); | ||
builder.field(NAME.getPreferredName(), index); | ||
builder.field(MODEL_ID.getPreferredName(), modelId); | ||
builder.endObject(); | ||
return builder; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
IndexLocation that = (IndexLocation) o; | ||
return Objects.equals(modelId, that.modelId) | ||
&& Objects.equals(index, that.index); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(modelId, index); | ||
} | ||
} |
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
14 changes: 14 additions & 0 deletions
14
...rc/main/java/org/elasticsearch/client/ml/inference/trainedmodel/TrainedModelLocation.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,14 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.client.ml.inference.trainedmodel; | ||
|
||
import org.elasticsearch.client.ml.inference.NamedXContentObject; | ||
|
||
public interface TrainedModelLocation extends NamedXContentObject { | ||
} |
Oops, something went wrong.