Skip to content

Commit

Permalink
Update README.md (#16)
Browse files Browse the repository at this point in the history
Signed-off-by: Glenn Jocher <[email protected]>
Co-authored-by: UltralyticsAssistant <[email protected]>
  • Loading branch information
glenn-jocher and UltralyticsAssistant authored Jan 16, 2025
1 parent 299922e commit 89629cc
Showing 1 changed file with 9 additions and 4 deletions.
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

0 comments on commit 89629cc

Please sign in to comment.