-
-
Notifications
You must be signed in to change notification settings - Fork 106
Add registry functions to instantiate models by provider #428
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
ad30add
Merge pull request #427 from explosion/main
rmitsch cd082ed
Add provider-specific registry functions.
rmitsch b83aa0a
Update model registry handles used in tests.
rmitsch ce9f429
Update readme and usage examples.
rmitsch a97bbe1
Update spacy_llm/models/rest/openai/registry.py
rmitsch 91a1ee0
Fix HF registry return type.
rmitsch 3680271
Fix GPU test error message regexes.
rmitsch c410ab7
Fix tests. Bump default OAI model to GPT-4.
rmitsch ed20c44
Fix external tests.
rmitsch b1339de
Merge branch 'main' into refactor/model-registry-by-provider
rmitsch d02bd41
Format.
rmitsch 5cd5c64
Merge branch 'refactor/model-registry-by-provider' of github.com:expl…
rmitsch 174ef84
Ignore LangChain deprecation warning. Ease sentiment tests.
rmitsch 7653a7b
Use GPT-4 for sharding spancat test case.
rmitsch 304b82c
Relax EL test. Remove unnecessary warning contexts.
rmitsch a5109e2
Fix comparison in EL test.
rmitsch f25092d
Fix GPU tests.
rmitsch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,50 @@ | ||
| from typing import Any, Callable, Dict, Iterable, Optional | ||
|
|
||
| from confection import SimpleFrozenDict | ||
|
|
||
| from ...registry import registry | ||
| 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(), | ||
| ) -> Callable[[Iterable[Iterable[str]]], Iterable[Iterable[str]]]: | ||
| """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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.