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

Importing smolagents takes a large amount of time #424

Open
lukegormsen opened this issue Jan 30, 2025 · 5 comments
Open

Importing smolagents takes a large amount of time #424

lukegormsen opened this issue Jan 30, 2025 · 5 comments
Labels
enhancement New feature or request

Comments

@lukegormsen
Copy link

Is your feature request related to a problem? Please describe.
The was referenced #100 and was addressed by not making certain heavy dependencies required like torch. After this was addressed, the import time was cut in half down to a much more manageable 3.8s #147 . However, the import time has now gone back up significantly seen after running

import time

start = time.time()
from smolagents import CodeAgent
end = time.time()

print(f"Import time: {end - start:.2f} seconds")

which results in ~ Import time: 7.92 seconds.

Describe the solution you'd like
Ideally, I’d love to see smolagents import faster, especially since it was optimized in a previous issue (#100). Maybe there’s an opportunity to revisit that optimization or find another way to delay some of the heavier imports until they’re actually needed.

That said, I totally get that some libraries just take time to load, and maybe this is unavoidable. If that’s the case, I’d appreciate any insight into why it’s happening and if there are any best practices for mitigating it (like lazy loading, import restructuring, etc.).

Is this not possible with the current options.
I’m not sure! It might be that smolagents is doing exactly what it needs to do, and this is just the reality of working with it. But if there’s an easy way to improve things, I’d be curious to hear about it.

Describe alternatives you've considered
I’ve thought about breaking up the import so that I only bring in the specific pieces I need instead of the full package, but since I’m using CodeAgent, I’m not sure if that would help much. Another option could be lazy-loading some dependencies, but I don’t know enough about the internals of smolagents to say if that would work here.

Additional context

@lukegormsen lukegormsen added the enhancement New feature or request label Jan 30, 2025
@touseefahmed96
Copy link
Contributor

@lukegormsen Which version of smolagent are you using? because the import time in Version: 1.6.0 is not 7.92 seconds

Your code :

import time

start = time.time()
from smolagents import CodeAgent
end = time.time()

print(f"Import time: {end - start:.2f} seconds")

Output ;

Import time: 1.54 seconds

pip show smolagents

Name: smolagents
Version: 1.6.0
Summary: 🤗 smolagents: a barebones library for agents. Agents write python code to call tools or orchestrate other agents.
Home-page: 
Author: Thomas Wolf
Author-email: Aymeric Roucher <[email protected]>
License: 
Location: C:\Convo\smolagents\test-env\Lib\site-packages
Requires: duckduckgo-search, huggingface-hub, jinja2, markdownify, pandas, pillow, requests, rich
Required-by:

@albertvillanova
Copy link
Member

albertvillanova commented Jan 30, 2025

As @touseefahmed96 mentioned, it is important to know which smolagents version you are using, @lukegormsen.

Concretely, for import time, we had a regression, but this is fixed since v1.5.0.

@touseefahmed96
Copy link
Contributor

As @touseefahmed96 mentioned, it is important to know which smolagents version you are using, @lukegormsen.

Concretely, for import time, we had a regression, but this is fixed since v1.5.0.

Yup because i checked no issue in 1.5.0 1.6.0 1.7.0(dev) import time is less than 1.8 sec

@lukegormsen
Copy link
Author

lukegormsen commented Jan 30, 2025

@touseefahmed96 I'm using 1.6.0 as well

(testingsmol) ➜  testingsmol pip show smolagents
Name: smolagents
Version: 1.6.0
Summary: 🤗 smolagents: a barebones library for agents. Agents write python code to call tools or orchestrate other agents.
Home-page: 
Author: Thomas Wolf
Author-email: Aymeric Roucher <[email protected]>
License: 
Location: /Users/lukegormsen/.local/share/virtualenvs/testingsmol-Rrb78KG9/lib/python3.13/site-packages
Requires: duckduckgo-search, huggingface-hub, jinja2, markdownify, pandas, pillow, requests, rich
Required-by: 

For more context of this test I'm installing smolagents by itself in a fresh pipenv with python 3.13 and am still getting ~8 seconds. This seems to be reflected in my lambda init time I'm deploying smolagents in but I could be doing something else wrong?

Running python -X importtime -c "import smolagents" is giving the same result

@aymeric-roucher
Copy link
Collaborator

Also @lukegormsen which version have you installed, is it a particular bundle of requirements like smolagents[dev] ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants