Skip to content

Commit fb39338

Browse files
authored
Merge pull request #204 from explosion/develop
Sync `main` with `develop`
2 parents 64f4ce2 + 1d0b262 commit fb39338

124 files changed

Lines changed: 4085 additions & 1422 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

β€ŽREADME.mdβ€Ž

Lines changed: 660 additions & 166 deletions
Large diffs are not rendered by default.

β€Žmigration_guide.mdβ€Ž

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Migration guides
2+
3+
<details open>
4+
<summary>0.3.x to 0.4.x</summary>
5+
6+
## `0.3.x` to `0.4.x`
7+
8+
`0.4.x` significantly refactors the code to make it more robust and the config more intuitive. 0.4.0 changes the config
9+
paradigm from `backend`- to `model`-centric. This is reflected in the external API in a different config structure.
10+
11+
Remember that there are three different types of models: the first uses the native REST implementation to communicate
12+
with hosted LLMs, the second builds on HuggingFace's `transformers` model to run models locally and the third leverages
13+
`langchain` to operate on hosted or local models. While the config for all three is rather similar (especially in
14+
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
15+
to 0.4.x for each of these model types.
16+
17+
### All model types
18+
- The registry name has changed - instead of `@llm_backends`, use `@llm_models`.
19+
- The `api` attribute has been removed.
20+
21+
### Models using REST
22+
23+
This is the default method to communicate with hosted models. Whenever you don't explicitly use LangChain models
24+
(see section at the bottom) or run models locally, you are using this kind of model.
25+
26+
In `0.3.x`:
27+
```ini
28+
[components.llm.backend]
29+
@llm_backends = "spacy.REST.v1"
30+
api = "OpenAI"
31+
config = {"model": "gpt-3.5-turbo", "temperature": 0.3}
32+
```
33+
In `0.4.x`:
34+
```ini
35+
[components.llm.model]
36+
@llm_models = "spacy.GPT-3-5.v1"
37+
name = "gpt-3-5-turbo"
38+
config = {"temperature": 0.3}
39+
```
40+
Note that the factory function (marked with `@`) refers to the name of the model. Variants of the same model can be
41+
specified with the `name` attribute - for `gpt-3.5` this could be `"gpt-3-5-turbo"` or `"gpt-3-5-turbo-16k"`.
42+
43+
### Models using HuggingFace
44+
45+
On top of the changes described in the section above, HF models like `spacy.Dolly.v1` now accept `config_init` and
46+
`config_run` to reflect that differerent arguments can be passed at init or run time.
47+
48+
In `0.3.x`:
49+
```ini
50+
[components.llm.backend]
51+
@llm_backends = "spacy.Dolly_HF.v1"
52+
model = "databricks/dolly-v2-3b"
53+
config = {}
54+
```
55+
In `0.4.x`:
56+
```ini
57+
[components.llm.model]
58+
@llm_models = "spacy.Dolly.v1"
59+
name = "dolly-v2-3b" # or databricks/dolly-v2-3b - the prefix is optional
60+
config_init = {} # Arguments passed to HF model at initialization time
61+
config_run = {} # Arguments passed to HF model at inference time
62+
```
63+
64+
### Models using LangChain
65+
66+
LangChain models are now accessible via `langchain.[API].[version]`, e. g. `langchain.OpenAI.v1`. Other than that the
67+
changes from 0.3.x to 0.4.x are identical with REST-based models.
68+
69+
In `0.3.x`:
70+
```ini
71+
[components.llm.backend]
72+
@llm_backends = "spacy.LangChain.v1"
73+
api = "OpenAI"
74+
config = {"temperature": 0.3}
75+
```
76+
77+
In `0.4.x`:
78+
```ini
79+
[components.llm.model]
80+
@llm_models = "langchain.OpenAI.v1"
81+
name = "gpt-3-5-turbo"
82+
config = {"temperature": 0.3}
83+
```
84+
85+
</details>

β€Žpyproject.tomlβ€Ž

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ filterwarnings = [
1818
"ignore:^.*pkg_resources.*:DeprecationWarning",
1919
"ignore:.*function is now available as sqlalchemy.orm.declarative_base().*:",
2020
"ignore:^.*You are trying to use a chat model. This way of initializing it is no longer supported. Instead, please use.*:UserWarning",
21+
"ignore:^.*Xformers is not installed correctly.*:",
22+
"ignore:^.*The 'warn' method is deprecated, use 'warning' instead.*:DeprecationWarning"
2123
]
2224
markers = [
2325
"external: interacts with a (potentially cost-incurring) third-party API"

β€Žrequirements-dev.txtβ€Ž

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ mypy>=0.990,<1.1.0; platform_machine != "aarch64" and python_version >= "3.7"
77
black==22.3.0
88
types-requests==2.28.11.16
99
# Prompting libraries needed for testing
10-
langchain==0.0.191; python_version>="3.9"
11-
minichain>=0.3,<0.4; python_version>="3.8" and python_version<"3.11"
10+
langchain==0.0.219; python_version>="3.9"
11+
openai>=0.27; python_version>="3.9"
1212

1313
# Necessary for running all local models on GPU.
1414
transformers[sentencepiece]>=4.0.0,<4.30
1515
torch
16+
einops>=0.4
1617

1718
# Necessary for pytest checks and ignores.
1819
sqlalchemy; python_version<"3.9"

β€Žsetup.cfgβ€Ž

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[metadata]
2-
version = 0.3.2
2+
version = 0.4.0
33
description = Integrating LLMs into structured NLP pipelines
44
author = Explosion
55
author_email = contact@explosion.ai
@@ -43,13 +43,13 @@ spacy_misc =
4343
spacy.FileReader.v1 = spacy_llm.registry:file_reader
4444

4545
[options.extras_require]
46-
minichain =
47-
minichain>=0.3,<0.4
4846
langchain =
4947
langchain==0.0.191
5048
transformers =
5149
torch>=1.13.1,<2.0
5250
transformers>=4.28.1,<5.0
51+
einops>=0.4
52+
xformers
5353

5454
[bdist_wheel]
5555
universal = true

β€Žspacy_llm/__init__.pyβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from . import backends # noqa: F401
21
from . import cache # noqa: F401
2+
from . import models # noqa: F401
33
from . import registry # noqa: F401
44
from . import tasks # noqa: F401
55
from .pipeline import llm

β€Žspacy_llm/backends/__init__.pyβ€Ž

Lines changed: 0 additions & 13 deletions
This file was deleted.

β€Žspacy_llm/backends/integration/__init__.pyβ€Ž

Lines changed: 0 additions & 17 deletions
This file was deleted.

β€Žspacy_llm/backends/integration/hf/__init__.pyβ€Ž

Lines changed: 0 additions & 11 deletions
This file was deleted.

β€Žspacy_llm/backends/integration/remote/__init__.pyβ€Ž

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
Β (0)