lm-deluge 0.0.40__py3-none-any.whl → 0.0.41__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.
Potentially problematic release.
This version of lm-deluge might be problematic. Click here for more details.
- lm_deluge/batches.py +96 -10
- lm_deluge/client.py +12 -11
- lm_deluge/tracker.py +1 -1
- {lm_deluge-0.0.40.dist-info → lm_deluge-0.0.41.dist-info}/METADATA +1 -1
- {lm_deluge-0.0.40.dist-info → lm_deluge-0.0.41.dist-info}/RECORD +8 -8
- {lm_deluge-0.0.40.dist-info → lm_deluge-0.0.41.dist-info}/WHEEL +0 -0
- {lm_deluge-0.0.40.dist-info → lm_deluge-0.0.41.dist-info}/licenses/LICENSE +0 -0
- {lm_deluge-0.0.40.dist-info → lm_deluge-0.0.41.dist-info}/top_level.txt +0 -0
lm_deluge/batches.py
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
1
|
-
import
|
|
1
|
+
import asyncio
|
|
2
2
|
import json
|
|
3
|
+
import os
|
|
4
|
+
import tempfile
|
|
3
5
|
import time
|
|
4
|
-
import
|
|
6
|
+
from typing import Literal, Sequence
|
|
7
|
+
|
|
5
8
|
import aiohttp
|
|
6
|
-
import tempfile
|
|
7
|
-
from lm_deluge.prompt import CachePattern, Conversation, prompts_to_conversations
|
|
8
|
-
from lm_deluge.config import SamplingParams
|
|
9
|
-
from lm_deluge.models import APIModel
|
|
10
|
-
from typing import Sequence, Literal
|
|
11
|
-
from lm_deluge.api_requests.openai import _build_oa_chat_request
|
|
12
|
-
from lm_deluge.api_requests.anthropic import _build_anthropic_request
|
|
13
9
|
from rich.console import Console
|
|
14
10
|
from rich.live import Live
|
|
15
11
|
from rich.spinner import Spinner
|
|
16
12
|
from rich.table import Table
|
|
17
13
|
from rich.text import Text
|
|
18
|
-
|
|
14
|
+
|
|
15
|
+
from lm_deluge.api_requests.anthropic import _build_anthropic_request
|
|
16
|
+
from lm_deluge.api_requests.openai import _build_oa_chat_request
|
|
17
|
+
from lm_deluge.config import SamplingParams
|
|
18
|
+
from lm_deluge.models import APIModel, registry
|
|
19
|
+
from lm_deluge.prompt import CachePattern, Conversation, prompts_to_conversations
|
|
19
20
|
from lm_deluge.request_context import RequestContext
|
|
20
21
|
|
|
21
22
|
|
|
@@ -162,6 +163,91 @@ async def _submit_anthropic_batch(file_path: str, headers: dict, model: str):
|
|
|
162
163
|
return batch_id
|
|
163
164
|
|
|
164
165
|
|
|
166
|
+
async def create_batch_files_oa(
|
|
167
|
+
model: str,
|
|
168
|
+
sampling_params: SamplingParams,
|
|
169
|
+
prompts: Sequence[str | list[dict] | Conversation],
|
|
170
|
+
batch_size: int = 50_000,
|
|
171
|
+
destination: str | None = None, # if none provided, temp files
|
|
172
|
+
):
|
|
173
|
+
MAX_BATCH_SIZE_BYTES = 200 * 1024 * 1024 # 200MB
|
|
174
|
+
MAX_BATCH_SIZE_ITEMS = batch_size
|
|
175
|
+
|
|
176
|
+
prompts = prompts_to_conversations(prompts)
|
|
177
|
+
if any(p is None for p in prompts):
|
|
178
|
+
raise ValueError("All prompts must be valid.")
|
|
179
|
+
|
|
180
|
+
model_obj = APIModel.from_registry(model)
|
|
181
|
+
|
|
182
|
+
current_batch = []
|
|
183
|
+
current_batch_size = 0
|
|
184
|
+
file_paths = []
|
|
185
|
+
|
|
186
|
+
for idx, prompt in enumerate(prompts):
|
|
187
|
+
assert isinstance(prompt, Conversation)
|
|
188
|
+
context = RequestContext(
|
|
189
|
+
task_id=idx,
|
|
190
|
+
model_name=model,
|
|
191
|
+
prompt=prompt,
|
|
192
|
+
sampling_params=sampling_params,
|
|
193
|
+
)
|
|
194
|
+
request = {
|
|
195
|
+
"custom_id": str(idx),
|
|
196
|
+
"method": "POST",
|
|
197
|
+
"url": "/v1/chat/completions",
|
|
198
|
+
"body": await _build_oa_chat_request(model_obj, context),
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
# Calculate size of this request
|
|
202
|
+
request_json = json.dumps(request) + "\n"
|
|
203
|
+
request_size = len(request_json.encode("utf-8"))
|
|
204
|
+
|
|
205
|
+
# Check if adding this request would exceed limits
|
|
206
|
+
would_exceed_size = current_batch_size + request_size > MAX_BATCH_SIZE_BYTES
|
|
207
|
+
would_exceed_items = len(current_batch) >= MAX_BATCH_SIZE_ITEMS
|
|
208
|
+
|
|
209
|
+
if current_batch and (would_exceed_size or would_exceed_items):
|
|
210
|
+
# Submit current batch
|
|
211
|
+
def write_batch_file():
|
|
212
|
+
with tempfile.NamedTemporaryFile(
|
|
213
|
+
mode="w+", suffix=".jsonl", delete=False
|
|
214
|
+
) as f:
|
|
215
|
+
for batch_request in current_batch:
|
|
216
|
+
json.dump(batch_request, f)
|
|
217
|
+
f.write("\n")
|
|
218
|
+
print("wrote", len(current_batch), "items")
|
|
219
|
+
return f.name
|
|
220
|
+
|
|
221
|
+
file_path = await asyncio.to_thread(write_batch_file)
|
|
222
|
+
file_paths.append(file_path)
|
|
223
|
+
# Start new batch
|
|
224
|
+
current_batch = []
|
|
225
|
+
current_batch_size = 0
|
|
226
|
+
# current_batch_start_idx = idx
|
|
227
|
+
|
|
228
|
+
# Add request to current batch
|
|
229
|
+
current_batch.append(request)
|
|
230
|
+
current_batch_size += request_size
|
|
231
|
+
|
|
232
|
+
# Submit final batch if it has items
|
|
233
|
+
if current_batch:
|
|
234
|
+
|
|
235
|
+
def write_final_batch_file():
|
|
236
|
+
with tempfile.NamedTemporaryFile(
|
|
237
|
+
mode="w+", suffix=".jsonl", delete=False
|
|
238
|
+
) as f:
|
|
239
|
+
for batch_request in current_batch:
|
|
240
|
+
json.dump(batch_request, f)
|
|
241
|
+
f.write("\n")
|
|
242
|
+
print("wrote", len(current_batch), "items")
|
|
243
|
+
return f.name
|
|
244
|
+
|
|
245
|
+
file_path = await asyncio.to_thread(write_final_batch_file)
|
|
246
|
+
file_paths.append(file_path)
|
|
247
|
+
|
|
248
|
+
return file_paths
|
|
249
|
+
|
|
250
|
+
|
|
165
251
|
async def submit_batches_oa(
|
|
166
252
|
model: str,
|
|
167
253
|
sampling_params: SamplingParams,
|
lm_deluge/client.py
CHANGED
|
@@ -356,16 +356,16 @@ class _LLMClient(BaseModel):
|
|
|
356
356
|
prompts = prompts_to_conversations(prompts)
|
|
357
357
|
ids = list(range(len(prompts)))
|
|
358
358
|
results: list[APIResponse | None] = [None for _ in range(len(prompts))]
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
tracker
|
|
359
|
+
# Use existing tracker if client has been opened; otherwise open/close automatically
|
|
360
|
+
tracker: StatusTracker
|
|
361
|
+
tracker_preopened = self._tracker is not None
|
|
362
|
+
if tracker_preopened:
|
|
363
|
+
tracker = self._tracker # type: ignore[assignment]
|
|
364
|
+
tracker.add_to_total(len(prompts))
|
|
365
|
+
else:
|
|
366
|
+
self.open(total=len(prompts), show_progress=show_progress)
|
|
367
|
+
tracker = self._tracker # type: ignore[assignment]
|
|
368
|
+
assert tracker is not None
|
|
369
369
|
|
|
370
370
|
# Create retry queue for failed requests
|
|
371
371
|
retry_queue: asyncio.Queue[RequestContext] = asyncio.Queue()
|
|
@@ -458,7 +458,8 @@ class _LLMClient(BaseModel):
|
|
|
458
458
|
# Sleep - original logic
|
|
459
459
|
await asyncio.sleep(seconds_to_sleep_each_loop + tracker.seconds_to_pause)
|
|
460
460
|
|
|
461
|
-
|
|
461
|
+
if not tracker_preopened:
|
|
462
|
+
self.close()
|
|
462
463
|
|
|
463
464
|
if return_completions_only:
|
|
464
465
|
return [r.completion if r is not None else None for r in results]
|
lm_deluge/tracker.py
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
lm_deluge/__init__.py,sha256=mAztMuxINmh7dGbYnT8tsmw1eryQAvd0jpY8yHzd0EE,315
|
|
2
2
|
lm_deluge/agent.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
|
-
lm_deluge/batches.py,sha256=
|
|
3
|
+
lm_deluge/batches.py,sha256=rQocJLyIs3Ko_nRdAE9jT__5cKWYxiIRAH_Lw3L0E1k,24653
|
|
4
4
|
lm_deluge/cache.py,sha256=VB1kv8rM2t5XWPR60uhszFcxLDnVKOe1oA5hYjVDjIo,4375
|
|
5
5
|
lm_deluge/cli.py,sha256=Ilww5gOw3J5v0NReq_Ra4hhxU4BCIJBl1oTGxJZKedc,12065
|
|
6
|
-
lm_deluge/client.py,sha256=
|
|
6
|
+
lm_deluge/client.py,sha256=TeaFqAzMKD-oFEfX-L5Qsh-o6G-SKQgPSLWCNhjmMYE,34193
|
|
7
7
|
lm_deluge/config.py,sha256=H1tQyJDNHGFuwxqQNL5Z-CjWAC0luHSBA3iY_pxmACM,932
|
|
8
8
|
lm_deluge/embed.py,sha256=CO-TOlC5kOTAM8lcnicoG4u4K664vCBwHF1vHa-nAGg,13382
|
|
9
9
|
lm_deluge/errors.py,sha256=oHjt7YnxWbh-eXMScIzov4NvpJMo0-2r5J6Wh5DQ1tk,209
|
|
@@ -14,7 +14,7 @@ lm_deluge/prompt.py,sha256=quG4dzK2yMiRqPiF67USY5Gl2TqT3rwYkZDJTfwZFHw,37183
|
|
|
14
14
|
lm_deluge/request_context.py,sha256=o33LSEwnK6YPhZeulUoSE_VrdKCXiCQa0tjjixK2K6M,2540
|
|
15
15
|
lm_deluge/rerank.py,sha256=-NBAJdHz9OB-SWWJnHzkFmeVO4wR6lFV7Vw-SxG7aVo,11457
|
|
16
16
|
lm_deluge/tool.py,sha256=_coOKB9nPNVZoseMRumRyQ8BMR7_d0IlstzMHNT69JY,15732
|
|
17
|
-
lm_deluge/tracker.py,sha256=
|
|
17
|
+
lm_deluge/tracker.py,sha256=EHFPsS94NmsON2u97rSE70q1t6pwCsixUmGV-kIphMs,11531
|
|
18
18
|
lm_deluge/usage.py,sha256=VMEKghePFIID5JFBObqYxFpgYxnbYm_dnHy7V1-_T6M,4866
|
|
19
19
|
lm_deluge/api_requests/__init__.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
20
20
|
lm_deluge/api_requests/anthropic.py,sha256=J5BzYV7aYNoL6FPArB6usyS267z1BguZTRY5JLMd0So,8159
|
|
@@ -64,8 +64,8 @@ lm_deluge/util/logprobs.py,sha256=UkBZakOxWluaLqHrjARu7xnJ0uCHVfLGHJdnYlEcutk,11
|
|
|
64
64
|
lm_deluge/util/spatial.py,sha256=BsF_UKhE-x0xBirc-bV1xSKZRTUhsOBdGqsMKme20C8,4099
|
|
65
65
|
lm_deluge/util/validation.py,sha256=hz5dDb3ebvZrZhnaWxOxbNSVMI6nmaOODBkk0htAUhs,1575
|
|
66
66
|
lm_deluge/util/xml.py,sha256=Ft4zajoYBJR3HHCt2oHwGfymGLdvp_gegVmJ-Wqk4Ck,10547
|
|
67
|
-
lm_deluge-0.0.
|
|
68
|
-
lm_deluge-0.0.
|
|
69
|
-
lm_deluge-0.0.
|
|
70
|
-
lm_deluge-0.0.
|
|
71
|
-
lm_deluge-0.0.
|
|
67
|
+
lm_deluge-0.0.41.dist-info/licenses/LICENSE,sha256=uNNXGXPCw2TC7CUs7SEBkA-Mz6QBQFWUUEWDMgEs1dU,1058
|
|
68
|
+
lm_deluge-0.0.41.dist-info/METADATA,sha256=JQLcTcp79Lqe5WPz8F2JPTZNVIWi5Z0NHoXakPkvzfw,13443
|
|
69
|
+
lm_deluge-0.0.41.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
70
|
+
lm_deluge-0.0.41.dist-info/top_level.txt,sha256=hqU-TJX93yBwpgkDtYcXyLr3t7TLSCCZ_reytJjwBaE,10
|
|
71
|
+
lm_deluge-0.0.41.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|