speedy-utils 1.1.27__py3-none-any.whl → 1.1.29__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. llm_utils/__init__.py +16 -4
  2. llm_utils/chat_format/__init__.py +10 -10
  3. llm_utils/chat_format/display.py +33 -21
  4. llm_utils/chat_format/transform.py +17 -19
  5. llm_utils/chat_format/utils.py +6 -4
  6. llm_utils/group_messages.py +17 -14
  7. llm_utils/lm/__init__.py +6 -5
  8. llm_utils/lm/async_lm/__init__.py +1 -0
  9. llm_utils/lm/async_lm/_utils.py +10 -9
  10. llm_utils/lm/async_lm/async_llm_task.py +141 -137
  11. llm_utils/lm/async_lm/async_lm.py +48 -42
  12. llm_utils/lm/async_lm/async_lm_base.py +59 -60
  13. llm_utils/lm/async_lm/lm_specific.py +4 -3
  14. llm_utils/lm/base_prompt_builder.py +93 -70
  15. llm_utils/lm/llm.py +126 -108
  16. llm_utils/lm/llm_signature.py +4 -2
  17. llm_utils/lm/lm_base.py +72 -73
  18. llm_utils/lm/mixins.py +102 -62
  19. llm_utils/lm/openai_memoize.py +124 -87
  20. llm_utils/lm/signature.py +105 -92
  21. llm_utils/lm/utils.py +42 -23
  22. llm_utils/scripts/vllm_load_balancer.py +23 -30
  23. llm_utils/scripts/vllm_serve.py +8 -7
  24. llm_utils/vector_cache/__init__.py +9 -3
  25. llm_utils/vector_cache/cli.py +1 -1
  26. llm_utils/vector_cache/core.py +59 -63
  27. llm_utils/vector_cache/types.py +7 -5
  28. llm_utils/vector_cache/utils.py +12 -8
  29. speedy_utils/__imports.py +244 -0
  30. speedy_utils/__init__.py +90 -194
  31. speedy_utils/all.py +125 -227
  32. speedy_utils/common/clock.py +37 -42
  33. speedy_utils/common/function_decorator.py +6 -12
  34. speedy_utils/common/logger.py +43 -52
  35. speedy_utils/common/notebook_utils.py +13 -21
  36. speedy_utils/common/patcher.py +21 -17
  37. speedy_utils/common/report_manager.py +42 -44
  38. speedy_utils/common/utils_cache.py +152 -169
  39. speedy_utils/common/utils_io.py +137 -103
  40. speedy_utils/common/utils_misc.py +15 -21
  41. speedy_utils/common/utils_print.py +22 -28
  42. speedy_utils/multi_worker/process.py +66 -79
  43. speedy_utils/multi_worker/thread.py +78 -155
  44. speedy_utils/scripts/mpython.py +38 -36
  45. speedy_utils/scripts/openapi_client_codegen.py +10 -10
  46. {speedy_utils-1.1.27.dist-info → speedy_utils-1.1.29.dist-info}/METADATA +1 -1
  47. speedy_utils-1.1.29.dist-info/RECORD +57 -0
  48. vision_utils/README.md +202 -0
  49. vision_utils/__init__.py +4 -0
  50. vision_utils/io_utils.py +735 -0
  51. vision_utils/plot.py +345 -0
  52. speedy_utils-1.1.27.dist-info/RECORD +0 -52
  53. {speedy_utils-1.1.27.dist-info → speedy_utils-1.1.29.dist-info}/WHEEL +0 -0
  54. {speedy_utils-1.1.27.dist-info → speedy_utils-1.1.29.dist-info}/entry_points.txt +0 -0
@@ -0,0 +1,57 @@
1
+ llm_utils/__init__.py,sha256=tSo9RfmOhH1ofZseRtwr4iOpIQ1zKRocAzmuy53RgiI,1634
2
+ llm_utils/group_messages.py,sha256=_XuFkEkO_iQDjVVx80XNFpufGH6iIDwHPDoCRJa60Ak,3691
3
+ llm_utils/chat_format/__init__.py,sha256=a7BKtBVktgLMq2Do4iNu3YfdDdTG1v9M_BkmaEorp5c,775
4
+ llm_utils/chat_format/display.py,sha256=Lffjzna9_vV3QgfiXZM2_tuVb3wqA-WxwrmoAjsJigw,17356
5
+ llm_utils/chat_format/transform.py,sha256=PJ2g9KT1GSbWuAs7giEbTpTAffpU9QsIXyRlbfpTZUQ,5351
6
+ llm_utils/chat_format/utils.py,sha256=M2EctZ6NeHXqFYufh26Y3CpSphN0bdZm5xoNaEJj5vg,1251
7
+ llm_utils/lm/__init__.py,sha256=lFE2DZRpj6eRMo11kx7oRLyYOP2FuDmz08mAcq-cYew,730
8
+ llm_utils/lm/base_prompt_builder.py,sha256=_TzYMsWr-SsbA_JNXptUVN56lV5RfgWWTrFi-E8LMy4,12337
9
+ llm_utils/lm/llm.py,sha256=Ryne4why4VgRCvTJW1SLJciv2pcYYROGP0AwkLVdGPg,16299
10
+ llm_utils/lm/llm_signature.py,sha256=vV8uZgLLd6ZKqWbq0OPywWvXAfl7hrJQnbtBF-VnZRU,1244
11
+ llm_utils/lm/lm_base.py,sha256=Bk3q34KrcCK_bC4Ryxbc3KqkiPL39zuVZaBQ1i6wJqs,9437
12
+ llm_utils/lm/mixins.py,sha256=on83g-JO2SpZ0digOpU8mooqFBX6w7Bc-DeGzVoVCX8,14536
13
+ llm_utils/lm/openai_memoize.py,sha256=rYrSFPpgO7adsjK1lVdkJlhqqIw_13TCW7zU8eNwm3o,5185
14
+ llm_utils/lm/signature.py,sha256=K1hvCAqoC5CmsQ0Y_ywnYy2fRb5JzmIK8OS-hjH-5To,9971
15
+ llm_utils/lm/utils.py,sha256=t-RSR-ffOs2HT67JfgqRhbZX9wbxlJNtQMro4ZyuVVM,12461
16
+ llm_utils/lm/async_lm/__init__.py,sha256=j0xK49ooZ0Dm5GstGGHbmPMrPjd3mOXoJ1H7eAL_Z4g,122
17
+ llm_utils/lm/async_lm/_utils.py,sha256=mB-AueWJJatTx0PXqd_oWc6Kz36cfgDmDTKgiXafCJI,6106
18
+ llm_utils/lm/async_lm/async_llm_task.py,sha256=2PWW4vPW2jYUiGmYFo4-DHrmX5Jm8Iw_1qo6EPL-ytE,18611
19
+ llm_utils/lm/async_lm/async_lm.py,sha256=W8n_S5PKJln9bzO9T525-tqo5DFwBZNXDucz_v-35iU,13761
20
+ llm_utils/lm/async_lm/async_lm_base.py,sha256=ga5nCzows5Ye3yop41zsUxNYxcj_Vpf02DsfJ1eoE9U,8358
21
+ llm_utils/lm/async_lm/lm_specific.py,sha256=PxP54ltrh9NrLJx7BPib52oYo_aCvDOjf7KzMjp1MYg,3929
22
+ llm_utils/scripts/README.md,sha256=yuOLnLa2od2jp4wVy3rV0rESeiV3o8zol5MNMsZx0DY,999
23
+ llm_utils/scripts/vllm_load_balancer.py,sha256=eQlH07573EDWIBkwc9ef1WvI59anLr4hQqLfZvQk7xk,37133
24
+ llm_utils/scripts/vllm_serve.py,sha256=tPcRB_MbJ01LcqC83RHQ7W9XDS7b1Ntc0fCRdegsNXU,14761
25
+ llm_utils/vector_cache/__init__.py,sha256=oZXpjgBuutI-Pd_pBNYAQMY7-K2C6xv8Qt6a3p88GBQ,879
26
+ llm_utils/vector_cache/cli.py,sha256=MAvnmlZ7j7_0CvIcSyK4TvJlSRFWYkm4wE7zSq3KR8k,6246
27
+ llm_utils/vector_cache/core.py,sha256=VXuYJy1AX22NHKvIXRriETip5RrmQcNp73-g-ZT774o,30950
28
+ llm_utils/vector_cache/types.py,sha256=CpMZanJSTeBVxQSqjBq6pBVWp7u2-JRcgY9t5jhykdQ,438
29
+ llm_utils/vector_cache/utils.py,sha256=OsiRFydv8i8HiJtPL9hh40aUv8I5pYfg2zvmtDi4DME,1446
30
+ speedy_utils/__imports.py,sha256=KQogps2TTzigJK8YkW875qaIEwf8PypmTtzyc7svvfw,5691
31
+ speedy_utils/__init__.py,sha256=dxEwqFTQIXIsWlKEXm6b5pcEx2c8W8R5iblbHN2chdc,2656
32
+ speedy_utils/all.py,sha256=5gN_mIvx9mtEWMXl64S0NvY3Wrj1bb5QyrMh-U03uiE,2508
33
+ speedy_utils/common/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
34
+ speedy_utils/common/clock.py,sha256=raLtMGIgzrRej5kUt7hOUm2ZZw2THVPo-q8dMvdZOxw,7354
35
+ speedy_utils/common/function_decorator.py,sha256=GKXqRs_hHFFmhyhql0Br0o52WzekUnpNlm99NfaVwgY,2025
36
+ speedy_utils/common/logger.py,sha256=pBZwLDduoVzXd1o-hR43Pkdt7farnjS-yZOFefAw5eA,6275
37
+ speedy_utils/common/notebook_utils.py,sha256=6mxXZcTHwYob3nobAzbSZnDyXRahFaaSko1_SYlvZy4,1905
38
+ speedy_utils/common/patcher.py,sha256=Rku-N4DJNue8BCLUx7y3ad_3t_WU2HleHKlbR0vhaRc,2319
39
+ speedy_utils/common/report_manager.py,sha256=78KQ0gUzvbzT6EjHYZ5zgtV41cPRvdX8hnF2oSWA4qA,3849
40
+ speedy_utils/common/utils_cache.py,sha256=1UAqOSb4nFVlhuQRfTEXCN-8Wf6yntXyMA6yp61-98I,26277
41
+ speedy_utils/common/utils_io.py,sha256=w9AxMD_8V3Wyo_0o9OtXjVQS8Z3KhxQiOkrl2p8Np70,15762
42
+ speedy_utils/common/utils_misc.py,sha256=ZRJCS7OJxybpVm1sasoeCYRW2TaaGCXj4DySYlQeVR8,2227
43
+ speedy_utils/common/utils_print.py,sha256=AGDB7mgJnO00QkJBH6kJb46738q3GzMUZPwtQ248vQw,4763
44
+ speedy_utils/multi_worker/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
45
+ speedy_utils/multi_worker/process.py,sha256=O3BpGH7iL_2vh_ezwyHb28lvkVADABpTUnhKHbiEe8I,10542
46
+ speedy_utils/multi_worker/thread.py,sha256=k4Ff4R2W0Ehet1zJ5nHQOfcsvOjnJzU6A2I18qw7_6M,21320
47
+ speedy_utils/scripts/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
48
+ speedy_utils/scripts/mpython.py,sha256=aZvusJLKa3APVhabbFUAEo873VBm8Fym7HKGmVW4LyE,3843
49
+ speedy_utils/scripts/openapi_client_codegen.py,sha256=GModmmhkvGnxljK4KczyixKDrk-VEcLaW5I0XT6tzWo,9657
50
+ vision_utils/README.md,sha256=AIDZZj8jo_QNrEjFyHwd00iOO431s-js-M2dLtVTn3I,5740
51
+ vision_utils/__init__.py,sha256=XsLxy1Fn33Zxu6hTFl3NEWfxGjuQQ-0Wmoh6lU9NZ_o,257
52
+ vision_utils/io_utils.py,sha256=1FkG6k7uwZALh3-JkWXEHoGQJhjTqG1jC20SxObPRS0,25921
53
+ vision_utils/plot.py,sha256=3NW2atYPdcs6-Qq8N179Pwji-p5ZUN6ddC0zE2WZb_8,11984
54
+ speedy_utils-1.1.29.dist-info/METADATA,sha256=FcgtzlK1CJlS3sWFYi3Apkx4qqTcTRoLOaHz6YW8Wuc,8028
55
+ speedy_utils-1.1.29.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
56
+ speedy_utils-1.1.29.dist-info/entry_points.txt,sha256=1rrFMfqvaMUE9hvwGiD6vnVh98kmgy0TARBj-v0Lfhs,244
57
+ speedy_utils-1.1.29.dist-info/RECORD,,
vision_utils/README.md ADDED
@@ -0,0 +1,202 @@
1
+ # Vision Utils
2
+
3
+ Utility functions for computer vision tasks, particularly for visualizing images in Jupyter notebooks.
4
+
5
+ ## Features
6
+
7
+ ### `plot_images_notebook(images, ...)`
8
+
9
+ Plot a batch of images in a notebook with automatic format detection, smart grid layout, and size optimization to prevent notebook breaking.
10
+
11
+ **Supported Input Formats:**
12
+ - **Numpy arrays:**
13
+ - Batch: `(B, H, W, C)` or `(B, C, H, W)`
14
+ - Single: `(H, W, C)`, `(C, H, W)`, or `(H, W)` for grayscale
15
+ - **PyTorch tensors:**
16
+ - Batch: `(B, H, W, C)` or `(B, C, H, W)`
17
+ - Single: `(H, W, C)`, `(C, H, W)`, or `(H, W)` for grayscale
18
+ - **List of images:**
19
+ - Mixed formats (numpy arrays and/or torch tensors)
20
+
21
+ **Parameters:**
22
+ - `images`: Images to plot (see supported formats above)
23
+ - `nrows`: Number of rows in grid (default: None, auto-calculated using sqrt)
24
+ - `ncols`: Number of columns in grid (default: None, auto-calculated using sqrt)
25
+ - `figsize`: Figure size `(width, height)` in inches (default: auto-calculated based on grid size and image count)
26
+ - `titles`: Optional list of titles for each image
27
+ - `cmap`: Colormap for grayscale images (default: 'gray')
28
+ - `dpi`: Dots per inch for the figure (default: 72)
29
+ - `max_figure_width`: Maximum figure width in inches (default: 15.0)
30
+ - `max_figure_height`: Maximum figure height in inches (default: 20.0)
31
+
32
+ **Smart Features:**
33
+ - **Auto Grid Layout**: When both `nrows` and `ncols` are None, uses sqrt to create roughly square grid
34
+ - **Adaptive Cell Sizing**: Automatically reduces cell size for larger image counts to prevent notebook breaking
35
+ - **Size Constraints**: Respects max width/height limits to ensure plots render properly in notebooks
36
+ - **Aspect Ratio Aware**: Calculates figure size based on actual image aspect ratios
37
+
38
+ ## Installation
39
+
40
+ The vision_utils module is part of speedy_utils. Install with:
41
+
42
+ ```bash
43
+ pip install -e .
44
+ ```
45
+
46
+ For PyTorch support:
47
+ ```bash
48
+ pip install torch
49
+ ```
50
+
51
+ For plotting (required):
52
+ ```bash
53
+ pip install matplotlib
54
+ ```
55
+
56
+ ## Usage Examples
57
+
58
+ ### Auto Grid Layout (Recommended)
59
+
60
+ ```python
61
+ import numpy as np
62
+ from vision_utils import plot_images_notebook
63
+
64
+ # Auto grid - creates 3x3 grid for 9 images
65
+ images = np.random.rand(9, 64, 64, 3)
66
+ plot_images_notebook(images)
67
+
68
+ # Auto grid - creates 3x3 grid for 8 images (1 empty cell)
69
+ images = np.random.rand(8, 64, 64, 3)
70
+ plot_images_notebook(images)
71
+ ```
72
+
73
+ ### Manual Grid Layout
74
+
75
+ ```python
76
+ import numpy as np
77
+ from vision_utils import plot_images_notebook
78
+
79
+ # Specify exact grid dimensions
80
+ images = np.random.rand(8, 64, 64, 3)
81
+ plot_images_notebook(images, nrows=2, ncols=4)
82
+ ```
83
+
84
+ ### Basic Usage
85
+
86
+ ```python
87
+ import numpy as np
88
+ from vision_utils import plot_images_notebook
89
+
90
+ # Batch of images - auto grid layout
91
+ images = np.random.rand(8, 64, 64, 3)
92
+ plot_images_notebook(images)
93
+ ```
94
+
95
+ ### Many Images (Adaptive Sizing)
96
+ ```
97
+
98
+ ### Many Images (Adaptive Sizing)
99
+
100
+ ```python
101
+ import numpy as np
102
+ from vision_utils import plot_images_notebook
103
+
104
+ # Automatically uses smaller cells for many images
105
+ images = np.random.rand(25, 64, 64, 3)
106
+ plot_images_notebook(images) # Creates 5x5 grid with optimized cell size
107
+ ```
108
+
109
+ ### PyTorch Tensors
110
+
111
+ ```python
112
+ import torch
113
+ from vision_utils import plot_images_notebook
114
+
115
+ # PyTorch tensor in (B, C, H, W) format
116
+ images = torch.rand(8, 3, 64, 64)
117
+ plot_images_notebook(images)
118
+ ```
119
+
120
+ ### Mixed Formats
121
+
122
+ ```python
123
+ import numpy as np
124
+ from vision_utils import plot_images_notebook
125
+
126
+ # List of images with different formats
127
+ images = [
128
+ np.random.rand(64, 64, 3), # (H, W, C)
129
+ np.random.rand(3, 64, 64), # (C, H, W)
130
+ np.random.rand(64, 64), # Grayscale
131
+ ]
132
+
133
+ plot_images_notebook(images, titles=titles)
134
+ ```
135
+
136
+ ### Single Image
137
+
138
+ ```python
139
+ import numpy as np
140
+ from vision_utils import plot_images_notebook
141
+
142
+ # Single image
143
+ image = np.random.rand(128, 128, 3)
144
+ plot_images_notebook(image)
145
+ ```
146
+
147
+ ### Custom Figure Size and Colormap
148
+
149
+ ```python
150
+ import numpy as np
151
+ from vision_utils import plot_images_notebook
152
+
153
+ # Grayscale images with custom settings
154
+ images = np.random.rand(4, 64, 64)
155
+ plot_images_notebook(
156
+ images,
157
+ nrows=2,
158
+ ncols=2,
159
+ figsize=(8, 8),
160
+ cmap='viridis',
161
+ dpi=100
162
+ )
163
+ ```
164
+
165
+ ## Smart Grid Layout
166
+
167
+ When `nrows` and `ncols` are both `None` (default), the function automatically calculates the optimal grid layout:
168
+
169
+ 1. Uses `sqrt(n_images)` to determine a roughly square grid
170
+ 2. For 9 images → 3x3 grid
171
+ 3. For 8 images → 3x3 grid (with 1 empty cell)
172
+ 4. For 16 images → 4x4 grid
173
+ 5. For 25 images → 5x5 grid
174
+
175
+ This ensures balanced layouts without manual calculation.
176
+
177
+ ## Adaptive Cell Sizing
178
+
179
+ The function automatically adjusts cell sizes based on the number of images to prevent notebook breaking:
180
+
181
+ - **1-4 images**: 4.0 inches per cell
182
+ - **5-9 images**: 3.0 inches per cell
183
+ - **10-16 images**: 2.5 inches per cell
184
+ - **17+ images**: 2.0 inches per cell
185
+
186
+ Additionally, it respects `max_figure_width` (default: 15") and `max_figure_height` (default: 20") constraints to ensure plots render properly in notebooks.
187
+
188
+ ## Format Detection
189
+
190
+ The function automatically detects and converts between different image formats:
191
+
192
+ 1. **Channel Detection:** Identifies if channels are in the first (`C, H, W`) or last (`H, W, C`) dimension
193
+ 2. **Batch Detection:** Handles both batched and single images
194
+ 3. **Type Conversion:** Automatically converts PyTorch tensors to numpy arrays
195
+ 4. **Value Normalization:** Handles both `[0, 1]` and `[0, 255]` value ranges
196
+
197
+ ## Notes
198
+
199
+ - The function assumes that if the first dimension is 1 or 3 and is smaller than the other dimensions, it represents channels (`C, H, W` format)
200
+ - Images with values in `[0, 1]` are displayed directly
201
+ - Images with values > 1 are assumed to be in `[0, 255]` range and normalized to `[0, 1]`
202
+ - Grayscale images can be 2D `(H, W)` or 3D `(H, W, 1)`
@@ -0,0 +1,4 @@
1
+ from .io_utils import read_images, read_images_cpu, read_images_gpu, ImageMmap, ImageMmapDynamic
2
+ from .plot import plot_images_notebook
3
+
4
+ __all__ = ['plot_images_notebook', 'read_images_cpu', 'read_images_gpu', 'read_images', 'ImageMmap', 'ImageMmapDynamic']