Skip to content

fix(core): lazy loading transformers, numpy, simsimd#26

Open
LennyMalcolm0 wants to merge 2 commits into
masterfrom
devasign-clone/pr-35466
Open

fix(core): lazy loading transformers, numpy, simsimd#26
LennyMalcolm0 wants to merge 2 commits into
masterfrom
devasign-clone/pr-35466

Conversation

@LennyMalcolm0

Copy link
Copy Markdown
Owner

fix(core): lazy loading transformers, numpy, simsimd

Summary

Optimized the initial import speed of langchain_core by converting top-level imports of transformers, numpy, and simsimd into lazy, local imports.

Details

Confirmed with python -X importtime that these dependencies are no longer loaded on initial import, and verified functionality through make format/lint and est.

Disclaimer

I used the Gemini CLI to help with the specific implementation details and to ensure compliance with linting and type checking and drafting this PR description.

before
without transformers / torch env.

$ time uv run python -c "from langchain_core.prompts import BasePromptTemplate"
real    0m0.600s
user    0m0.509s
sys     0m0.074s

with transformers / torch installed env.

$ uv pip install transformers
...
$ uv pip install numpy
...

$ time uv run python -c "from langchain_core.prompts import BasePromptTemplate"
real    0m9.664s
user    0m4.268s
sys     0m0.752s

$ time uv run python -c "from langchain_core.prompts import BasePromptTemplate" # one more time

real    0m4.030s
user    0m3.877s
sys     0m0.468s

after PR applied

$ time uv run python -c "from langchain_core.prompts import BasePromptTemplate"
real    0m0.797s
user    0m0.662s
sys     0m0.110s

$ uv pip show transformers
Name: transformers
Version: 4.55.0
Location: /home/future/repo/linkBrain-server/.venv/lib/python3.13/site-packages
Requires: filelock, huggingface-hub, numpy, packaging, pyyaml, regex, requests, safetensors, tokenizers, tqdm
Required-by: docling-ibm-models, optimum, sentence-transformers

See also langchain-ai#35469


Cloned from langchain-ai#35466 for DevAsign stress testing.

wkpark added 2 commits May 22, 2026 19:03
fix transformer lint
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants