-
-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add registry functions to instantiate models by provider (#428)
* Add provider-specific registry functions. * Update model registry handles used in tests. * Update readme and usage examples. * Update spacy_llm/models/rest/openai/registry.py Co-authored-by: Sofie Van Landeghem <svlandeg@users.noreply.github.com> * Fix HF registry return type. * Fix GPU test error message regexes. * Fix tests. Bump default OAI model to GPT-4. * Fix external tests. * Format. * Ignore LangChain deprecation warning. Ease sentiment tests. * Use GPT-4 for sharding spancat test case. * Relax EL test. Remove unnecessary warning contexts. * Fix comparison in EL test. * Fix GPU tests. --------- Co-authored-by: Sofie Van Landeghem <svlandeg@users.noreply.github.com>
- Loading branch information
Showing
46 changed files
with
363 additions
and
97 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from typing import Any, Dict, Optional | ||
|
||
from confection import SimpleFrozenDict | ||
|
||
from ...registry import registry | ||
from .base import HuggingFace | ||
from .dolly import Dolly | ||
from .falcon import Falcon | ||
from .llama2 import Llama2 | ||
from .mistral import Mistral | ||
from .openllama import OpenLLaMA | ||
from .stablelm import StableLM | ||
|
||
|
||
@registry.llm_models("spacy.HF.v1") | ||
@registry.llm_models("spacy.HuggingFace.v1") | ||
def huggingface_v1( | ||
name: str, | ||
config_init: Optional[Dict[str, Any]] = SimpleFrozenDict(), | ||
config_run: Optional[Dict[str, Any]] = SimpleFrozenDict(), | ||
) -> HuggingFace: | ||
"""Returns HuggingFace model instance. | ||
name (str): Name of model to use. | ||
config_init (Optional[Dict[str, Any]]): HF config for initializing the model. | ||
config_run (Optional[Dict[str, Any]]): HF config for running the model. | ||
RETURNS (Callable[[Iterable[str]], Iterable[str]]): Model instance that can execute a set of prompts and return | ||
the raw responses. | ||
""" | ||
model_context_lengths = { | ||
Dolly: 2048, | ||
Falcon: 2048, | ||
Llama2: 4096, | ||
Mistral: 8000, | ||
OpenLLaMA: 2048, | ||
StableLM: 4096, | ||
} | ||
|
||
for model_cls, context_length in model_context_lengths.items(): | ||
model_names = getattr(model_cls, "MODEL_NAMES") | ||
if model_names and name in model_names.__args__: | ||
return model_cls( | ||
name=name, | ||
config_init=config_init, | ||
config_run=config_run, | ||
context_length=context_length, | ||
) | ||
|
||
raise ValueError( | ||
f"Name {name} could not be associated with any of the supported models. Please check " | ||
f"https://spacy.io/api/large-language-models#models-hf to ensure the specified model name is correct." | ||
) |
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
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
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
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
Oops, something went wrong.