-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Importing smolagents Takes Excessive Time #100
Comments
Thank you @xianminx for proposing this! Could you propose a PR and report the reduction in import time? |
cool, let me try to hack around for the optimization. |
I took some time and investigated the issue. It seems to be related to PyTorch itself. I ran the test on an old x86 macOS, and importing Since |
Hi @xianminx. import time
t0 = time.time()
from smolagents import CodeAgent, HfApiModel
t1 = time.time()
print(f"Total time: {t1 - t0:.2f}") With this removal of torch, the import time falls from 6.52s to 3.8s! So I'd say this mostly solves the issue. 🥳 Stay tuned for the PR! |
Noting this is closed with the PR merged! |
Bug Report: Importing
smolagents
Takes Excessive TimeDescription
Importing the
smolagents
module takes an unusually long time, which affects usability, especially for non-transformer-related tools. The long import time seems to be caused by the initialization of heavy dependencies liketransformers
andtorch
, even when they are not required for certain tools.Steps to Reproduce
Run the following script to benchmark the import time:
Observed Behavior
Expected Behavior
The
smolagents
module should import significantly faster, especially when non-transformer-related tools (e.g.,DuckDuckGoSearchTool
) are being used. The framework should avoid loading unnecessary dependencies during import or should defer their initialization using lazy loading.Possible Cause
The long import time appears to be due to the initialization of dependencies like:
transformers
torch
These dependencies are loaded even when they are not required for certain tools or agents. As an agent framework,
smolagents
should minimize the overhead of importing the module by:transformers
andtorch
.Environment
smolagents
version: 1.1.0Proposed Solution
transformers
andtorch
.Impact
The high import time reduces the performance and efficiency of the framework, especially in scenarios where only lightweight tools like
DuckDuckGoSearchTool
are required.Additional Context
This issue significantly impacts workflows where
smolagents
is used as a lightweight agent framework for tools that do not require deep learning components.The text was updated successfully, but these errors were encountered: