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

Update README.md #16

Merged
merged 6 commits into from
Jan 16, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,19 @@ pip install ultralytics-autoimport
Use the `lazy` context manager to defer imports:

```python
import time

from autoimport import lazy

with lazy():
import torch # torch is only imported when used
t0 = time.perf_counter()
import torch # Import is deferred until first use

print(f"Initial import time: {time.perf_counter() - t0:.3f}s") # Example output: 0.000s

print("Torch imported:", "torch" in globals())
torch.cuda.is_available() # Now torch is imported
print("Torch imported:", "torch" in globals())
t1 = time.perf_counter()
torch.cuda.is_available() # Package is actually loaded here
print(f"First use time: {time.perf_counter() - t1:.3f}s") # Example output: 0.462s
```

## πŸ—‚ Repository Structure
Expand Down
Loading