mirror of
https://github.com/hwchase17/langchain.git
synced 2025-08-09 04:50:37 +00:00
huggingface[major]: Reduce disk footprint by 95% by making large dependencies optional (#31268)
**Description:** `langchain_huggingface` has a very large installation size of around 600 MB (on a Mac with Python 3.11). This is due to its dependency on `sentence-transformers`, which in turn depends on `torch`, which is 320 MB all by itself. Similarly, the depedency on `transformers` adds another set of heavy dependencies. With those dependencies removed, the installation of `langchain_huggingface` only takes up ~26 MB. This is only 5 % of the full installation! These libraries are not necessary to use `langchain_huggingface`'s API wrapper classes, only for local inferences/embeddings. All import statements for those two libraries already have import guards in place (try/catch with a helpful "please install x" message). This PR therefore moves those two libraries to an optional dependency group `full`. So a `pip install langchain_huggingface` will only install the lightweight version, and a `pip install "langchain_huggingface[full]"` will install all dependencies. I know this may break existing code, because `sentence-transformers` and `transformers` are now no longer installed by default. Given that users will see helpful error messages when that happens, and the major impact of this small change, I hope that you will still consider this PR. **Dependencies:** No new dependencies, but new optional grouping.
This commit is contained in:
parent
ae3551c96b
commit
815bfa5408
@ -9,8 +9,6 @@ requires-python = ">=3.9"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"langchain-core<1.0.0,>=0.3.59",
|
"langchain-core<1.0.0,>=0.3.59",
|
||||||
"tokenizers>=0.19.1",
|
"tokenizers>=0.19.1",
|
||||||
"transformers>=4.39.0",
|
|
||||||
"sentence-transformers>=2.6.0",
|
|
||||||
"huggingface-hub>=0.30.2",
|
"huggingface-hub>=0.30.2",
|
||||||
]
|
]
|
||||||
name = "langchain-huggingface"
|
name = "langchain-huggingface"
|
||||||
@ -23,6 +21,12 @@ readme = "README.md"
|
|||||||
"Release Notes" = "https://github.com/langchain-ai/langchain/releases?q=tag%3A%22langchain-huggingface%3D%3D0%22&expanded=true"
|
"Release Notes" = "https://github.com/langchain-ai/langchain/releases?q=tag%3A%22langchain-huggingface%3D%3D0%22&expanded=true"
|
||||||
repository = "https://github.com/langchain-ai/langchain"
|
repository = "https://github.com/langchain-ai/langchain"
|
||||||
|
|
||||||
|
[project.optional-dependencies]
|
||||||
|
full = [
|
||||||
|
"transformers>=4.39.0",
|
||||||
|
"sentence-transformers>=2.6.0",
|
||||||
|
]
|
||||||
|
|
||||||
[dependency-groups]
|
[dependency-groups]
|
||||||
test = [
|
test = [
|
||||||
"pytest<8.0.0,>=7.3.0",
|
"pytest<8.0.0,>=7.3.0",
|
||||||
@ -53,7 +57,7 @@ target-version = "py39"
|
|||||||
|
|
||||||
[tool.ruff.lint]
|
[tool.ruff.lint]
|
||||||
select = ["E", "F", "I", "T201", "UP"]
|
select = ["E", "F", "I", "T201", "UP"]
|
||||||
ignore = [ "UP007", ]
|
ignore = ["UP007"]
|
||||||
|
|
||||||
[tool.coverage.run]
|
[tool.coverage.run]
|
||||||
omit = ["tests/*"]
|
omit = ["tests/*"]
|
||||||
|
Loading…
Reference in New Issue
Block a user