Import the trained model and vocabulary
Elastic Cloud Serverless projects are autoscaled environments, fully managed by Elastic and available on Elastic Cloud. Availability This functionality is generally available and ready for production usage. Serverless interfaces and procedures might differ from classic Elastic Stack deployments. The Elastic Stack includes Elastic's core products such as Elasticsearch, Kibana, Logstash, and Beats. Availability This functionality is generally available and ready for production usage. Unless stated otherwise on the page, this functionality is available when your Elastic Stack is deployed on Elastic Cloud Hosted, Elastic Cloud Enterprise, Elastic Cloud on Kubernetes, and self-managed environments. This documentation corresponds to the latest patch available for each minor version. If you're not using the latest patch, check the release notes for changes.
Serverless
Generally available
Stack
Generally available
PyTorch models can execute code on your Elasticsearch server, exposing your cluster to potential security vulnerabilities.
Only use models from trusted sources and never use models from unverified or unknown providers.
If you want to install a trained model in a restricted or closed network, refer to these instructions.
After you choose a model, you must import it and its tokenizer vocabulary to your cluster. When you import the model, it must be chunked and imported one chunk at a time for storage in parts due to its size.
Trained models must be in a TorchScript representation for use with Elastic Stack machine learning features.
Eland is an Elasticsearch Python client that provides a simple script to perform the conversion of Hugging Face transformer models to their TorchScript representations, the chunking process, and upload to Elasticsearch; it is therefore the recommended import method. You can either install the Python Eland client on your machine or use a Docker image to build Eland and run the model import script.
Install the Eland Python client with PyTorch extra dependencies.
Shell python -m pip install 'eland[pytorch]'Run the
eland_import_hub_modelscript to download the model from Hugging Face, convert it to TorchScript format, and upload to the Elasticsearch cluster. For example:Text eland_import_hub_model \ --url <url> \ --es-api-key <api-key> \ --hub-model-id elastic/distilbert-base-cased-finetuned-conll03-english \ --task-type ner- Specify your Elasticsearch cluster URL.
- Specify an API key to securely access your cluster. Refer to Authentication methods to learn more.
- Specify the identifier for the model in the Hugging Face model hub.
- Specify the type of NLP task. Supported values are
fill_mask,ner,question_answering,text_classification,text_embedding,text_expansion,text_similarity, andzero_shot_classification.
For more details, refer to the Eland documentation.
If you want to use Eland without installing it, run the following command:
$ docker run -it --rm --network host docker.elastic.co/eland/eland
The eland_import_hub_model script can be run directly in the docker command:
docker run -it --rm docker.elastic.co/eland/eland \
eland_import_hub_model \
--url $ELASTICSEARCH_URL \
--hub-model-id elastic/distilbert-base-uncased-finetuned-conll03-english \
--start
Replace the $ELASTICSEARCH_URL with the URL for your Elasticsearch cluster. Refer to Authentication methods to learn more.
The following authentication options are available when using the import script:
- username/password authentication (specified with the
-uand-poptions):
eland_import_hub_model --url https://<hostname>:<port> -u <username> -p <password> ...
- username/password authentication (embedded in the URL):
eland_import_hub_model --url https://<user>:<password>@<hostname>:<port> ...
- API key authentication:
eland_import_hub_model --url https://<hostname>:<port> --es-api-key <api-key> ...