together 1.3.1__tar.gz → 1.3.3__tar.gz

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 (59) hide show
  1. {together-1.3.1 → together-1.3.3}/PKG-INFO +2 -2
  2. {together-1.3.1 → together-1.3.3}/README.md +0 -1
  3. {together-1.3.1 → together-1.3.3}/pyproject.toml +1 -1
  4. {together-1.3.1 → together-1.3.3}/src/together/abstract/api_requestor.py +1 -1
  5. {together-1.3.1 → together-1.3.3}/src/together/cli/api/finetune.py +9 -0
  6. together-1.3.3/src/together/cli/api/utils.py +30 -0
  7. {together-1.3.1 → together-1.3.3}/src/together/resources/finetune.py +133 -53
  8. {together-1.3.1 → together-1.3.3}/src/together/types/finetune.py +4 -0
  9. together-1.3.1/src/together/cli/api/utils.py +0 -21
  10. {together-1.3.1 → together-1.3.3}/LICENSE +0 -0
  11. {together-1.3.1 → together-1.3.3}/src/together/__init__.py +0 -0
  12. {together-1.3.1 → together-1.3.3}/src/together/abstract/__init__.py +0 -0
  13. {together-1.3.1 → together-1.3.3}/src/together/cli/__init__.py +0 -0
  14. {together-1.3.1 → together-1.3.3}/src/together/cli/api/__init__.py +0 -0
  15. {together-1.3.1 → together-1.3.3}/src/together/cli/api/chat.py +0 -0
  16. {together-1.3.1 → together-1.3.3}/src/together/cli/api/completions.py +0 -0
  17. {together-1.3.1 → together-1.3.3}/src/together/cli/api/files.py +0 -0
  18. {together-1.3.1 → together-1.3.3}/src/together/cli/api/images.py +0 -0
  19. {together-1.3.1 → together-1.3.3}/src/together/cli/api/models.py +0 -0
  20. {together-1.3.1 → together-1.3.3}/src/together/cli/cli.py +0 -0
  21. {together-1.3.1 → together-1.3.3}/src/together/client.py +0 -0
  22. {together-1.3.1 → together-1.3.3}/src/together/constants.py +0 -0
  23. {together-1.3.1 → together-1.3.3}/src/together/error.py +0 -0
  24. {together-1.3.1 → together-1.3.3}/src/together/filemanager.py +0 -0
  25. {together-1.3.1 → together-1.3.3}/src/together/legacy/__init__.py +0 -0
  26. {together-1.3.1 → together-1.3.3}/src/together/legacy/base.py +0 -0
  27. {together-1.3.1 → together-1.3.3}/src/together/legacy/complete.py +0 -0
  28. {together-1.3.1 → together-1.3.3}/src/together/legacy/embeddings.py +0 -0
  29. {together-1.3.1 → together-1.3.3}/src/together/legacy/files.py +0 -0
  30. {together-1.3.1 → together-1.3.3}/src/together/legacy/finetune.py +0 -0
  31. {together-1.3.1 → together-1.3.3}/src/together/legacy/images.py +0 -0
  32. {together-1.3.1 → together-1.3.3}/src/together/legacy/models.py +0 -0
  33. {together-1.3.1 → together-1.3.3}/src/together/resources/__init__.py +0 -0
  34. {together-1.3.1 → together-1.3.3}/src/together/resources/chat/__init__.py +0 -0
  35. {together-1.3.1 → together-1.3.3}/src/together/resources/chat/completions.py +0 -0
  36. {together-1.3.1 → together-1.3.3}/src/together/resources/completions.py +0 -0
  37. {together-1.3.1 → together-1.3.3}/src/together/resources/embeddings.py +0 -0
  38. {together-1.3.1 → together-1.3.3}/src/together/resources/files.py +0 -0
  39. {together-1.3.1 → together-1.3.3}/src/together/resources/images.py +0 -0
  40. {together-1.3.1 → together-1.3.3}/src/together/resources/models.py +0 -0
  41. {together-1.3.1 → together-1.3.3}/src/together/resources/rerank.py +0 -0
  42. {together-1.3.1 → together-1.3.3}/src/together/together_response.py +0 -0
  43. {together-1.3.1 → together-1.3.3}/src/together/types/__init__.py +0 -0
  44. {together-1.3.1 → together-1.3.3}/src/together/types/abstract.py +0 -0
  45. {together-1.3.1 → together-1.3.3}/src/together/types/chat_completions.py +0 -0
  46. {together-1.3.1 → together-1.3.3}/src/together/types/common.py +0 -0
  47. {together-1.3.1 → together-1.3.3}/src/together/types/completions.py +0 -0
  48. {together-1.3.1 → together-1.3.3}/src/together/types/embeddings.py +0 -0
  49. {together-1.3.1 → together-1.3.3}/src/together/types/error.py +0 -0
  50. {together-1.3.1 → together-1.3.3}/src/together/types/files.py +0 -0
  51. {together-1.3.1 → together-1.3.3}/src/together/types/images.py +0 -0
  52. {together-1.3.1 → together-1.3.3}/src/together/types/models.py +0 -0
  53. {together-1.3.1 → together-1.3.3}/src/together/types/rerank.py +0 -0
  54. {together-1.3.1 → together-1.3.3}/src/together/utils/__init__.py +0 -0
  55. {together-1.3.1 → together-1.3.3}/src/together/utils/_log.py +0 -0
  56. {together-1.3.1 → together-1.3.3}/src/together/utils/api_helpers.py +0 -0
  57. {together-1.3.1 → together-1.3.3}/src/together/utils/files.py +0 -0
  58. {together-1.3.1 → together-1.3.3}/src/together/utils/tools.py +0 -0
  59. {together-1.3.1 → together-1.3.3}/src/together/version.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: together
3
- Version: 1.3.1
3
+ Version: 1.3.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
@@ -15,6 +15,7 @@ Classifier: Programming Language :: Python :: 3.9
15
15
  Classifier: Programming Language :: Python :: 3.10
16
16
  Classifier: Programming Language :: Python :: 3.11
17
17
  Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
18
19
  Requires-Dist: aiohttp (>=3.9.3,<4.0.0)
19
20
  Requires-Dist: click (>=8.1.7,<9.0.0)
20
21
  Requires-Dist: eval-type-backport (>=0.1.3,<0.3.0)
@@ -193,7 +194,6 @@ prompts = [
193
194
  ]
194
195
 
195
196
  async def async_chat_completion(prompts):
196
- async_client = AsyncTogether(api_key=os.environ.get("TOGETHER_API_KEY"))
197
197
  tasks = [
198
198
  async_client.completions.create(
199
199
  model="codellama/CodeLlama-34b-Python-hf",
@@ -158,7 +158,6 @@ prompts = [
158
158
  ]
159
159
 
160
160
  async def async_chat_completion(prompts):
161
- async_client = AsyncTogether(api_key=os.environ.get("TOGETHER_API_KEY"))
162
161
  tasks = [
163
162
  async_client.completions.create(
164
163
  model="codellama/CodeLlama-34b-Python-hf",
@@ -12,7 +12,7 @@ build-backend = "poetry.masonry.api"
12
12
 
13
13
  [tool.poetry]
14
14
  name = "together"
15
- version = "1.3.1"
15
+ version = "1.3.3"
16
16
  authors = [
17
17
  "Together AI <support@together.ai>"
18
18
  ]
@@ -366,7 +366,7 @@ class APIRequestor:
366
366
  headers=resp._headers,
367
367
  request_id=resp.request_id,
368
368
  )
369
- elif rcode in [400, 403, 404, 415]:
369
+ elif rcode in [400, 403, 404, 415, 422]:
370
370
  return error.InvalidRequestError(
371
371
  error_data,
372
372
  http_status=rcode,
@@ -60,6 +60,12 @@ def fine_tuning(ctx: click.Context) -> None:
60
60
  )
61
61
  @click.option("--batch-size", type=INT_WITH_MAX, default="max", help="Train batch size")
62
62
  @click.option("--learning-rate", type=float, default=1e-5, help="Learning rate")
63
+ @click.option(
64
+ "--warmup-ratio",
65
+ type=float,
66
+ default=0.0,
67
+ help="Warmup ratio for learning rate scheduler.",
68
+ )
63
69
  @click.option(
64
70
  "--lora/--no-lora",
65
71
  type=bool,
@@ -97,6 +103,7 @@ def create(
97
103
  n_checkpoints: int,
98
104
  batch_size: int | Literal["max"],
99
105
  learning_rate: float,
106
+ warmup_ratio: float,
100
107
  lora: bool,
101
108
  lora_r: int,
102
109
  lora_dropout: float,
@@ -118,6 +125,7 @@ def create(
118
125
  n_checkpoints=n_checkpoints,
119
126
  batch_size=batch_size,
120
127
  learning_rate=learning_rate,
128
+ warmup_ratio=warmup_ratio,
121
129
  lora=lora,
122
130
  lora_r=lora_r,
123
131
  lora_dropout=lora_dropout,
@@ -186,6 +194,7 @@ def create(
186
194
  n_checkpoints=n_checkpoints,
187
195
  batch_size=batch_size,
188
196
  learning_rate=learning_rate,
197
+ warmup_ratio=warmup_ratio,
189
198
  lora=lora,
190
199
  lora_r=lora_r,
191
200
  lora_dropout=lora_dropout,
@@ -0,0 +1,30 @@
1
+ from __future__ import annotations
2
+
3
+ from gettext import gettext as _
4
+ from typing import Literal
5
+
6
+ import click
7
+
8
+
9
+ class AutoIntParamType(click.ParamType):
10
+ name = "integer_or_max"
11
+ _number_class = int
12
+
13
+ def convert(
14
+ self, value: str, param: click.Parameter | None, ctx: click.Context | None
15
+ ) -> int | Literal["max"] | None:
16
+ if value == "max":
17
+ return "max"
18
+ try:
19
+ return int(value)
20
+ except ValueError:
21
+ self.fail(
22
+ _("{value!r} is not a valid {number_type}.").format(
23
+ value=value, number_type=self.name
24
+ ),
25
+ param,
26
+ ctx,
27
+ )
28
+
29
+
30
+ INT_WITH_MAX = AutoIntParamType()
@@ -25,6 +25,81 @@ from together.types.finetune import DownloadCheckpointType
25
25
  from together.utils import log_warn_once, normalize_key
26
26
 
27
27
 
28
+ def createFinetuneRequest(
29
+ model_limits: FinetuneTrainingLimits,
30
+ training_file: str,
31
+ model: str,
32
+ n_epochs: int = 1,
33
+ validation_file: str | None = "",
34
+ n_evals: int | None = 0,
35
+ n_checkpoints: int | None = 1,
36
+ batch_size: int | Literal["max"] = "max",
37
+ learning_rate: float | None = 0.00001,
38
+ warmup_ratio: float | None = 0.0,
39
+ lora: bool = False,
40
+ lora_r: int | None = None,
41
+ lora_dropout: float | None = 0,
42
+ lora_alpha: float | None = None,
43
+ lora_trainable_modules: str | None = "all-linear",
44
+ suffix: str | None = None,
45
+ wandb_api_key: str | None = None,
46
+ ) -> FinetuneRequest:
47
+ if batch_size == "max":
48
+ log_warn_once(
49
+ "Starting from together>=1.3.0, "
50
+ "the default batch size is set to the maximum allowed value for each model."
51
+ )
52
+ if warmup_ratio is None:
53
+ warmup_ratio = 0.0
54
+
55
+ training_type: TrainingType = FullTrainingType()
56
+ if lora:
57
+ if model_limits.lora_training is None:
58
+ raise ValueError("LoRA adapters are not supported for the selected model.")
59
+ lora_r = lora_r if lora_r is not None else model_limits.lora_training.max_rank
60
+ lora_alpha = lora_alpha if lora_alpha is not None else lora_r * 2
61
+ training_type = LoRATrainingType(
62
+ lora_r=lora_r,
63
+ lora_alpha=lora_alpha,
64
+ lora_dropout=lora_dropout,
65
+ lora_trainable_modules=lora_trainable_modules,
66
+ )
67
+
68
+ batch_size = (
69
+ batch_size
70
+ if batch_size != "max"
71
+ else model_limits.lora_training.max_batch_size
72
+ )
73
+ else:
74
+ if model_limits.full_training is None:
75
+ raise ValueError("Full training is not supported for the selected model.")
76
+ batch_size = (
77
+ batch_size
78
+ if batch_size != "max"
79
+ else model_limits.full_training.max_batch_size
80
+ )
81
+
82
+ if warmup_ratio > 1 or warmup_ratio < 0:
83
+ raise ValueError("Warmup ratio should be between 0 and 1")
84
+
85
+ finetune_request = FinetuneRequest(
86
+ model=model,
87
+ training_file=training_file,
88
+ validation_file=validation_file,
89
+ n_epochs=n_epochs,
90
+ n_evals=n_evals,
91
+ n_checkpoints=n_checkpoints,
92
+ batch_size=batch_size,
93
+ learning_rate=learning_rate,
94
+ warmup_ratio=warmup_ratio,
95
+ training_type=training_type,
96
+ suffix=suffix,
97
+ wandb_key=wandb_api_key,
98
+ )
99
+
100
+ return finetune_request
101
+
102
+
28
103
  class FineTuning:
29
104
  def __init__(self, client: TogetherClient) -> None:
30
105
  self._client = client
@@ -40,6 +115,7 @@ class FineTuning:
40
115
  n_checkpoints: int | None = 1,
41
116
  batch_size: int | Literal["max"] = "max",
42
117
  learning_rate: float | None = 0.00001,
118
+ warmup_ratio: float | None = 0.0,
43
119
  lora: bool = False,
44
120
  lora_r: int | None = None,
45
121
  lora_dropout: float | None = 0,
@@ -64,6 +140,7 @@ class FineTuning:
64
140
  batch_size (int, optional): Batch size for fine-tuning. Defaults to max.
65
141
  learning_rate (float, optional): Learning rate multiplier to use for training
66
142
  Defaults to 0.00001.
143
+ warmup_ratio (float, optional): Warmup ratio for learning rate scheduler.
67
144
  lora (bool, optional): Whether to use LoRA adapters. Defaults to True.
68
145
  lora_r (int, optional): Rank of LoRA adapters. Defaults to 8.
69
146
  lora_dropout (float, optional): Dropout rate for LoRA adapters. Defaults to 0.
@@ -82,12 +159,6 @@ class FineTuning:
82
159
  FinetuneResponse: Object containing information about fine-tuning job.
83
160
  """
84
161
 
85
- if batch_size == "max":
86
- log_warn_once(
87
- "Starting from together>=1.3.0, "
88
- "the default batch size is set to the maximum allowed value for each model."
89
- )
90
-
91
162
  requestor = api_requestor.APIRequestor(
92
163
  client=self._client,
93
164
  )
@@ -95,52 +166,26 @@ class FineTuning:
95
166
  if model_limits is None:
96
167
  model_limits = self.get_model_limits(model=model)
97
168
 
98
- training_type: TrainingType = FullTrainingType()
99
- if lora:
100
- if model_limits.lora_training is None:
101
- raise ValueError(
102
- "LoRA adapters are not supported for the selected model."
103
- )
104
- lora_r = (
105
- lora_r if lora_r is not None else model_limits.lora_training.max_rank
106
- )
107
- lora_alpha = lora_alpha if lora_alpha is not None else lora_r * 2
108
- training_type = LoRATrainingType(
109
- lora_r=lora_r,
110
- lora_alpha=lora_alpha,
111
- lora_dropout=lora_dropout,
112
- lora_trainable_modules=lora_trainable_modules,
113
- )
114
-
115
- batch_size = (
116
- batch_size
117
- if batch_size != "max"
118
- else model_limits.lora_training.max_batch_size
119
- )
120
- else:
121
- if model_limits.full_training is None:
122
- raise ValueError(
123
- "Full training is not supported for the selected model."
124
- )
125
- batch_size = (
126
- batch_size
127
- if batch_size != "max"
128
- else model_limits.full_training.max_batch_size
129
- )
130
-
131
- finetune_request = FinetuneRequest(
132
- model=model,
169
+ finetune_request = createFinetuneRequest(
170
+ model_limits=model_limits,
133
171
  training_file=training_file,
134
- validation_file=validation_file,
172
+ model=model,
135
173
  n_epochs=n_epochs,
174
+ validation_file=validation_file,
136
175
  n_evals=n_evals,
137
176
  n_checkpoints=n_checkpoints,
138
177
  batch_size=batch_size,
139
178
  learning_rate=learning_rate,
140
- training_type=training_type,
179
+ warmup_ratio=warmup_ratio,
180
+ lora=lora,
181
+ lora_r=lora_r,
182
+ lora_dropout=lora_dropout,
183
+ lora_alpha=lora_alpha,
184
+ lora_trainable_modules=lora_trainable_modules,
141
185
  suffix=suffix,
142
- wandb_key=wandb_api_key,
186
+ wandb_api_key=wandb_api_key,
143
187
  )
188
+
144
189
  if verbose:
145
190
  rprint(
146
191
  "Submitting a fine-tuning job with the following parameters:",
@@ -377,12 +422,20 @@ class AsyncFineTuning:
377
422
  model: str,
378
423
  n_epochs: int = 1,
379
424
  validation_file: str | None = "",
380
- n_evals: int = 0,
425
+ n_evals: int | None = 0,
381
426
  n_checkpoints: int | None = 1,
382
- batch_size: int | None = 32,
383
- learning_rate: float = 0.00001,
427
+ batch_size: int | Literal["max"] = "max",
428
+ learning_rate: float | None = 0.00001,
429
+ warmup_ratio: float | None = 0.0,
430
+ lora: bool = False,
431
+ lora_r: int | None = None,
432
+ lora_dropout: float | None = 0,
433
+ lora_alpha: float | None = None,
434
+ lora_trainable_modules: str | None = "all-linear",
384
435
  suffix: str | None = None,
385
436
  wandb_api_key: str | None = None,
437
+ verbose: bool = False,
438
+ model_limits: FinetuneTrainingLimits | None = None,
386
439
  ) -> FinetuneResponse:
387
440
  """
388
441
  Async method to initiate a fine-tuning job
@@ -395,13 +448,23 @@ class AsyncFineTuning:
395
448
  n_evals (int, optional): Number of evaluation loops to run. Defaults to 0.
396
449
  n_checkpoints (int, optional): Number of checkpoints to save during fine-tuning.
397
450
  Defaults to 1.
398
- batch_size (int, optional): Batch size for fine-tuning. Defaults to 32.
451
+ batch_size (int, optional): Batch size for fine-tuning. Defaults to max.
399
452
  learning_rate (float, optional): Learning rate multiplier to use for training
400
453
  Defaults to 0.00001.
454
+ warmup_ratio (float, optional): Warmup ratio for learning rate scheduler.
455
+ lora (bool, optional): Whether to use LoRA adapters. Defaults to True.
456
+ lora_r (int, optional): Rank of LoRA adapters. Defaults to 8.
457
+ lora_dropout (float, optional): Dropout rate for LoRA adapters. Defaults to 0.
458
+ lora_alpha (float, optional): Alpha for LoRA adapters. Defaults to 8.
459
+ lora_trainable_modules (str, optional): Trainable modules for LoRA adapters. Defaults to "all-linear".
401
460
  suffix (str, optional): Up to 40 character suffix that will be added to your fine-tuned model name.
402
461
  Defaults to None.
403
462
  wandb_api_key (str, optional): API key for Weights & Biases integration.
404
463
  Defaults to None.
464
+ verbose (bool, optional): whether to print the job parameters before submitting a request.
465
+ Defaults to False.
466
+ model_limits (FinetuneTrainingLimits, optional): Limits for the hyperparameters the model in Fine-tuning.
467
+ Defaults to None.
405
468
 
406
469
  Returns:
407
470
  FinetuneResponse: Object containing information about fine-tuning job.
@@ -411,18 +474,35 @@ class AsyncFineTuning:
411
474
  client=self._client,
412
475
  )
413
476
 
414
- parameter_payload = FinetuneRequest(
415
- model=model,
477
+ if model_limits is None:
478
+ model_limits = await self.get_model_limits(model=model)
479
+
480
+ finetune_request = createFinetuneRequest(
481
+ model_limits=model_limits,
416
482
  training_file=training_file,
417
- validation_file=validation_file,
483
+ model=model,
418
484
  n_epochs=n_epochs,
485
+ validation_file=validation_file,
419
486
  n_evals=n_evals,
420
487
  n_checkpoints=n_checkpoints,
421
488
  batch_size=batch_size,
422
489
  learning_rate=learning_rate,
490
+ warmup_ratio=warmup_ratio,
491
+ lora=lora,
492
+ lora_r=lora_r,
493
+ lora_dropout=lora_dropout,
494
+ lora_alpha=lora_alpha,
495
+ lora_trainable_modules=lora_trainable_modules,
423
496
  suffix=suffix,
424
- wandb_key=wandb_api_key,
425
- ).model_dump(exclude_none=True)
497
+ wandb_api_key=wandb_api_key,
498
+ )
499
+
500
+ if verbose:
501
+ rprint(
502
+ "Submitting a fine-tuning job with the following parameters:",
503
+ finetune_request,
504
+ )
505
+ parameter_payload = finetune_request.model_dump(exclude_none=True)
426
506
 
427
507
  response, _, _ = await requestor.arequest(
428
508
  options=TogetherRequest(
@@ -150,6 +150,8 @@ class FinetuneRequest(BaseModel):
150
150
  n_epochs: int
151
151
  # training learning rate
152
152
  learning_rate: float
153
+ # learning rate warmup ratio
154
+ warmup_ratio: float
153
155
  # number of checkpoints to save
154
156
  n_checkpoints: int | None = None
155
157
  # number of evaluation loops to run
@@ -190,6 +192,8 @@ class FinetuneResponse(BaseModel):
190
192
  batch_size: int | None = None
191
193
  # training learning rate
192
194
  learning_rate: float | None = None
195
+ # learning rate warmup ratio
196
+ warmup_ratio: float | None = None
193
197
  # number of steps between evals
194
198
  eval_steps: int | None = None
195
199
  # training type
@@ -1,21 +0,0 @@
1
- import click
2
-
3
- from typing import Literal
4
-
5
-
6
- class AutoIntParamType(click.ParamType):
7
- name = "integer"
8
-
9
- def convert(
10
- self, value: str, param: click.Parameter | None, ctx: click.Context | None
11
- ) -> int | Literal["max"] | None:
12
- if isinstance(value, int):
13
- return value
14
-
15
- if value == "max":
16
- return "max"
17
-
18
- self.fail("Invalid integer value: {value}")
19
-
20
-
21
- INT_WITH_MAX = AutoIntParamType()
File without changes
File without changes