together 1.2.2__py3-none-any.whl → 1.2.4__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/__init__.py +14 -6
- together/abstract/__init__.py +0 -1
- together/cli/api/chat.py +4 -2
- together/cli/api/completions.py +4 -2
- together/cli/api/files.py +4 -4
- together/cli/api/finetune.py +46 -5
- together/error.py +1 -1
- together/legacy/complete.py +6 -4
- together/legacy/embeddings.py +3 -1
- together/legacy/files.py +9 -5
- together/legacy/finetune.py +10 -6
- together/legacy/images.py +3 -1
- together/legacy/models.py +2 -2
- together/resources/chat/completions.py +2 -2
- together/resources/completions.py +2 -2
- together/resources/embeddings.py +2 -2
- together/resources/finetune.py +25 -2
- together/resources/images.py +2 -2
- together/types/__init__.py +6 -0
- together/types/chat_completions.py +5 -2
- together/types/finetune.py +33 -5
- {together-1.2.2.dist-info → together-1.2.4.dist-info}/METADATA +1 -1
- {together-1.2.2.dist-info → together-1.2.4.dist-info}/RECORD +26 -26
- {together-1.2.2.dist-info → together-1.2.4.dist-info}/LICENSE +0 -0
- {together-1.2.2.dist-info → together-1.2.4.dist-info}/WHEEL +0 -0
- {together-1.2.2.dist-info → together-1.2.4.dist-info}/entry_points.txt +0 -0
together/__init__.py
CHANGED
|
@@ -16,6 +16,12 @@ from together import (
|
|
|
16
16
|
)
|
|
17
17
|
from together.version import VERSION
|
|
18
18
|
|
|
19
|
+
from together.legacy.complete import AsyncComplete, Complete, Completion
|
|
20
|
+
from together.legacy.embeddings import Embeddings
|
|
21
|
+
from together.legacy.files import Files
|
|
22
|
+
from together.legacy.finetune import Finetune
|
|
23
|
+
from together.legacy.images import Image
|
|
24
|
+
from together.legacy.models import Models
|
|
19
25
|
|
|
20
26
|
version = VERSION
|
|
21
27
|
|
|
@@ -37,12 +43,6 @@ from together.client import AsyncClient, AsyncTogether, Client, Together
|
|
|
37
43
|
api_key: str | None = None # To be deprecated in the next major release
|
|
38
44
|
|
|
39
45
|
# Legacy functions
|
|
40
|
-
from together.legacy.complete import AsyncComplete, Complete, Completion
|
|
41
|
-
from together.legacy.embeddings import Embeddings
|
|
42
|
-
from together.legacy.files import Files
|
|
43
|
-
from together.legacy.finetune import Finetune
|
|
44
|
-
from together.legacy.images import Image
|
|
45
|
-
from together.legacy.models import Models
|
|
46
46
|
|
|
47
47
|
|
|
48
48
|
__all__ = [
|
|
@@ -61,4 +61,12 @@ __all__ = [
|
|
|
61
61
|
"together_response",
|
|
62
62
|
"client",
|
|
63
63
|
"utils",
|
|
64
|
+
"Complete",
|
|
65
|
+
"AsyncComplete",
|
|
66
|
+
"Completion",
|
|
67
|
+
"Embeddings",
|
|
68
|
+
"Files",
|
|
69
|
+
"Finetune",
|
|
70
|
+
"Image",
|
|
71
|
+
"Models",
|
|
64
72
|
]
|
together/abstract/__init__.py
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
from together.abstract.api_requestor import APIRequestor
|
together/cli/api/chat.py
CHANGED
|
@@ -238,7 +238,7 @@ def chat(
|
|
|
238
238
|
assert chunk.choices
|
|
239
239
|
|
|
240
240
|
if raw:
|
|
241
|
-
click.echo(f"{json.dumps(chunk.model_dump())}")
|
|
241
|
+
click.echo(f"{json.dumps(chunk.model_dump(exclude_none=True))}")
|
|
242
242
|
continue
|
|
243
243
|
|
|
244
244
|
should_print_header = len(chunk.choices) > 1
|
|
@@ -261,7 +261,9 @@ def chat(
|
|
|
261
261
|
assert isinstance(response.choices, list)
|
|
262
262
|
|
|
263
263
|
if raw:
|
|
264
|
-
click.echo(
|
|
264
|
+
click.echo(
|
|
265
|
+
f"{json.dumps(response.model_dump(exclude_none=True), indent=4)}"
|
|
266
|
+
)
|
|
265
267
|
return
|
|
266
268
|
|
|
267
269
|
should_print_header = len(response.choices) > 1
|
together/cli/api/completions.py
CHANGED
|
@@ -80,7 +80,7 @@ def completions(
|
|
|
80
80
|
assert chunk.choices
|
|
81
81
|
|
|
82
82
|
if raw:
|
|
83
|
-
click.echo(f"{json.dumps(chunk.model_dump())}")
|
|
83
|
+
click.echo(f"{json.dumps(chunk.model_dump(exclude_none=True))}")
|
|
84
84
|
continue
|
|
85
85
|
|
|
86
86
|
should_print_header = len(chunk.choices) > 1
|
|
@@ -104,7 +104,9 @@ def completions(
|
|
|
104
104
|
assert isinstance(response.choices, list)
|
|
105
105
|
|
|
106
106
|
if raw:
|
|
107
|
-
click.echo(
|
|
107
|
+
click.echo(
|
|
108
|
+
f"{json.dumps(response.model_dump(exclude_none=True), indent=4)}"
|
|
109
|
+
)
|
|
108
110
|
return
|
|
109
111
|
|
|
110
112
|
should_print_header = len(response.choices) > 1
|
together/cli/api/files.py
CHANGED
|
@@ -44,7 +44,7 @@ def upload(ctx: click.Context, file: pathlib.Path, purpose: str, check: bool) ->
|
|
|
44
44
|
|
|
45
45
|
response = client.files.upload(file=file, purpose=purpose, check=check)
|
|
46
46
|
|
|
47
|
-
click.echo(json.dumps(response.model_dump(), indent=4))
|
|
47
|
+
click.echo(json.dumps(response.model_dump(exclude_none=True), indent=4))
|
|
48
48
|
|
|
49
49
|
|
|
50
50
|
@files.command()
|
|
@@ -83,7 +83,7 @@ def retrieve(ctx: click.Context, id: str) -> None:
|
|
|
83
83
|
|
|
84
84
|
response = client.files.retrieve(id=id)
|
|
85
85
|
|
|
86
|
-
click.echo(json.dumps(response.model_dump(), indent=4))
|
|
86
|
+
click.echo(json.dumps(response.model_dump(exclude_none=True), indent=4))
|
|
87
87
|
|
|
88
88
|
|
|
89
89
|
@files.command()
|
|
@@ -97,7 +97,7 @@ def retrieve_content(ctx: click.Context, id: str, output: str) -> None:
|
|
|
97
97
|
|
|
98
98
|
response = client.files.retrieve_content(id=id, output=output)
|
|
99
99
|
|
|
100
|
-
click.echo(json.dumps(response.model_dump(), indent=4))
|
|
100
|
+
click.echo(json.dumps(response.model_dump(exclude_none=True), indent=4))
|
|
101
101
|
|
|
102
102
|
|
|
103
103
|
@files.command()
|
|
@@ -110,7 +110,7 @@ def delete(ctx: click.Context, id: str) -> None:
|
|
|
110
110
|
|
|
111
111
|
response = client.files.delete(id=id)
|
|
112
112
|
|
|
113
|
-
click.echo(json.dumps(response.model_dump(), indent=4))
|
|
113
|
+
click.echo(json.dumps(response.model_dump(exclude_none=True), indent=4))
|
|
114
114
|
|
|
115
115
|
|
|
116
116
|
@files.command()
|
together/cli/api/finetune.py
CHANGED
|
@@ -2,6 +2,7 @@ import json
|
|
|
2
2
|
from textwrap import wrap
|
|
3
3
|
|
|
4
4
|
import click
|
|
5
|
+
from click.core import ParameterSource # type: ignore[attr-defined]
|
|
5
6
|
from tabulate import tabulate
|
|
6
7
|
|
|
7
8
|
from together import Together
|
|
@@ -26,7 +27,22 @@ def fine_tuning(ctx: click.Context) -> None:
|
|
|
26
27
|
"--n-checkpoints", type=int, default=1, help="Number of checkpoints to save"
|
|
27
28
|
)
|
|
28
29
|
@click.option("--batch-size", type=int, default=32, help="Train batch size")
|
|
29
|
-
@click.option("--learning-rate", type=float, default=
|
|
30
|
+
@click.option("--learning-rate", type=float, default=1e-5, help="Learning rate")
|
|
31
|
+
@click.option(
|
|
32
|
+
"--lora/--no-lora",
|
|
33
|
+
type=bool,
|
|
34
|
+
default=False,
|
|
35
|
+
help="Whether to use LoRA adapters for fine-tuning",
|
|
36
|
+
)
|
|
37
|
+
@click.option("--lora-r", type=int, default=8, help="LoRA adapters' rank")
|
|
38
|
+
@click.option("--lora-dropout", type=float, default=0, help="LoRA adapters' dropout")
|
|
39
|
+
@click.option("--lora-alpha", type=float, default=8, help="LoRA adapters' alpha")
|
|
40
|
+
@click.option(
|
|
41
|
+
"--lora-trainable-modules",
|
|
42
|
+
type=str,
|
|
43
|
+
default="all-linear",
|
|
44
|
+
help="Trainable modules for LoRA adapters. For example, 'all-linear', 'q_proj,v_proj'",
|
|
45
|
+
)
|
|
30
46
|
@click.option(
|
|
31
47
|
"--suffix", type=str, default=None, help="Suffix for the fine-tuned model name"
|
|
32
48
|
)
|
|
@@ -39,12 +55,32 @@ def create(
|
|
|
39
55
|
n_checkpoints: int,
|
|
40
56
|
batch_size: int,
|
|
41
57
|
learning_rate: float,
|
|
58
|
+
lora: bool,
|
|
59
|
+
lora_r: int,
|
|
60
|
+
lora_dropout: float,
|
|
61
|
+
lora_alpha: float,
|
|
62
|
+
lora_trainable_modules: str,
|
|
42
63
|
suffix: str,
|
|
43
64
|
wandb_api_key: str,
|
|
44
65
|
) -> None:
|
|
45
66
|
"""Start fine-tuning"""
|
|
46
67
|
client: Together = ctx.obj
|
|
47
68
|
|
|
69
|
+
if lora:
|
|
70
|
+
learning_rate_source = click.get_current_context().get_parameter_source( # type: ignore[attr-defined]
|
|
71
|
+
"learning_rate"
|
|
72
|
+
)
|
|
73
|
+
if learning_rate_source == ParameterSource.DEFAULT:
|
|
74
|
+
learning_rate = 1e-3
|
|
75
|
+
else:
|
|
76
|
+
for param in ["lora_r", "lora_dropout", "lora_alpha", "lora_trainable_modules"]:
|
|
77
|
+
param_source = click.get_current_context().get_parameter_source(param) # type: ignore[attr-defined]
|
|
78
|
+
if param_source != ParameterSource.DEFAULT:
|
|
79
|
+
raise click.BadParameter(
|
|
80
|
+
f"You set LoRA parameter `{param}` for a full fine-tuning job. "
|
|
81
|
+
f"Please change the job type with --lora or remove `{param}` from the arguments"
|
|
82
|
+
)
|
|
83
|
+
|
|
48
84
|
response = client.fine_tuning.create(
|
|
49
85
|
training_file=training_file,
|
|
50
86
|
model=model,
|
|
@@ -52,11 +88,16 @@ def create(
|
|
|
52
88
|
n_checkpoints=n_checkpoints,
|
|
53
89
|
batch_size=batch_size,
|
|
54
90
|
learning_rate=learning_rate,
|
|
91
|
+
lora=lora,
|
|
92
|
+
lora_r=lora_r,
|
|
93
|
+
lora_dropout=lora_dropout,
|
|
94
|
+
lora_alpha=lora_alpha,
|
|
95
|
+
lora_trainable_modules=lora_trainable_modules,
|
|
55
96
|
suffix=suffix,
|
|
56
97
|
wandb_api_key=wandb_api_key,
|
|
57
98
|
)
|
|
58
99
|
|
|
59
|
-
click.echo(json.dumps(response.model_dump(), indent=4))
|
|
100
|
+
click.echo(json.dumps(response.model_dump(exclude_none=True), indent=4))
|
|
60
101
|
|
|
61
102
|
|
|
62
103
|
@fine_tuning.command()
|
|
@@ -101,7 +142,7 @@ def retrieve(ctx: click.Context, fine_tune_id: str) -> None:
|
|
|
101
142
|
# remove events from response for cleaner output
|
|
102
143
|
response.events = None
|
|
103
144
|
|
|
104
|
-
click.echo(json.dumps(response.model_dump(), indent=4))
|
|
145
|
+
click.echo(json.dumps(response.model_dump(exclude_none=True), indent=4))
|
|
105
146
|
|
|
106
147
|
|
|
107
148
|
@fine_tuning.command()
|
|
@@ -123,7 +164,7 @@ def cancel(ctx: click.Context, fine_tune_id: str, quiet: bool = False) -> None:
|
|
|
123
164
|
return
|
|
124
165
|
response = client.fine_tuning.cancel(fine_tune_id)
|
|
125
166
|
|
|
126
|
-
click.echo(json.dumps(response.model_dump(), indent=4))
|
|
167
|
+
click.echo(json.dumps(response.model_dump(exclude_none=True), indent=4))
|
|
127
168
|
|
|
128
169
|
|
|
129
170
|
@fine_tuning.command()
|
|
@@ -182,4 +223,4 @@ def download(
|
|
|
182
223
|
fine_tune_id, output=output_dir, checkpoint_step=checkpoint_step
|
|
183
224
|
)
|
|
184
225
|
|
|
185
|
-
click.echo(json.dumps(response.model_dump(), indent=4))
|
|
226
|
+
click.echo(json.dumps(response.model_dump(exclude_none=True), indent=4))
|
together/error.py
CHANGED
together/legacy/complete.py
CHANGED
|
@@ -25,9 +25,11 @@ class Complete:
|
|
|
25
25
|
|
|
26
26
|
client = together.Together(api_key=api_key)
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
result = client.completions.create(prompt=prompt, stream=False, **kwargs)
|
|
29
|
+
|
|
30
|
+
assert isinstance(result, CompletionResponse)
|
|
31
|
+
|
|
32
|
+
return result.model_dump(exclude_none=True)
|
|
31
33
|
|
|
32
34
|
@classmethod
|
|
33
35
|
@deprecated # type: ignore
|
|
@@ -46,7 +48,7 @@ class Complete:
|
|
|
46
48
|
client = together.Together(api_key=api_key)
|
|
47
49
|
|
|
48
50
|
return (
|
|
49
|
-
token.model_dump() # type: ignore
|
|
51
|
+
token.model_dump(exclude_none=True) # type: ignore
|
|
50
52
|
for token in client.completions.create(prompt=prompt, stream=True, **kwargs)
|
|
51
53
|
)
|
|
52
54
|
|
together/legacy/embeddings.py
CHANGED
together/legacy/files.py
CHANGED
|
@@ -24,7 +24,7 @@ class Files:
|
|
|
24
24
|
|
|
25
25
|
client = together.Together(api_key=api_key)
|
|
26
26
|
|
|
27
|
-
return client.files.list().model_dump()
|
|
27
|
+
return client.files.list().model_dump(exclude_none=True)
|
|
28
28
|
|
|
29
29
|
@classmethod
|
|
30
30
|
def check(self, file: str) -> Dict[str, object]:
|
|
@@ -54,7 +54,9 @@ class Files:
|
|
|
54
54
|
client = together.Together(api_key=api_key)
|
|
55
55
|
|
|
56
56
|
# disabling the check, because it was run previously
|
|
57
|
-
response = client.files.upload(file=file, check=False).model_dump(
|
|
57
|
+
response = client.files.upload(file=file, check=False).model_dump(
|
|
58
|
+
exclude_none=True
|
|
59
|
+
)
|
|
58
60
|
|
|
59
61
|
if check:
|
|
60
62
|
response["report_dict"] = report_dict
|
|
@@ -76,7 +78,7 @@ class Files:
|
|
|
76
78
|
|
|
77
79
|
client = together.Together(api_key=api_key)
|
|
78
80
|
|
|
79
|
-
return client.files.delete(id=file_id).model_dump()
|
|
81
|
+
return client.files.delete(id=file_id).model_dump(exclude_none=True)
|
|
80
82
|
|
|
81
83
|
@classmethod
|
|
82
84
|
@deprecated # type: ignore
|
|
@@ -93,7 +95,7 @@ class Files:
|
|
|
93
95
|
|
|
94
96
|
client = together.Together(api_key=api_key)
|
|
95
97
|
|
|
96
|
-
return client.files.retrieve(id=file_id).model_dump()
|
|
98
|
+
return client.files.retrieve(id=file_id).model_dump(exclude_none=True)
|
|
97
99
|
|
|
98
100
|
@classmethod
|
|
99
101
|
@deprecated # type: ignore
|
|
@@ -111,7 +113,9 @@ class Files:
|
|
|
111
113
|
|
|
112
114
|
client = together.Together(api_key=api_key)
|
|
113
115
|
|
|
114
|
-
return client.files.retrieve_content(id=file_id, output=output).
|
|
116
|
+
return client.files.retrieve_content(id=file_id, output=output).dict(
|
|
117
|
+
exclude_none=True
|
|
118
|
+
)
|
|
115
119
|
|
|
116
120
|
@classmethod
|
|
117
121
|
@deprecated # type: ignore
|
together/legacy/finetune.py
CHANGED
|
@@ -47,7 +47,7 @@ class Finetune:
|
|
|
47
47
|
learning_rate=learning_rate,
|
|
48
48
|
suffix=suffix,
|
|
49
49
|
wandb_api_key=wandb_api_key,
|
|
50
|
-
).model_dump()
|
|
50
|
+
).model_dump(exclude_none=True)
|
|
51
51
|
|
|
52
52
|
@classmethod
|
|
53
53
|
@deprecated # type: ignore
|
|
@@ -63,7 +63,7 @@ class Finetune:
|
|
|
63
63
|
|
|
64
64
|
client = together.Together(api_key=api_key)
|
|
65
65
|
|
|
66
|
-
return client.fine_tuning.list().model_dump()
|
|
66
|
+
return client.fine_tuning.list().model_dump(exclude_none=True)
|
|
67
67
|
|
|
68
68
|
@classmethod
|
|
69
69
|
@deprecated # type: ignore
|
|
@@ -80,7 +80,9 @@ class Finetune:
|
|
|
80
80
|
|
|
81
81
|
client = together.Together(api_key=api_key)
|
|
82
82
|
|
|
83
|
-
return client.fine_tuning.retrieve(id=fine_tune_id).model_dump(
|
|
83
|
+
return client.fine_tuning.retrieve(id=fine_tune_id).model_dump(
|
|
84
|
+
exclude_none=True
|
|
85
|
+
)
|
|
84
86
|
|
|
85
87
|
@classmethod
|
|
86
88
|
@deprecated # type: ignore
|
|
@@ -97,7 +99,7 @@ class Finetune:
|
|
|
97
99
|
|
|
98
100
|
client = together.Together(api_key=api_key)
|
|
99
101
|
|
|
100
|
-
return client.fine_tuning.cancel(id=fine_tune_id).model_dump()
|
|
102
|
+
return client.fine_tuning.cancel(id=fine_tune_id).model_dump(exclude_none=True)
|
|
101
103
|
|
|
102
104
|
@classmethod
|
|
103
105
|
@deprecated # type: ignore
|
|
@@ -114,7 +116,9 @@ class Finetune:
|
|
|
114
116
|
|
|
115
117
|
client = together.Together(api_key=api_key)
|
|
116
118
|
|
|
117
|
-
return client.fine_tuning.list_events(id=fine_tune_id).model_dump(
|
|
119
|
+
return client.fine_tuning.list_events(id=fine_tune_id).model_dump(
|
|
120
|
+
exclude_none=True
|
|
121
|
+
)
|
|
118
122
|
|
|
119
123
|
@classmethod
|
|
120
124
|
@deprecated # type: ignore
|
|
@@ -170,4 +174,4 @@ class Finetune:
|
|
|
170
174
|
|
|
171
175
|
return client.fine_tuning.download(
|
|
172
176
|
id=fine_tune_id, output=output, checkpoint_step=step
|
|
173
|
-
).model_dump()
|
|
177
|
+
).model_dump(exclude_none=True)
|
together/legacy/images.py
CHANGED
together/legacy/models.py
CHANGED
|
@@ -20,7 +20,7 @@ class Models:
|
|
|
20
20
|
|
|
21
21
|
client = together.Together(api_key=api_key)
|
|
22
22
|
|
|
23
|
-
return [item.model_dump() for item in client.models.list()]
|
|
23
|
+
return [item.model_dump(exclude_none=True) for item in client.models.list()]
|
|
24
24
|
|
|
25
25
|
@classmethod
|
|
26
26
|
@deprecated # type: ignore
|
|
@@ -41,4 +41,4 @@ class Models:
|
|
|
41
41
|
|
|
42
42
|
for item in model_list:
|
|
43
43
|
if item.id == model:
|
|
44
|
-
return item.model_dump()
|
|
44
|
+
return item.model_dump(exclude_none=True)
|
|
@@ -131,7 +131,7 @@ class ChatCompletions:
|
|
|
131
131
|
response_format=response_format,
|
|
132
132
|
tools=tools,
|
|
133
133
|
tool_choice=tool_choice,
|
|
134
|
-
).model_dump()
|
|
134
|
+
).model_dump(exclude_none=True)
|
|
135
135
|
|
|
136
136
|
response, _, _ = requestor.request(
|
|
137
137
|
options=TogetherRequest(
|
|
@@ -268,7 +268,7 @@ class AsyncChatCompletions:
|
|
|
268
268
|
response_format=response_format,
|
|
269
269
|
tools=tools,
|
|
270
270
|
tool_choice=tool_choice,
|
|
271
|
-
).model_dump()
|
|
271
|
+
).model_dump(exclude_none=True)
|
|
272
272
|
|
|
273
273
|
response, _, _ = await requestor.arequest(
|
|
274
274
|
options=TogetherRequest(
|
|
@@ -113,7 +113,7 @@ class Completions:
|
|
|
113
113
|
echo=echo,
|
|
114
114
|
n=n,
|
|
115
115
|
safety_model=safety_model,
|
|
116
|
-
).model_dump()
|
|
116
|
+
).model_dump(exclude_none=True)
|
|
117
117
|
|
|
118
118
|
response, _, _ = requestor.request(
|
|
119
119
|
options=TogetherRequest(
|
|
@@ -232,7 +232,7 @@ class AsyncCompletions:
|
|
|
232
232
|
echo=echo,
|
|
233
233
|
n=n,
|
|
234
234
|
safety_model=safety_model,
|
|
235
|
-
).model_dump()
|
|
235
|
+
).model_dump(exclude_none=True)
|
|
236
236
|
|
|
237
237
|
response, _, _ = await requestor.arequest(
|
|
238
238
|
options=TogetherRequest(
|
together/resources/embeddings.py
CHANGED
|
@@ -40,7 +40,7 @@ class Embeddings:
|
|
|
40
40
|
parameter_payload = EmbeddingRequest(
|
|
41
41
|
input=input,
|
|
42
42
|
model=model,
|
|
43
|
-
).model_dump()
|
|
43
|
+
).model_dump(exclude_none=True)
|
|
44
44
|
|
|
45
45
|
response, _, _ = requestor.request(
|
|
46
46
|
options=TogetherRequest(
|
|
@@ -84,7 +84,7 @@ class AsyncEmbeddings:
|
|
|
84
84
|
parameter_payload = EmbeddingRequest(
|
|
85
85
|
input=input,
|
|
86
86
|
model=model,
|
|
87
|
-
).model_dump()
|
|
87
|
+
).model_dump(exclude_none=True)
|
|
88
88
|
|
|
89
89
|
response, _, _ = await requestor.arequest(
|
|
90
90
|
options=TogetherRequest(
|
together/resources/finetune.py
CHANGED
|
@@ -11,8 +11,11 @@ from together.types import (
|
|
|
11
11
|
FinetuneListEvents,
|
|
12
12
|
FinetuneRequest,
|
|
13
13
|
FinetuneResponse,
|
|
14
|
+
FullTrainingType,
|
|
15
|
+
LoRATrainingType,
|
|
14
16
|
TogetherClient,
|
|
15
17
|
TogetherRequest,
|
|
18
|
+
TrainingType,
|
|
16
19
|
)
|
|
17
20
|
from together.utils import normalize_key
|
|
18
21
|
|
|
@@ -30,6 +33,11 @@ class FineTuning:
|
|
|
30
33
|
n_checkpoints: int | None = 1,
|
|
31
34
|
batch_size: int | None = 32,
|
|
32
35
|
learning_rate: float | None = 0.00001,
|
|
36
|
+
lora: bool = True,
|
|
37
|
+
lora_r: int | None = 8,
|
|
38
|
+
lora_dropout: float | None = 0,
|
|
39
|
+
lora_alpha: float | None = 8,
|
|
40
|
+
lora_trainable_modules: str | None = "all-linear",
|
|
33
41
|
suffix: str | None = None,
|
|
34
42
|
wandb_api_key: str | None = None,
|
|
35
43
|
) -> FinetuneResponse:
|
|
@@ -45,6 +53,11 @@ class FineTuning:
|
|
|
45
53
|
batch_size (int, optional): Batch size for fine-tuning. Defaults to 32.
|
|
46
54
|
learning_rate (float, optional): Learning rate multiplier to use for training
|
|
47
55
|
Defaults to 0.00001.
|
|
56
|
+
lora (bool, optional): Whether to use LoRA adapters. Defaults to True.
|
|
57
|
+
lora_r (int, optional): Rank of LoRA adapters. Defaults to 8.
|
|
58
|
+
lora_dropout (float, optional): Dropout rate for LoRA adapters. Defaults to 0.
|
|
59
|
+
lora_alpha (float, optional): Alpha for LoRA adapters. Defaults to 8.
|
|
60
|
+
lora_trainable_modules (str, optional): Trainable modules for LoRA adapters. Defaults to "all-linear".
|
|
48
61
|
suffix (str, optional): Up to 40 character suffix that will be added to your fine-tuned model name.
|
|
49
62
|
Defaults to None.
|
|
50
63
|
wandb_api_key (str, optional): API key for Weights & Biases integration.
|
|
@@ -58,6 +71,15 @@ class FineTuning:
|
|
|
58
71
|
client=self._client,
|
|
59
72
|
)
|
|
60
73
|
|
|
74
|
+
training_type: TrainingType = FullTrainingType()
|
|
75
|
+
if lora:
|
|
76
|
+
training_type = LoRATrainingType(
|
|
77
|
+
lora_r=lora_r,
|
|
78
|
+
lora_alpha=lora_alpha,
|
|
79
|
+
lora_dropout=lora_dropout,
|
|
80
|
+
lora_trainable_modules=lora_trainable_modules,
|
|
81
|
+
)
|
|
82
|
+
|
|
61
83
|
parameter_payload = FinetuneRequest(
|
|
62
84
|
model=model,
|
|
63
85
|
training_file=training_file,
|
|
@@ -65,9 +87,10 @@ class FineTuning:
|
|
|
65
87
|
n_checkpoints=n_checkpoints,
|
|
66
88
|
batch_size=batch_size,
|
|
67
89
|
learning_rate=learning_rate,
|
|
90
|
+
training_type=training_type,
|
|
68
91
|
suffix=suffix,
|
|
69
92
|
wandb_key=wandb_api_key,
|
|
70
|
-
).model_dump()
|
|
93
|
+
).model_dump(exclude_none=True)
|
|
71
94
|
|
|
72
95
|
response, _, _ = requestor.request(
|
|
73
96
|
options=TogetherRequest(
|
|
@@ -281,7 +304,7 @@ class AsyncFineTuning:
|
|
|
281
304
|
learning_rate=learning_rate,
|
|
282
305
|
suffix=suffix,
|
|
283
306
|
wandb_key=wandb_api_key,
|
|
284
|
-
).model_dump()
|
|
307
|
+
).model_dump(exclude_none=True)
|
|
285
308
|
|
|
286
309
|
response, _, _ = await requestor.arequest(
|
|
287
310
|
options=TogetherRequest(
|
together/resources/images.py
CHANGED
|
@@ -67,7 +67,7 @@ class Images:
|
|
|
67
67
|
height=height,
|
|
68
68
|
width=width,
|
|
69
69
|
negative_prompt=negative_prompt,
|
|
70
|
-
).model_dump()
|
|
70
|
+
).model_dump(exclude_none=True)
|
|
71
71
|
|
|
72
72
|
response, _, _ = requestor.request(
|
|
73
73
|
options=TogetherRequest(
|
|
@@ -140,7 +140,7 @@ class AsyncImages:
|
|
|
140
140
|
height=height,
|
|
141
141
|
width=width,
|
|
142
142
|
negative_prompt=negative_prompt,
|
|
143
|
-
).model_dump()
|
|
143
|
+
).model_dump(exclude_none=True)
|
|
144
144
|
|
|
145
145
|
response, _, _ = await requestor.arequest(
|
|
146
146
|
options=TogetherRequest(
|
together/types/__init__.py
CHANGED
|
@@ -26,6 +26,9 @@ from together.types.finetune import (
|
|
|
26
26
|
FinetuneListEvents,
|
|
27
27
|
FinetuneRequest,
|
|
28
28
|
FinetuneResponse,
|
|
29
|
+
FullTrainingType,
|
|
30
|
+
LoRATrainingType,
|
|
31
|
+
TrainingType,
|
|
29
32
|
)
|
|
30
33
|
from together.types.images import (
|
|
31
34
|
ImageRequest,
|
|
@@ -60,4 +63,7 @@ __all__ = [
|
|
|
60
63
|
"ImageRequest",
|
|
61
64
|
"ImageResponse",
|
|
62
65
|
"ModelObject",
|
|
66
|
+
"TrainingType",
|
|
67
|
+
"FullTrainingType",
|
|
68
|
+
"LoRATrainingType",
|
|
63
69
|
]
|
|
@@ -4,7 +4,7 @@ import warnings
|
|
|
4
4
|
from enum import Enum
|
|
5
5
|
from typing import Any, Dict, List
|
|
6
6
|
|
|
7
|
-
from pydantic import
|
|
7
|
+
from pydantic import model_validator
|
|
8
8
|
from typing_extensions import Self
|
|
9
9
|
|
|
10
10
|
from together.types.abstract import BaseModel
|
|
@@ -48,7 +48,10 @@ class ChatCompletionMessage(BaseModel):
|
|
|
48
48
|
|
|
49
49
|
class ResponseFormat(BaseModel):
|
|
50
50
|
type: ResponseFormatType
|
|
51
|
-
schema_: Dict[str, Any] | None =
|
|
51
|
+
schema_: Dict[str, Any] | None = None
|
|
52
|
+
|
|
53
|
+
def to_dict(self) -> Dict[str, Any]:
|
|
54
|
+
return {"schema": self.schema_, "type": self.type}
|
|
52
55
|
|
|
53
56
|
|
|
54
57
|
class FunctionTool(BaseModel):
|
together/types/finetune.py
CHANGED
|
@@ -100,6 +100,34 @@ class FinetuneEvent(BaseModel):
|
|
|
100
100
|
hash: str | None = None
|
|
101
101
|
|
|
102
102
|
|
|
103
|
+
class TrainingType(BaseModel):
|
|
104
|
+
"""
|
|
105
|
+
Abstract training type
|
|
106
|
+
"""
|
|
107
|
+
|
|
108
|
+
type: str
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
class FullTrainingType(TrainingType):
|
|
112
|
+
"""
|
|
113
|
+
Training type for full fine-tuning
|
|
114
|
+
"""
|
|
115
|
+
|
|
116
|
+
type: str = "Full"
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
class LoRATrainingType(TrainingType):
|
|
120
|
+
"""
|
|
121
|
+
Training type for LoRA adapters training
|
|
122
|
+
"""
|
|
123
|
+
|
|
124
|
+
lora_r: int
|
|
125
|
+
lora_alpha: int
|
|
126
|
+
lora_dropout: float
|
|
127
|
+
lora_trainable_modules: str
|
|
128
|
+
type: str = "Lora"
|
|
129
|
+
|
|
130
|
+
|
|
103
131
|
class FinetuneRequest(BaseModel):
|
|
104
132
|
"""
|
|
105
133
|
Fine-tune request type
|
|
@@ -121,6 +149,7 @@ class FinetuneRequest(BaseModel):
|
|
|
121
149
|
suffix: str | None = None
|
|
122
150
|
# weights & biases api key
|
|
123
151
|
wandb_key: str | None = None
|
|
152
|
+
training_type: FullTrainingType | LoRATrainingType | None = None
|
|
124
153
|
|
|
125
154
|
|
|
126
155
|
class FinetuneResponse(BaseModel):
|
|
@@ -138,6 +167,8 @@ class FinetuneResponse(BaseModel):
|
|
|
138
167
|
model: str | None = None
|
|
139
168
|
# output model name
|
|
140
169
|
output_name: str | None = Field(None, alias="model_output_name")
|
|
170
|
+
# adapter output name
|
|
171
|
+
adapter_output_name: str | None = None
|
|
141
172
|
# number of epochs
|
|
142
173
|
n_epochs: int | None = None
|
|
143
174
|
# number of checkpoints to save
|
|
@@ -148,11 +179,8 @@ class FinetuneResponse(BaseModel):
|
|
|
148
179
|
learning_rate: float | None = None
|
|
149
180
|
# number of steps between evals
|
|
150
181
|
eval_steps: int | None = None
|
|
151
|
-
#
|
|
152
|
-
|
|
153
|
-
lora_r: int | None = None
|
|
154
|
-
lora_alpha: int | None = None
|
|
155
|
-
lora_dropout: int | None = None
|
|
182
|
+
# training type
|
|
183
|
+
training_type: FullTrainingType | LoRATrainingType | None = None
|
|
156
184
|
# created/updated datetime stamps
|
|
157
185
|
created_at: str | None = None
|
|
158
186
|
updated_at: str | None = None
|
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
together/__init__.py,sha256=
|
|
2
|
-
together/abstract/__init__.py,sha256=
|
|
1
|
+
together/__init__.py,sha256=B8T7ybZ7D6jJNRTuFDVjOFlImCNag8tNZXpZdXz7xNM,1530
|
|
2
|
+
together/abstract/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
3
|
together/abstract/api_requestor.py,sha256=8fuAJHIZFLfzItaeSqRgsqSD6KnAvF1J_SrwKkfkHTg,25103
|
|
4
4
|
together/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
5
|
together/cli/api/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
|
-
together/cli/api/chat.py,sha256=
|
|
7
|
-
together/cli/api/completions.py,sha256=
|
|
8
|
-
together/cli/api/files.py,sha256=
|
|
9
|
-
together/cli/api/finetune.py,sha256=
|
|
6
|
+
together/cli/api/chat.py,sha256=2PHRb-9T-lUEKhUJFtc7SxJv3shCVx40gq_8pzfsewM,9234
|
|
7
|
+
together/cli/api/completions.py,sha256=l-Zw5t7hojL3w8xd_mitS2NRB72i5Z0xwkzH0rT5XMc,4263
|
|
8
|
+
together/cli/api/files.py,sha256=QLYEXRkY8J2Gg1SbTCtzGfoTMvosoeACNK83L_oLubs,3397
|
|
9
|
+
together/cli/api/finetune.py,sha256=hRIZj-p7vTsvl35pCBRTFpumzEVQbK1CMpVruW2bxJM,7157
|
|
10
10
|
together/cli/api/images.py,sha256=01dFYa2sK1HqUwVCD9FlwcjqkYWLoNxFZkzok13EriE,2363
|
|
11
11
|
together/cli/api/models.py,sha256=xWEzu8ZpxM_Pz9KEjRPRVuv_v22RayYZ4QcgiezT5tE,1126
|
|
12
12
|
together/cli/cli.py,sha256=RC0tgapkSOFjsRPg8p-8dx9D2LDzm8YmVCHUjk_aVyQ,1977
|
|
13
13
|
together/client.py,sha256=7QT5lwn7-QGf0vtgbhslQujm4986CgfE2spyMYP4JyU,4774
|
|
14
14
|
together/constants.py,sha256=WHe6JA9TliwgErkCnovWPS9w9xXfA3X5PtKJv_y2JxQ,908
|
|
15
|
-
together/error.py,sha256=
|
|
15
|
+
together/error.py,sha256=emjhTSsLwiZvW0v1EmYemjacCMtcFIKAXWWK_2IdP18,5419
|
|
16
16
|
together/filemanager.py,sha256=QHhBn73oVFdgUpSYXYLmJzHJ9c5wYEMJC0ur6ZgDeYo,11269
|
|
17
17
|
together/legacy/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
18
18
|
together/legacy/base.py,sha256=ehrX1SCfRbK5OA83wL1q7-tfF-yuZOUxzjxYfFtdvvQ,727
|
|
19
|
-
together/legacy/complete.py,sha256=
|
|
20
|
-
together/legacy/embeddings.py,sha256=
|
|
21
|
-
together/legacy/files.py,sha256=
|
|
22
|
-
together/legacy/finetune.py,sha256=
|
|
23
|
-
together/legacy/images.py,sha256=
|
|
24
|
-
together/legacy/models.py,sha256=
|
|
19
|
+
together/legacy/complete.py,sha256=2W4OoXc9cX6G2ZfoQJRg8RUgisYd42x8Y9U5bL0xL70,2419
|
|
20
|
+
together/legacy/embeddings.py,sha256=SSQJlgMlCRgXomlhpOTJktLqZEVPncsl1cMN67Jxeeg,630
|
|
21
|
+
together/legacy/files.py,sha256=qmAqMiNTPWb6WvLV5Tsv6kxGRfQ31q7OkHZNFwkw8v0,4082
|
|
22
|
+
together/legacy/finetune.py,sha256=k-lERbZLEZlW1QQ9A9zhhwl5KIPjf_jT0R0LSiLbD2Y,5063
|
|
23
|
+
together/legacy/images.py,sha256=fWp5xdmRBENgy9UClG43gEO8XMRdh6c-Psj-VE-Kz_E,621
|
|
24
|
+
together/legacy/models.py,sha256=85ZN9Ids_FjdYNDRv5k7sgrtVWPKPHqkDplORtVUGHg,1087
|
|
25
25
|
together/resources/__init__.py,sha256=lqALaYtprhTzvHFP5xFuEjm-ooDJtCioDKEbboXaCE4,701
|
|
26
26
|
together/resources/chat/__init__.py,sha256=RsTptdP8MeGjcdIjze896-J27cRvCbUoMft0X2BVlQ8,617
|
|
27
|
-
together/resources/chat/completions.py,sha256=
|
|
28
|
-
together/resources/completions.py,sha256=
|
|
29
|
-
together/resources/embeddings.py,sha256=
|
|
27
|
+
together/resources/chat/completions.py,sha256=BFeApiCRSTzy3FXiRudWVhN-dOodC4MMYoM3gdpfURU,14118
|
|
28
|
+
together/resources/completions.py,sha256=ouv9_jCsVT-vz49i77T053v35LL9iWhUXT7awa_gH5o,11387
|
|
29
|
+
together/resources/embeddings.py,sha256=AddhcJTS7cjhCpW6v8B2mOLoHugeo3AxL9AGrBEKe8o,2580
|
|
30
30
|
together/resources/files.py,sha256=bnPbaF25e4InBRPvHwXHXT-oSX1Z1sZRsnQW5wq82U4,4990
|
|
31
|
-
together/resources/finetune.py,sha256=
|
|
32
|
-
together/resources/images.py,sha256=
|
|
31
|
+
together/resources/finetune.py,sha256=MUHOpvQLIa0tAy7XKhfdyaugZ4AhjSpeLCreRAQSnJU,13505
|
|
32
|
+
together/resources/images.py,sha256=ALTxJyrUHkGnPzfm7R_nySF0fhUwPjrcyg1j3hzZ_WY,4809
|
|
33
33
|
together/resources/models.py,sha256=2dtHhXAqTDOOpwSbYLzWcKTC0-m2Szlb7LDYvp7Jr4w,1786
|
|
34
34
|
together/together_response.py,sha256=MhczUCPem93cjX-A1TOAUrRj3sO-o3SLcEcTsZgVzQI,1319
|
|
35
|
-
together/types/__init__.py,sha256=
|
|
35
|
+
together/types/__init__.py,sha256=QeDcuLgW1lowGijdwEZXCibaBIb9k0YKG581TlXwzd4,1562
|
|
36
36
|
together/types/abstract.py,sha256=1lFQI_3WjsR_t1128AeKW0aTk6EiM6Gh1J3ZuyLLPao,642
|
|
37
|
-
together/types/chat_completions.py,sha256=
|
|
37
|
+
together/types/chat_completions.py,sha256=wy_2E2moA2Aw1RVRXG7bLcHqkSULv-MlJZygajbQN_8,4406
|
|
38
38
|
together/types/common.py,sha256=4ZeIgqGioqhIC-nNxY90czNPp-kAqboMulw6-1z6ShM,1511
|
|
39
39
|
together/types/completions.py,sha256=yydloTQePGaY97Lx-kbkvgCqBFhHFl7jU5s7uf9Ncg0,2901
|
|
40
40
|
together/types/embeddings.py,sha256=J7grkYYn7xhqeKaBO2T-8XQRtHhkzYzymovtGdIUK5A,751
|
|
41
41
|
together/types/error.py,sha256=OVlCs3cx_2WhZK4JzHT8SQyRIIqKOP1AZQ4y1PydjAE,370
|
|
42
42
|
together/types/files.py,sha256=-rEUfsV6f2vZB9NrFxT4_933ubsDIUNkPB-3OlOFk4A,1954
|
|
43
|
-
together/types/finetune.py,sha256=
|
|
43
|
+
together/types/finetune.py,sha256=qApCHFPKmXuA4rOnW1qh3IK165gCKe5Kr-usn8ZOXLg,6344
|
|
44
44
|
together/types/images.py,sha256=zX4Vt38tFDKU6yGb_hBY_N5eSTn3KPdpP5Ce_qnRHXQ,915
|
|
45
45
|
together/types/models.py,sha256=3zag9x2fus2McNmLkr3fKzQL-2RNIT1-tiabI-z21p8,1013
|
|
46
46
|
together/utils/__init__.py,sha256=VpjeRTya1m5eEE-Qe1zYTFsNAvuEA-dy7M2eG9Xu4fc,662
|
|
@@ -49,8 +49,8 @@ together/utils/api_helpers.py,sha256=RSF7SRhbjHzroMOSWAXscflByM1r1ta_1SpxkAT22iE
|
|
|
49
49
|
together/utils/files.py,sha256=gMLthqfP5hKxVAerHMdy7gLXzdfY6lyOXdpW24Y4X3I,7165
|
|
50
50
|
together/utils/tools.py,sha256=3-lXWP3cBCzOVSZg9tr5zOT1jaVeKAKVWxO2fcXZTh8,1788
|
|
51
51
|
together/version.py,sha256=p03ivHyE0SyWU4jAnRTBi_sOwywVWoZPU4g2gzRgG-Y,126
|
|
52
|
-
together-1.2.
|
|
53
|
-
together-1.2.
|
|
54
|
-
together-1.2.
|
|
55
|
-
together-1.2.
|
|
56
|
-
together-1.2.
|
|
52
|
+
together-1.2.4.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
53
|
+
together-1.2.4.dist-info/METADATA,sha256=eh2uGO8KHretuiGKie4a_JS2lNy_g82tSsN7faHyuwY,11812
|
|
54
|
+
together-1.2.4.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
|
55
|
+
together-1.2.4.dist-info/entry_points.txt,sha256=G-b5NKW6lUUf1V1fH8IPTBb7jXnK7lhbX9H1zTEJXPs,50
|
|
56
|
+
together-1.2.4.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|