together 1.5.5__py3-none-any.whl → 1.5.7__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.
- together/cli/api/finetune.py +11 -3
- together/resources/code_interpreter.py +28 -4
- together/resources/finetune.py +19 -7
- together/types/code_interpreter.py +11 -0
- together/types/finetune.py +9 -1
- {together-1.5.5.dist-info → together-1.5.7.dist-info}/METADATA +26 -2
- {together-1.5.5.dist-info → together-1.5.7.dist-info}/RECORD +10 -10
- {together-1.5.5.dist-info → together-1.5.7.dist-info}/LICENSE +0 -0
- {together-1.5.5.dist-info → together-1.5.7.dist-info}/WHEEL +0 -0
- {together-1.5.5.dist-info → together-1.5.7.dist-info}/entry_points.txt +0 -0
together/cli/api/finetune.py
CHANGED
|
@@ -258,10 +258,13 @@ def create(
|
|
|
258
258
|
raise click.BadParameter(
|
|
259
259
|
f"LoRA fine-tuning is not supported for the model `{model}`"
|
|
260
260
|
)
|
|
261
|
-
|
|
261
|
+
if training_method == "dpo":
|
|
262
|
+
default_batch_size = model_limits.lora_training.max_batch_size_dpo
|
|
263
|
+
else:
|
|
264
|
+
default_batch_size = model_limits.lora_training.max_batch_size
|
|
262
265
|
default_values = {
|
|
263
266
|
"lora_r": model_limits.lora_training.max_rank,
|
|
264
|
-
"batch_size":
|
|
267
|
+
"batch_size": default_batch_size,
|
|
265
268
|
"learning_rate": 1e-3,
|
|
266
269
|
}
|
|
267
270
|
|
|
@@ -288,7 +291,12 @@ def create(
|
|
|
288
291
|
|
|
289
292
|
batch_size_source = ctx.get_parameter_source("batch_size") # type: ignore[attr-defined]
|
|
290
293
|
if batch_size_source == ParameterSource.DEFAULT:
|
|
291
|
-
|
|
294
|
+
if training_method == "dpo":
|
|
295
|
+
training_args["batch_size"] = (
|
|
296
|
+
model_limits.full_training.max_batch_size_dpo
|
|
297
|
+
)
|
|
298
|
+
else:
|
|
299
|
+
training_args["batch_size"] = model_limits.full_training.max_batch_size
|
|
292
300
|
|
|
293
301
|
if n_evals <= 0 and validation_file:
|
|
294
302
|
log_warn(
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
-
from typing import Dict, Literal, Optional
|
|
3
|
+
from typing import Any, Dict, List, Literal, Optional
|
|
4
|
+
from pydantic import ValidationError
|
|
4
5
|
|
|
5
6
|
from together.abstract import api_requestor
|
|
6
7
|
from together.together_response import TogetherResponse
|
|
7
8
|
from together.types import TogetherClient, TogetherRequest
|
|
8
|
-
from together.types.code_interpreter import ExecuteResponse
|
|
9
|
+
from together.types.code_interpreter import ExecuteResponse, FileInput
|
|
9
10
|
|
|
10
11
|
|
|
11
12
|
class CodeInterpreter:
|
|
@@ -19,22 +20,28 @@ class CodeInterpreter:
|
|
|
19
20
|
code: str,
|
|
20
21
|
language: Literal["python"],
|
|
21
22
|
session_id: Optional[str] = None,
|
|
23
|
+
files: Optional[List[Dict[str, Any]]] = None,
|
|
22
24
|
) -> ExecuteResponse:
|
|
23
|
-
"""Execute a code snippet.
|
|
25
|
+
"""Execute a code snippet, optionally with files.
|
|
24
26
|
|
|
25
27
|
Args:
|
|
26
28
|
code (str): Code snippet to execute
|
|
27
29
|
language (str): Programming language for the code to execute. Currently only supports Python.
|
|
28
30
|
session_id (str, optional): Identifier of the current session. Used to make follow-up calls.
|
|
31
|
+
files (List[Dict], optional): Files to upload to the session before executing the code.
|
|
29
32
|
|
|
30
33
|
Returns:
|
|
31
34
|
ExecuteResponse: Object containing execution results and outputs
|
|
35
|
+
|
|
36
|
+
Raises:
|
|
37
|
+
ValidationError: If any dictionary in the `files` list does not conform to the
|
|
38
|
+
required structure or types.
|
|
32
39
|
"""
|
|
33
40
|
requestor = api_requestor.APIRequestor(
|
|
34
41
|
client=self._client,
|
|
35
42
|
)
|
|
36
43
|
|
|
37
|
-
data: Dict[str,
|
|
44
|
+
data: Dict[str, Any] = {
|
|
38
45
|
"code": code,
|
|
39
46
|
"language": language,
|
|
40
47
|
}
|
|
@@ -42,6 +49,23 @@ class CodeInterpreter:
|
|
|
42
49
|
if session_id is not None:
|
|
43
50
|
data["session_id"] = session_id
|
|
44
51
|
|
|
52
|
+
if files is not None:
|
|
53
|
+
serialized_files = []
|
|
54
|
+
try:
|
|
55
|
+
for file_dict in files:
|
|
56
|
+
# Validate the dictionary by creating a FileInput instance
|
|
57
|
+
validated_file = FileInput(**file_dict)
|
|
58
|
+
# Serialize the validated model back to a dict for the API call
|
|
59
|
+
serialized_files.append(validated_file.model_dump())
|
|
60
|
+
except ValidationError as e:
|
|
61
|
+
raise ValueError(f"Invalid file input format: {e}") from e
|
|
62
|
+
except TypeError as e:
|
|
63
|
+
raise ValueError(
|
|
64
|
+
f"Invalid file input: Each item in 'files' must be a dictionary. Error: {e}"
|
|
65
|
+
) from e
|
|
66
|
+
|
|
67
|
+
data["files"] = serialized_files
|
|
68
|
+
|
|
45
69
|
# Use absolute URL to bypass the /v1 prefix
|
|
46
70
|
response, _, _ = requestor.request(
|
|
47
71
|
options=TogetherRequest(
|
together/resources/finetune.py
CHANGED
|
@@ -102,6 +102,7 @@ def create_finetune_request(
|
|
|
102
102
|
|
|
103
103
|
training_type: TrainingType = FullTrainingType()
|
|
104
104
|
max_batch_size: int = 0
|
|
105
|
+
max_batch_size_dpo: int = 0
|
|
105
106
|
min_batch_size: int = 0
|
|
106
107
|
if lora:
|
|
107
108
|
if model_limits.lora_training is None:
|
|
@@ -119,7 +120,7 @@ def create_finetune_request(
|
|
|
119
120
|
|
|
120
121
|
max_batch_size = model_limits.lora_training.max_batch_size
|
|
121
122
|
min_batch_size = model_limits.lora_training.min_batch_size
|
|
122
|
-
|
|
123
|
+
max_batch_size_dpo = model_limits.lora_training.max_batch_size_dpo
|
|
123
124
|
else:
|
|
124
125
|
if model_limits.full_training is None:
|
|
125
126
|
raise ValueError(
|
|
@@ -128,13 +129,24 @@ def create_finetune_request(
|
|
|
128
129
|
|
|
129
130
|
max_batch_size = model_limits.full_training.max_batch_size
|
|
130
131
|
min_batch_size = model_limits.full_training.min_batch_size
|
|
132
|
+
max_batch_size_dpo = model_limits.full_training.max_batch_size_dpo
|
|
131
133
|
|
|
132
|
-
|
|
134
|
+
if batch_size == "max":
|
|
135
|
+
if training_method == "dpo":
|
|
136
|
+
batch_size = max_batch_size_dpo
|
|
137
|
+
else:
|
|
138
|
+
batch_size = max_batch_size
|
|
133
139
|
|
|
134
|
-
if
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
140
|
+
if training_method == "sft":
|
|
141
|
+
if batch_size > max_batch_size:
|
|
142
|
+
raise ValueError(
|
|
143
|
+
f"Requested batch size of {batch_size} is higher that the maximum allowed value of {max_batch_size}."
|
|
144
|
+
)
|
|
145
|
+
elif training_method == "dpo":
|
|
146
|
+
if batch_size > max_batch_size_dpo:
|
|
147
|
+
raise ValueError(
|
|
148
|
+
f"Requested batch size of {batch_size} is higher that the maximum allowed value of {max_batch_size_dpo}."
|
|
149
|
+
)
|
|
138
150
|
|
|
139
151
|
if batch_size < min_batch_size:
|
|
140
152
|
raise ValueError(
|
|
@@ -600,7 +612,7 @@ class FineTuning:
|
|
|
600
612
|
raise ValueError(
|
|
601
613
|
"Only DEFAULT checkpoint type is allowed for FullTrainingType"
|
|
602
614
|
)
|
|
603
|
-
url += "&checkpoint=
|
|
615
|
+
url += "&checkpoint=model_output_path"
|
|
604
616
|
elif isinstance(ft_job.training_type, LoRATrainingType):
|
|
605
617
|
if checkpoint_type == DownloadCheckpointType.DEFAULT:
|
|
606
618
|
checkpoint_type = DownloadCheckpointType.MERGED
|
|
@@ -7,6 +7,16 @@ from pydantic import Field
|
|
|
7
7
|
from together.types.endpoints import TogetherJSONModel
|
|
8
8
|
|
|
9
9
|
|
|
10
|
+
class FileInput(TogetherJSONModel):
|
|
11
|
+
"""File input to be uploaded to the code interpreter session."""
|
|
12
|
+
|
|
13
|
+
name: str = Field(description="The name of the file.")
|
|
14
|
+
encoding: Literal["string", "base64"] = Field(
|
|
15
|
+
description="Encoding of the file content. Use 'string' for text files and 'base64' for binary files."
|
|
16
|
+
)
|
|
17
|
+
content: str = Field(description="The content of the file, encoded as specified.")
|
|
18
|
+
|
|
19
|
+
|
|
10
20
|
class InterpreterOutput(TogetherJSONModel):
|
|
11
21
|
"""Base class for interpreter output types."""
|
|
12
22
|
|
|
@@ -40,6 +50,7 @@ class ExecuteResponse(TogetherJSONModel):
|
|
|
40
50
|
|
|
41
51
|
|
|
42
52
|
__all__ = [
|
|
53
|
+
"FileInput",
|
|
43
54
|
"InterpreterOutput",
|
|
44
55
|
"ExecuteResponseData",
|
|
45
56
|
"ExecuteResponse",
|
together/types/finetune.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
from enum import Enum
|
|
4
|
-
from typing import List, Literal
|
|
4
|
+
from typing import List, Literal, Any
|
|
5
5
|
|
|
6
6
|
from pydantic import StrictBool, Field, field_validator
|
|
7
7
|
|
|
@@ -329,8 +329,16 @@ class FinetuneDownloadResult(BaseModel):
|
|
|
329
329
|
|
|
330
330
|
class FinetuneFullTrainingLimits(BaseModel):
|
|
331
331
|
max_batch_size: int
|
|
332
|
+
max_batch_size_dpo: int = -1
|
|
332
333
|
min_batch_size: int
|
|
333
334
|
|
|
335
|
+
def __init__(self, **data: Any) -> None:
|
|
336
|
+
super().__init__(**data)
|
|
337
|
+
if self.max_batch_size_dpo == -1:
|
|
338
|
+
half_max = self.max_batch_size // 2
|
|
339
|
+
rounded_half_max = (half_max // 8) * 8
|
|
340
|
+
self.max_batch_size_dpo = max(self.min_batch_size, rounded_half_max)
|
|
341
|
+
|
|
334
342
|
|
|
335
343
|
class FinetuneLoraTrainingLimits(FinetuneFullTrainingLimits):
|
|
336
344
|
max_rank: int
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: together
|
|
3
|
-
Version: 1.5.
|
|
3
|
+
Version: 1.5.7
|
|
4
4
|
Summary: Python client for Together's Cloud Platform!
|
|
5
5
|
License: Apache-2.0
|
|
6
6
|
Author: Together AI
|
|
@@ -23,7 +23,7 @@ Requires-Dist: pillow (>=11.1.0,<12.0.0)
|
|
|
23
23
|
Requires-Dist: pyarrow (>=10.0.1)
|
|
24
24
|
Requires-Dist: pydantic (>=2.6.3,<3.0.0)
|
|
25
25
|
Requires-Dist: requests (>=2.31.0,<3.0.0)
|
|
26
|
-
Requires-Dist: rich (>=13.8.1,<
|
|
26
|
+
Requires-Dist: rich (>=13.8.1,<15.0.0)
|
|
27
27
|
Requires-Dist: tabulate (>=0.9.0,<0.10.0)
|
|
28
28
|
Requires-Dist: tqdm (>=4.66.2,<5.0.0)
|
|
29
29
|
Requires-Dist: typer (>=0.9,<0.16)
|
|
@@ -220,6 +220,30 @@ async def async_chat_completion(messages):
|
|
|
220
220
|
asyncio.run(async_chat_completion(messages))
|
|
221
221
|
```
|
|
222
222
|
|
|
223
|
+
#### Fetching logprobs
|
|
224
|
+
|
|
225
|
+
Logprobs are logarithms of token-level generation probabilities that indicate the likelihood of the generated token based on the previous tokens in the context. Logprobs allow us to estimate the model's confidence in its outputs, which can be used to decide how to optimally consume the model's output (e.g. rejecting low confidence outputs, retrying or ensembling model outputs etc).
|
|
226
|
+
|
|
227
|
+
```python
|
|
228
|
+
from together import Together
|
|
229
|
+
|
|
230
|
+
client = Together()
|
|
231
|
+
|
|
232
|
+
response = client.chat.completions.create(
|
|
233
|
+
model="mistralai/Mixtral-8x7B-Instruct-v0.1",
|
|
234
|
+
messages=[{"role": "user", "content": "tell me about new york"}],
|
|
235
|
+
logprobs=1
|
|
236
|
+
)
|
|
237
|
+
|
|
238
|
+
response_lobprobs = response.choices[0].logprobs
|
|
239
|
+
|
|
240
|
+
print(dict(zip(response_lobprobs.tokens, response_lobprobs.token_logprobs)))
|
|
241
|
+
# {'New': -2.384e-07, ' York': 0.0, ',': 0.0, ' also': -0.20703125, ' known': -0.20214844, ' as': -8.34465e-07, ... }
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
More details about using logprobs in Together's API can be found [here](https://docs.together.ai/docs/logprobs).
|
|
245
|
+
|
|
246
|
+
|
|
223
247
|
### Completions
|
|
224
248
|
|
|
225
249
|
Completions are for code and language models shown [here](https://docs.together.ai/docs/inference-models). Below, a code model example is shown.
|
|
@@ -7,7 +7,7 @@ together/cli/api/chat.py,sha256=2PHRb-9T-lUEKhUJFtc7SxJv3shCVx40gq_8pzfsewM,9234
|
|
|
7
7
|
together/cli/api/completions.py,sha256=l-Zw5t7hojL3w8xd_mitS2NRB72i5Z0xwkzH0rT5XMc,4263
|
|
8
8
|
together/cli/api/endpoints.py,sha256=tM42PthzkpTjOkmL6twyWYXqEQw0DOqsEKTZdhp6vKU,13284
|
|
9
9
|
together/cli/api/files.py,sha256=QLYEXRkY8J2Gg1SbTCtzGfoTMvosoeACNK83L_oLubs,3397
|
|
10
|
-
together/cli/api/finetune.py,sha256=
|
|
10
|
+
together/cli/api/finetune.py,sha256=AnVa5sDB4ZCR_S-CMJStj1vzi0b2AwYQT2c3rkUnAbQ,16238
|
|
11
11
|
together/cli/api/images.py,sha256=GADSeaNUHUVMtWovmccGuKc28IJ9E_v4vAEwYHJhu5o,2645
|
|
12
12
|
together/cli/api/models.py,sha256=CXw8B1hqNkadogi58GIXhLg_dTJnvTBaE7Kq1_xQ-10,1423
|
|
13
13
|
together/cli/api/utils.py,sha256=IuqYWPnLI38_Bqd7lj8V_SnGdYc59pRmMbQmciS4FsM,1326
|
|
@@ -29,12 +29,12 @@ together/resources/audio/__init__.py,sha256=e7xp0Lkp_nMAHXcuFHS7dLXP_YqTPMMZIilW
|
|
|
29
29
|
together/resources/audio/speech.py,sha256=81ib_gIo-Rxoaipx2Pi9ZsKnOTjeFPwSlBrcUkyX5xk,5211
|
|
30
30
|
together/resources/chat/__init__.py,sha256=RsTptdP8MeGjcdIjze896-J27cRvCbUoMft0X2BVlQ8,617
|
|
31
31
|
together/resources/chat/completions.py,sha256=jYiNZsWa8RyEacL0VgxWj1egJ857oU4nxIY8uqGHcaU,14459
|
|
32
|
-
together/resources/code_interpreter.py,sha256=
|
|
32
|
+
together/resources/code_interpreter.py,sha256=vbN8Mh5MG6HQvqra7p61leIyfebgbgJTM_q2A_Fylhw,2948
|
|
33
33
|
together/resources/completions.py,sha256=5Wa-ZjPCxRcam6CDe7KgGYlTA7yJZMmd5TrRgGCL_ug,11726
|
|
34
34
|
together/resources/embeddings.py,sha256=PTvLb82yjG_-iQOyuhsilp77Fr7gZ0o6WD2KeRnKoxs,2675
|
|
35
35
|
together/resources/endpoints.py,sha256=NNjp-wyzOotzlscGGrANhOHxQBjHTN8f5kTQTH_CLvE,17177
|
|
36
36
|
together/resources/files.py,sha256=bnPbaF25e4InBRPvHwXHXT-oSX1Z1sZRsnQW5wq82U4,4990
|
|
37
|
-
together/resources/finetune.py,sha256=
|
|
37
|
+
together/resources/finetune.py,sha256=7rcGfZqre1szzlh1MwseLlghZ9vRHwHAdeITvP2ohJY,36942
|
|
38
38
|
together/resources/images.py,sha256=LQUjKPaFxWTqOAPnyF1Pp7Rz4NLOYhmoKwshpYiprEM,4923
|
|
39
39
|
together/resources/models.py,sha256=qgmAXv61Cq4oLxytenEZBywA8shldDHYxJ_EAu_4JWQ,3864
|
|
40
40
|
together/resources/rerank.py,sha256=3Ju_aRSyZ1s_3zCSNZnSnEJErUVmt2xa3M8z1nvejMA,3931
|
|
@@ -43,14 +43,14 @@ together/types/__init__.py,sha256=VgIbE2AOK9c2TQUzkbRbyRkdia2COXJXl_wxPaoxR-M,26
|
|
|
43
43
|
together/types/abstract.py,sha256=1lFQI_3WjsR_t1128AeKW0aTk6EiM6Gh1J3ZuyLLPao,642
|
|
44
44
|
together/types/audio_speech.py,sha256=jlj8BZf3dkIDARF1P11fuenVLj4try8Yx4RN-EAkhOU,2609
|
|
45
45
|
together/types/chat_completions.py,sha256=ggwt1LlBXTB_hZKbtLsjg8j-gXxO8pUUQfTrxUmRXHU,5078
|
|
46
|
-
together/types/code_interpreter.py,sha256=
|
|
46
|
+
together/types/code_interpreter.py,sha256=cjF8TKgRkJllHS4i24dWQZBGTRsG557eHSewOiip0Kk,1770
|
|
47
47
|
together/types/common.py,sha256=kxZ-N9xtBsGYZBmbIWnZ0rfT3Pn8PFB7sAbp3iv96pw,1525
|
|
48
48
|
together/types/completions.py,sha256=o3FR5ixsTUj-a3pmOUzbSQg-hESVhpqrC9UD__VCqr4,2971
|
|
49
49
|
together/types/embeddings.py,sha256=J7grkYYn7xhqeKaBO2T-8XQRtHhkzYzymovtGdIUK5A,751
|
|
50
50
|
together/types/endpoints.py,sha256=EzNhHOoQ_D9fUdNQtxQPeSWiFzdFLqpNodN0YLmv_h0,4393
|
|
51
51
|
together/types/error.py,sha256=OVlCs3cx_2WhZK4JzHT8SQyRIIqKOP1AZQ4y1PydjAE,370
|
|
52
52
|
together/types/files.py,sha256=-rEUfsV6f2vZB9NrFxT4_933ubsDIUNkPB-3OlOFk4A,1954
|
|
53
|
-
together/types/finetune.py,sha256=
|
|
53
|
+
together/types/finetune.py,sha256=KVaos9wBjFZFvVoL4DBx3PlXjGAx7_0CTQxKzEZzf40,10940
|
|
54
54
|
together/types/images.py,sha256=xnC-FZGdZU30WSFTybfGneWxb-kj0ZGufJsgHtB8j0k,980
|
|
55
55
|
together/types/models.py,sha256=nwQIZGHKZpX9I6mK8z56VW70YC6Ry6JGsVa0s99QVxc,1055
|
|
56
56
|
together/types/rerank.py,sha256=qZfuXOn7MZ6ly8hpJ_MZ7OU_Bi1-cgYNSB20Wja8Qkk,1061
|
|
@@ -60,8 +60,8 @@ together/utils/api_helpers.py,sha256=2K0O6qeEQ2zVFvi5NBN5m2kjZJaS3-JfKFecQ7SmGaw
|
|
|
60
60
|
together/utils/files.py,sha256=rfp10qU0urtWOXXFeasFtO9xp-1KIhM3S43JxcnHmL0,16438
|
|
61
61
|
together/utils/tools.py,sha256=H2MTJhEqtBllaDvOyZehIO_IVNK3P17rSDeILtJIVag,2964
|
|
62
62
|
together/version.py,sha256=p03ivHyE0SyWU4jAnRTBi_sOwywVWoZPU4g2gzRgG-Y,126
|
|
63
|
-
together-1.5.
|
|
64
|
-
together-1.5.
|
|
65
|
-
together-1.5.
|
|
66
|
-
together-1.5.
|
|
67
|
-
together-1.5.
|
|
63
|
+
together-1.5.7.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
64
|
+
together-1.5.7.dist-info/METADATA,sha256=c8znCsq8LslEJ8Y7Kep9Ld_fIUsL2hpKjgZGv21Yrk4,15415
|
|
65
|
+
together-1.5.7.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
|
|
66
|
+
together-1.5.7.dist-info/entry_points.txt,sha256=G-b5NKW6lUUf1V1fH8IPTBb7jXnK7lhbX9H1zTEJXPs,50
|
|
67
|
+
together-1.5.7.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|