elastic / elastic/eland

Simplify model import code

Open
#618 0 comments 2 reactions 0 assignees View on GitHub
enhancement topic:NLP
Dominant language
Python
Stars
693
Forks
112
PR merge metrics
No merged PRs in 30d

Description

## Feature Request
As a Python user, I would like to simplify the code required to load an inference model from Hugging Face (or private source) into Elasticsearch.

## Use Case
Today eland is the way we load inference models into Elasticsearch. Many users will only use eland to load models, making it as simple to use will help the end-user experience.

Currently, in python, it requires several lines of code
eg:
```
hf_model_id='sentence-transformers/msmarco-MiniLM-L-12-v3'
tm = TransformerModel(hf_model_id, "text_embedding")
es_model_id = tm.elasticsearch_model_id()
tmp_path = "models"
Path(tmp_path).mkdir(parents=True, exist_ok=True)
model_path, config, vocab_path = tm.save(tmp_path)
ptm = PyTorchModel(es, es_model_id)
ptm.import_model(model_path=model_path, config_path=None, vocab_path=vocab_path, config=config)
```

This could be abstracted into a simple function call such as `eland.ml.pytorch.import_model` and take in the minimum required parameters. Something like

```
def import_model(
es: Elasticsearch,
model_id: str,
task_type: str = 'text_embedding',
access_token: Union[str, bool] = False
) -> str:
```
where it would return the model_id as it is known in Elasticsearch so it can be used later in the code to call inference

cc: @joshdevins

Contributor guide

Open the contributing guide

Research direction

Start by tracing TransformerModel, PyTorchModel, and PyTorchModel.import_model, then compare them with the proposed eland.ml.pytorch.import_model entry point. Done means a minimal call can load a Hugging Face or private-source model, accept the stated parameters, and return the Elasticsearch model ID.

Written by the indexing model from the issue text.

Assessment

Tech stack
elasticsearch, huggingface, python
Domain
machine-learning
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.