together 1.2.2__py3-none-any.whl → 1.2.3__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.
@@ -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=3e-5, help="Learning rate")
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,6 +88,11 @@ 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
  )
@@ -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,6 +87,7 @@ 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
93
  ).model_dump()
@@ -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
  ]
@@ -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
- # is LoRA finetune boolean
152
- lora: bool | None = None
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,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: together
3
- Version: 1.2.2
3
+ Version: 1.2.3
4
4
  Summary: Python client for Together's Cloud Platform!
5
5
  Home-page: https://github.com/togethercomputer/together-python
6
6
  License: Apache-2.0
@@ -6,7 +6,7 @@ together/cli/api/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,
6
6
  together/cli/api/chat.py,sha256=qmDcYohGe1ODfvYEDN6Z2eZO3qODgmeUTll8P5qoKYQ,9170
7
7
  together/cli/api/completions.py,sha256=v6KvGsXnPCdSM7WIu_QmKXOA4iVjW93k3dLwfIBkxPQ,4199
8
8
  together/cli/api/files.py,sha256=hOiN1ftwbSAs3gcVqwmPymhmzDYiIUrFWXFHVcWWom8,3329
9
- together/cli/api/finetune.py,sha256=mSQSasmVQLtNzjJLeoEEwvewfEcpSkjKyozWqwb-7p0,5417
9
+ together/cli/api/finetune.py,sha256=xg9yb1GEvtxj7RR6g2A4Mn9gM6M9Oeb0Tp-8EF8DSc0,7089
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
@@ -28,11 +28,11 @@ together/resources/chat/completions.py,sha256=QGrg0fGsn16k6jpxbQGoIBRivHWgEimPWA
28
28
  together/resources/completions.py,sha256=5s-jly2vbpI1rWhFwVijCmCOyhEZuDuwJblrm3HD0Gs,11353
29
29
  together/resources/embeddings.py,sha256=yRG0JaF4u_MEynQ4TBgCOVf9bKSvGI1fRaQx3CHUiB0,2546
30
30
  together/resources/files.py,sha256=bnPbaF25e4InBRPvHwXHXT-oSX1Z1sZRsnQW5wq82U4,4990
31
- together/resources/finetune.py,sha256=DcA0A3I9khS8nMv2KpVNjDVI92knnI2o-O_93Z8gP-U,12416
31
+ together/resources/finetune.py,sha256=-MU25J2gHSFQnBIPg4XDle5cgfrkOnQtK9_T_hJqRy8,13471
32
32
  together/resources/images.py,sha256=gFzXy7gLzr20KsXJXHEsOZtJJpuR6pH1d8XHCd6Dl9E,4775
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=K7Gv6hLmobIfqfmijZbZwFrwxK_YKIDR_v94_ElFmVA,1432
35
+ together/types/__init__.py,sha256=QeDcuLgW1lowGijdwEZXCibaBIb9k0YKG581TlXwzd4,1562
36
36
  together/types/abstract.py,sha256=1lFQI_3WjsR_t1128AeKW0aTk6EiM6Gh1J3ZuyLLPao,642
37
37
  together/types/chat_completions.py,sha256=VxuvcHM9IQVWfD1qKu6gDWdrV5UainjkV3pGm_4Oiyo,4335
38
38
  together/types/common.py,sha256=4ZeIgqGioqhIC-nNxY90czNPp-kAqboMulw6-1z6ShM,1511
@@ -40,7 +40,7 @@ together/types/completions.py,sha256=yydloTQePGaY97Lx-kbkvgCqBFhHFl7jU5s7uf9Ncg0
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=eK2Zv47ccvbenGv87PmNCBsqPQleiA3KxoK7KjsuYTM,5850
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.2.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
53
- together-1.2.2.dist-info/METADATA,sha256=S9B78Nc5Ge6nBVMfLDFCK9qTQPrmhXMo4BbxCyYSsoo,11812
54
- together-1.2.2.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
55
- together-1.2.2.dist-info/entry_points.txt,sha256=G-b5NKW6lUUf1V1fH8IPTBb7jXnK7lhbX9H1zTEJXPs,50
56
- together-1.2.2.dist-info/RECORD,,
52
+ together-1.2.3.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
53
+ together-1.2.3.dist-info/METADATA,sha256=BdqQEU6vpCarSDazFhrqWoaZqBkz8tfTN7iH8HPjZH4,11812
54
+ together-1.2.3.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
55
+ together-1.2.3.dist-info/entry_points.txt,sha256=G-b5NKW6lUUf1V1fH8IPTBb7jXnK7lhbX9H1zTEJXPs,50
56
+ together-1.2.3.dist-info/RECORD,,