Skip to content
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

Refactor backend -> model #176

Merged
merged 49 commits into from
Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
51ca50c
Refactor backend -> model.
rmitsch Jun 19, 2023
90739e5
Fix Literal imports.
rmitsch Jun 19, 2023
3db4ffb
Fix REST init test. Use suffix for OpenAI models.
rmitsch Jun 19, 2023
cbd578c
Change pre- to suffixes for Cohere and Anthropic models.
rmitsch Jun 19, 2023
a95040a
Merge branch 'develop' into refactor/backend-to-models
rmitsch Jun 19, 2023
f39f1d4
Update OpenAI models.
rmitsch Jun 20, 2023
2611542
Change OpenLLaMa to OpenLLaMA.
rmitsch Jun 21, 2023
06c22fd
Fix OpenLLaMA renaming.
rmitsch Jun 21, 2023
f78adfc
Update variant -> name.
rmitsch Jun 22, 2023
4b967dd
Drop MiniChain. Remove API suffixes from model registration handles.
rmitsch Jun 22, 2023
9e1f406
Replace dots in model names with dashes.
rmitsch Jun 22, 2023
7b96692
Format readme.
rmitsch Jun 22, 2023
4b4002f
Add dynamic registration of LangChain APIs as model functions. Fix us…
rmitsch Jun 22, 2023
26e3c6c
Merge branch 'develop' into refactor/backend-to-models
rmitsch Jun 22, 2023
6cd6101
Check for langchain availability before registration.
rmitsch Jun 22, 2023
b068e1d
Make HF model name setting more robust. Unify Literal handling in HF …
rmitsch Jun 26, 2023
01c6ad7
Fix Literal import.
rmitsch Jun 26, 2023
05c4ee2
Fix Literal import.
rmitsch Jun 26, 2023
049e8de
Merge branch 'refactor/backend-to-models' of github.com:explosion/spa…
rmitsch Jun 26, 2023
70fa932
Reintroduce public method for supported model names. Clean up and sta…
rmitsch Jun 27, 2023
670ca68
Attempt to resolve cyclic import.
rmitsch Jun 27, 2023
a3dafc4
Move LangChain availability checks into .register_models().
rmitsch Jun 27, 2023
8b3bab3
Expand comments.
rmitsch Jun 27, 2023
b1916ed
Fix Literal import.
rmitsch Jun 27, 2023
1a386fe
Update spacy_llm/models/hf/base.py
rmitsch Jun 28, 2023
8d6ae3f
Incorporate feedback.
rmitsch Jun 28, 2023
b9305f4
Update readme.
rmitsch Jun 28, 2023
502697f
Add migration guide. Pull model name from config dict for LangChain m…
rmitsch Jun 28, 2023
45b0a21
Ignore LangChain class installation warning.
rmitsch Jun 28, 2023
5dd2ad4
Fix failing tests due to changes in OpenAI model behavior.
rmitsch Jun 28, 2023
8ebe1d8
Change config spec in test_combinations().
rmitsch Jun 28, 2023
bb194c6
Small refactoring of LangChain model class.
rmitsch Jun 28, 2023
2893606
Fix import error.
rmitsch Jun 28, 2023
0cc07ab
Fix import error.
rmitsch Jun 28, 2023
011885b
Bump version.
rmitsch Jun 28, 2023
4f18796
Merge branch 'develop' into refactor/backend-to-models
rmitsch Jun 28, 2023
5b537fd
Add debug message.
rmitsch Jun 28, 2023
e7c556c
Attempt to fix LangChain registration issue.
rmitsch Jun 29, 2023
f3333f6
Attempt to fix LangChain registration issue.
rmitsch Jun 29, 2023
81a535e
Apply suggestions from code review
rmitsch Jun 29, 2023
5bc5993
Add openai dependency in dev requirements.
rmitsch Jun 29, 2023
7ea3ec0
Apply suggestions from code review
rmitsch Jun 29, 2023
3590ae9
Fix Anthropic test errors.
rmitsch Jun 29, 2023
ed88b0f
Fix some tests.
rmitsch Jun 29, 2023
6c4bc79
Fix another test.
rmitsch Jun 29, 2023
912a75e
Fix another test.
rmitsch Jun 29, 2023
57bc905
Remove TypeVars for HF and LangChain models.
rmitsch Jun 29, 2023
d3f3e74
Lower temperature for lemma tests.
rmitsch Jun 29, 2023
fee5cef
Update readme. Fix REL tests.
rmitsch Jun 29, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
198 changes: 83 additions & 115 deletions README.md

Large diffs are not rendered by default.

85 changes: 85 additions & 0 deletions migration_guide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Migration guides

<details open>
<summary>0.3.x to 0.4.x</summary>

## `0.3.x` to `0.4.x`

`0.4.x` significantly refactors the code to make it more robust and the config more intuitive. 0.4.0 changes the config
paradigm from backend- to model-centric. This is reflected in the external API in a different config structure.
rmitsch marked this conversation as resolved.
Show resolved Hide resolved

Remember that there are three different types of models: the first uses the native REST implementation to communicate
with hosted LLMs, the second builds on HuggingFace's `transformers` model to run models locally and the third leverages
`langchain` to operate on hosted or local models. While they config for all three is rather similar (especially in
rmitsch marked this conversation as resolved.
Show resolved Hide resolved
0.4.x), there are differences in how these models have to be configured. We show how to migrate your config from 0.3.x
to 0.4.x for each of these model types.

For all model types:
rmitsch marked this conversation as resolved.
Show resolved Hide resolved
- The registry name has changed - instead of `llm_backends`, use `llm_models`.
rmitsch marked this conversation as resolved.
Show resolved Hide resolved
- The `api` attribute has been removed.

### Models using REST

This is the default method to communicate with hosted models. Whenever you don't explicitly use LangChain models
(see section at the bottom) or run models locally, you are using this kind of model.

In `0.3.x`:
```ini
[components.llm.backend]
@llm_backends = "spacy.REST.v1"
api = "OpenAI"
config = {"model": "gpt-3.5-turbo", "temperature": 0.3}
```
In `0.4.x`:
```ini
[components.llm.model]
@llm_models = "spacy.gpt-3-5.v1"
name = "gpt-3-5-turbo"
config = {"temperature": 0.3}
```
Note that the factory function (marked with `@`) refers to the name of the model. Variants of the same model can be
specified with the `name` attribute - for `gpt-3.5` this could be `"gpt-3-5-turbo"` or `"gpt-3-5-turbo-16k"`.

### Models using HuggingFace

On top of the changes described in the section above, HF models like `spacy.Dolly.v1` now accept `config_init` and
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"above" is confusing here, because the section above is about the REST API. I would just remove this subsection, and start with "HF models like ..."

`config_run` to reflect that differerent arguments can be passed at init or run time.

In `0.3.x`:
```ini
[components.llm.backend]
@llm_backends = "spacy.Dolly_HF.v1"
model = "databricks/dolly-v2-3b"
config = {}
```
In `0.4.x`:
```ini
[components.llm.model]
@llm_models = "spacy.Dolly.v1"
name = "dolly-v2-3b" # or databricks/dolly-v2-3b - the prefix is optional
config_init = {} # Arguments passed to HF model at initalization time
rmitsch marked this conversation as resolved.
Show resolved Hide resolved
config_run = {} # Arguments passed to HF model at inference time
```

### Models using LangChain

LangChain models are now accessible via `langchain.[API].[version]`, e. g. `langchain.OpenAI.v1`. Other than that the
changes from 0.3.x to 0.4.x are identical with REST-based models.

In `0.3.x`:
```ini
[components.llm.backend]
@llm_backends = "spacy.LangChain.v1"
api = "OpenAI"
config = {"temperature": 0.3}
```

In `0.4.x`:
```ini
[components.llm.model]
@llm_models = "langchain.OpenAI.v1"
name = "gpt-3-5-turbo"
config = {"temperature": 0.3}
```

</details>
rmitsch marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ filterwarnings = [
"ignore:^.*pkg_resources.*:DeprecationWarning",
"ignore:.*function is now available as sqlalchemy.orm.declarative_base().*:",
"ignore:^.*You are trying to use a chat model. This way of initializing it is no longer supported. Instead, please use.*:UserWarning",
"ignore:^.*Failed to instantiate LangChain class.*:UserWarning"
]
markers = [
"external: interacts with a (potentially cost-incurring) third-party API"
Expand Down
1 change: 0 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ black==22.3.0
types-requests==2.28.11.16
# Prompting libraries needed for testing
langchain==0.0.191; python_version>="3.9"
minichain>=0.3,<0.4; python_version>="3.8" and python_version<"3.11"

# Necessary for running all local models on GPU.
transformers[sentencepiece]>=4.0.0,<4.30
Expand Down
2 changes: 0 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ spacy_misc =
spacy.FileReader.v1 = spacy_llm.registry:file_reader

[options.extras_require]
minichain =
minichain>=0.3,<0.4
langchain =
langchain==0.0.191
transformers =
Expand Down
2 changes: 1 addition & 1 deletion spacy_llm/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from . import backends # noqa: F401
from . import cache # noqa: F401
from . import models # noqa: F401
from . import registry # noqa: F401
from . import tasks # noqa: F401
from .pipeline import llm
Expand Down
13 changes: 0 additions & 13 deletions spacy_llm/backends/__init__.py

This file was deleted.

17 changes: 0 additions & 17 deletions spacy_llm/backends/integration/__init__.py

This file was deleted.

11 changes: 0 additions & 11 deletions spacy_llm/backends/integration/hf/__init__.py

This file was deleted.

11 changes: 0 additions & 11 deletions spacy_llm/backends/integration/remote/__init__.py

This file was deleted.

29 changes: 0 additions & 29 deletions spacy_llm/backends/integration/remote/base.py

This file was deleted.

74 changes: 0 additions & 74 deletions spacy_llm/backends/integration/remote/langchain.py

This file was deleted.

70 changes: 0 additions & 70 deletions spacy_llm/backends/integration/remote/minichain.py

This file was deleted.

25 changes: 0 additions & 25 deletions spacy_llm/backends/rest/noop.py

This file was deleted.