together 1.5.31__tar.gz → 1.5.32__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 (77) hide show
  1. {together-1.5.31 → together-1.5.32}/PKG-INFO +30 -2
  2. {together-1.5.31 → together-1.5.32}/README.md +28 -0
  3. {together-1.5.31 → together-1.5.32}/pyproject.toml +2 -2
  4. together-1.5.32/src/together/__init__.py +123 -0
  5. {together-1.5.31 → together-1.5.32}/src/together/cli/api/finetune.py +38 -4
  6. {together-1.5.31 → together-1.5.32}/src/together/resources/finetune.py +204 -1
  7. {together-1.5.31 → together-1.5.32}/src/together/types/__init__.py +4 -0
  8. {together-1.5.31 → together-1.5.32}/src/together/types/finetune.py +26 -0
  9. together-1.5.31/src/together/__init__.py +0 -72
  10. {together-1.5.31 → together-1.5.32}/LICENSE +0 -0
  11. {together-1.5.31 → together-1.5.32}/src/together/abstract/__init__.py +0 -0
  12. {together-1.5.31 → together-1.5.32}/src/together/abstract/api_requestor.py +0 -0
  13. {together-1.5.31 → together-1.5.32}/src/together/cli/__init__.py +0 -0
  14. {together-1.5.31 → together-1.5.32}/src/together/cli/api/__init__.py +0 -0
  15. {together-1.5.31 → together-1.5.32}/src/together/cli/api/chat.py +0 -0
  16. {together-1.5.31 → together-1.5.32}/src/together/cli/api/completions.py +0 -0
  17. {together-1.5.31 → together-1.5.32}/src/together/cli/api/endpoints.py +0 -0
  18. {together-1.5.31 → together-1.5.32}/src/together/cli/api/evaluation.py +0 -0
  19. {together-1.5.31 → together-1.5.32}/src/together/cli/api/files.py +0 -0
  20. {together-1.5.31 → together-1.5.32}/src/together/cli/api/images.py +0 -0
  21. {together-1.5.31 → together-1.5.32}/src/together/cli/api/models.py +0 -0
  22. {together-1.5.31 → together-1.5.32}/src/together/cli/api/utils.py +0 -0
  23. {together-1.5.31 → together-1.5.32}/src/together/cli/cli.py +0 -0
  24. {together-1.5.31 → together-1.5.32}/src/together/client.py +0 -0
  25. {together-1.5.31 → together-1.5.32}/src/together/constants.py +0 -0
  26. {together-1.5.31 → together-1.5.32}/src/together/error.py +0 -0
  27. {together-1.5.31 → together-1.5.32}/src/together/filemanager.py +0 -0
  28. {together-1.5.31 → together-1.5.32}/src/together/legacy/__init__.py +0 -0
  29. {together-1.5.31 → together-1.5.32}/src/together/legacy/base.py +0 -0
  30. {together-1.5.31 → together-1.5.32}/src/together/legacy/complete.py +0 -0
  31. {together-1.5.31 → together-1.5.32}/src/together/legacy/embeddings.py +0 -0
  32. {together-1.5.31 → together-1.5.32}/src/together/legacy/files.py +0 -0
  33. {together-1.5.31 → together-1.5.32}/src/together/legacy/finetune.py +0 -0
  34. {together-1.5.31 → together-1.5.32}/src/together/legacy/images.py +0 -0
  35. {together-1.5.31 → together-1.5.32}/src/together/legacy/models.py +0 -0
  36. {together-1.5.31 → together-1.5.32}/src/together/resources/__init__.py +0 -0
  37. {together-1.5.31 → together-1.5.32}/src/together/resources/audio/__init__.py +0 -0
  38. {together-1.5.31 → together-1.5.32}/src/together/resources/audio/speech.py +0 -0
  39. {together-1.5.31 → together-1.5.32}/src/together/resources/audio/transcriptions.py +0 -0
  40. {together-1.5.31 → together-1.5.32}/src/together/resources/audio/translations.py +0 -0
  41. {together-1.5.31 → together-1.5.32}/src/together/resources/audio/voices.py +0 -0
  42. {together-1.5.31 → together-1.5.32}/src/together/resources/batch.py +0 -0
  43. {together-1.5.31 → together-1.5.32}/src/together/resources/chat/__init__.py +0 -0
  44. {together-1.5.31 → together-1.5.32}/src/together/resources/chat/completions.py +0 -0
  45. {together-1.5.31 → together-1.5.32}/src/together/resources/code_interpreter.py +0 -0
  46. {together-1.5.31 → together-1.5.32}/src/together/resources/completions.py +0 -0
  47. {together-1.5.31 → together-1.5.32}/src/together/resources/embeddings.py +0 -0
  48. {together-1.5.31 → together-1.5.32}/src/together/resources/endpoints.py +0 -0
  49. {together-1.5.31 → together-1.5.32}/src/together/resources/evaluation.py +0 -0
  50. {together-1.5.31 → together-1.5.32}/src/together/resources/files.py +0 -0
  51. {together-1.5.31 → together-1.5.32}/src/together/resources/images.py +0 -0
  52. {together-1.5.31 → together-1.5.32}/src/together/resources/models.py +0 -0
  53. {together-1.5.31 → together-1.5.32}/src/together/resources/rerank.py +0 -0
  54. {together-1.5.31 → together-1.5.32}/src/together/resources/videos.py +0 -0
  55. {together-1.5.31 → together-1.5.32}/src/together/together_response.py +0 -0
  56. {together-1.5.31 → together-1.5.32}/src/together/types/abstract.py +0 -0
  57. {together-1.5.31 → together-1.5.32}/src/together/types/audio_speech.py +0 -0
  58. {together-1.5.31 → together-1.5.32}/src/together/types/batch.py +0 -0
  59. {together-1.5.31 → together-1.5.32}/src/together/types/chat_completions.py +0 -0
  60. {together-1.5.31 → together-1.5.32}/src/together/types/code_interpreter.py +0 -0
  61. {together-1.5.31 → together-1.5.32}/src/together/types/common.py +0 -0
  62. {together-1.5.31 → together-1.5.32}/src/together/types/completions.py +0 -0
  63. {together-1.5.31 → together-1.5.32}/src/together/types/embeddings.py +0 -0
  64. {together-1.5.31 → together-1.5.32}/src/together/types/endpoints.py +0 -0
  65. {together-1.5.31 → together-1.5.32}/src/together/types/error.py +0 -0
  66. {together-1.5.31 → together-1.5.32}/src/together/types/evaluation.py +0 -0
  67. {together-1.5.31 → together-1.5.32}/src/together/types/files.py +0 -0
  68. {together-1.5.31 → together-1.5.32}/src/together/types/images.py +0 -0
  69. {together-1.5.31 → together-1.5.32}/src/together/types/models.py +0 -0
  70. {together-1.5.31 → together-1.5.32}/src/together/types/rerank.py +0 -0
  71. {together-1.5.31 → together-1.5.32}/src/together/types/videos.py +0 -0
  72. {together-1.5.31 → together-1.5.32}/src/together/utils/__init__.py +0 -0
  73. {together-1.5.31 → together-1.5.32}/src/together/utils/_log.py +0 -0
  74. {together-1.5.31 → together-1.5.32}/src/together/utils/api_helpers.py +0 -0
  75. {together-1.5.31 → together-1.5.32}/src/together/utils/files.py +0 -0
  76. {together-1.5.31 → together-1.5.32}/src/together/utils/tools.py +0 -0
  77. {together-1.5.31 → together-1.5.32}/src/together/version.py +0 -0
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: together
3
- Version: 1.5.31
4
- Summary: Python client for Together's Cloud Platform!
3
+ Version: 1.5.32
4
+ Summary: Python client for Together's Cloud Platform! Note: SDK 2.0 is now available at https://github.com/togethercomputer/together-py
5
5
  License: Apache-2.0
6
6
  License-File: LICENSE
7
7
  Author: Together AI
@@ -42,6 +42,34 @@ Description-Content-Type: text/markdown
42
42
  </a>
43
43
  </div>
44
44
 
45
+ > [!NOTE]
46
+ > ## 🚀 Together Python SDK 2.0 is now available!
47
+ >
48
+ > Check out the new SDK: **[together-py](https://github.com/togethercomputer/together-py)**
49
+ >
50
+ > 📖 **Migration Guide:** [https://docs.together.ai/docs/pythonv2-migration-guide](https://docs.together.ai/docs/pythonv2-migration-guide)
51
+ >
52
+ > ### Install the Beta
53
+ >
54
+ > **Using uv (Recommended):**
55
+ > ```bash
56
+ > # Install uv if you haven't already
57
+ > curl -LsSf https://astral.sh/uv/install.sh | sh
58
+ >
59
+ > # Install together python SDK
60
+ > uv add together --prerelease allow
61
+ >
62
+ > # Or upgrade an existing installation
63
+ > uv sync --upgrade-package together --prerelease allow
64
+ > ```
65
+ >
66
+ > **Using pip:**
67
+ > ```bash
68
+ > pip install --pre together
69
+ > ```
70
+ >
71
+ > This package will be maintained until January 2026.
72
+
45
73
  # Together Python API library
46
74
 
47
75
  [![PyPI version](https://img.shields.io/pypi/v/together.svg)](https://pypi.org/project/together/)
@@ -4,6 +4,34 @@
4
4
  </a>
5
5
  </div>
6
6
 
7
+ > [!NOTE]
8
+ > ## 🚀 Together Python SDK 2.0 is now available!
9
+ >
10
+ > Check out the new SDK: **[together-py](https://github.com/togethercomputer/together-py)**
11
+ >
12
+ > 📖 **Migration Guide:** [https://docs.together.ai/docs/pythonv2-migration-guide](https://docs.together.ai/docs/pythonv2-migration-guide)
13
+ >
14
+ > ### Install the Beta
15
+ >
16
+ > **Using uv (Recommended):**
17
+ > ```bash
18
+ > # Install uv if you haven't already
19
+ > curl -LsSf https://astral.sh/uv/install.sh | sh
20
+ >
21
+ > # Install together python SDK
22
+ > uv add together --prerelease allow
23
+ >
24
+ > # Or upgrade an existing installation
25
+ > uv sync --upgrade-package together --prerelease allow
26
+ > ```
27
+ >
28
+ > **Using pip:**
29
+ > ```bash
30
+ > pip install --pre together
31
+ > ```
32
+ >
33
+ > This package will be maintained until January 2026.
34
+
7
35
  # Together Python API library
8
36
 
9
37
  [![PyPI version](https://img.shields.io/pypi/v/together.svg)](https://pypi.org/project/together/)
@@ -12,9 +12,9 @@ build-backend = "poetry.masonry.api"
12
12
 
13
13
  [tool.poetry]
14
14
  name = "together"
15
- version = "1.5.31"
15
+ version = "1.5.32"
16
16
  authors = ["Together AI <support@together.ai>"]
17
- description = "Python client for Together's Cloud Platform!"
17
+ description = "Python client for Together's Cloud Platform! Note: SDK 2.0 is now available at https://github.com/togethercomputer/together-py"
18
18
  readme = "README.md"
19
19
  license = "Apache-2.0"
20
20
  classifiers = [
@@ -0,0 +1,123 @@
1
+ from __future__ import annotations
2
+
3
+ import os
4
+ import sys
5
+
6
+ # =============================================================================
7
+ # SDK 2.0 ANNOUNCEMENT
8
+ # =============================================================================
9
+ _ANNOUNCEMENT_MESSAGE = """
10
+ ================================================================================
11
+ Together Python SDK 2.0 is now available!
12
+
13
+ Install: pip install --pre together
14
+ New SDK: https://github.com/togethercomputer/together-py
15
+ Migration guide: https://docs.together.ai/docs/pythonv2-migration-guide
16
+
17
+ This package will be maintained until January 2026.
18
+ ================================================================================
19
+ """
20
+
21
+ # Show info banner (unless suppressed)
22
+ if not os.environ.get("TOGETHER_NO_BANNER"):
23
+ try:
24
+ from rich.console import Console
25
+ from rich.panel import Panel
26
+
27
+ console = Console(stderr=True)
28
+ console.print(
29
+ Panel(
30
+ "[bold cyan]Together Python SDK 2.0 is now available![/bold cyan]\n\n"
31
+ "Install the beta:\n"
32
+ "[green]pip install --pre together[/green] or "
33
+ "[green]uv add together --prerelease allow[/green]\n\n"
34
+ "New SDK: [link=https://github.com/togethercomputer/together-py]"
35
+ "https://github.com/togethercomputer/together-py[/link]\n"
36
+ "Migration guide: [link=https://docs.together.ai/docs/pythonv2-migration-guide]"
37
+ "https://docs.together.ai/docs/pythonv2-migration-guide[/link]\n\n"
38
+ "[dim]This package will be maintained until January 2026.\n"
39
+ "Set TOGETHER_NO_BANNER=1 to hide this message.[/dim]",
40
+ title="🚀 New SDK Available",
41
+ border_style="cyan",
42
+ )
43
+ )
44
+ except Exception:
45
+ # Fallback for any error (ImportError, OSError in daemons, rich errors, etc.)
46
+ # Banner display should never break module imports
47
+ try:
48
+ print(_ANNOUNCEMENT_MESSAGE, file=sys.stderr)
49
+ except Exception:
50
+ pass # Silently ignore if even stderr is unavailable
51
+
52
+ # =============================================================================
53
+
54
+ from contextvars import ContextVar
55
+ from typing import TYPE_CHECKING, Callable
56
+
57
+ from together import (
58
+ abstract,
59
+ client,
60
+ constants,
61
+ error,
62
+ filemanager,
63
+ resources,
64
+ together_response,
65
+ types,
66
+ utils,
67
+ )
68
+ from together.version import VERSION
69
+
70
+ from together.legacy.complete import AsyncComplete, Complete, Completion
71
+ from together.legacy.embeddings import Embeddings
72
+ from together.legacy.files import Files
73
+ from together.legacy.finetune import Finetune
74
+ from together.legacy.images import Image
75
+ from together.legacy.models import Models
76
+
77
+ version = VERSION
78
+
79
+ log: str | None = None # Set to either 'debug' or 'info', controls console logging
80
+
81
+ if TYPE_CHECKING:
82
+ import requests
83
+ from aiohttp import ClientSession
84
+
85
+ requestssession: "requests.Session" | Callable[[], "requests.Session"] | None = None
86
+
87
+ aiosession: ContextVar["ClientSession" | None] = ContextVar(
88
+ "aiohttp-session", default=None
89
+ )
90
+
91
+ from together.client import AsyncClient, AsyncTogether, Client, Together
92
+
93
+
94
+ api_key: str | None = None # To be deprecated in the next major release
95
+
96
+ # Legacy functions
97
+
98
+
99
+ __all__ = [
100
+ "aiosession",
101
+ "constants",
102
+ "version",
103
+ "Together",
104
+ "AsyncTogether",
105
+ "Client",
106
+ "AsyncClient",
107
+ "resources",
108
+ "types",
109
+ "abstract",
110
+ "filemanager",
111
+ "error",
112
+ "together_response",
113
+ "client",
114
+ "utils",
115
+ "Complete",
116
+ "AsyncComplete",
117
+ "Completion",
118
+ "Embeddings",
119
+ "Files",
120
+ "Finetune",
121
+ "Image",
122
+ "Models",
123
+ ]
@@ -17,6 +17,8 @@ from together.types.finetune import (
17
17
  DownloadCheckpointType,
18
18
  FinetuneEventType,
19
19
  FinetuneTrainingLimits,
20
+ FullTrainingType,
21
+ LoRATrainingType,
20
22
  )
21
23
  from together.utils import (
22
24
  finetune_price_to_dollars,
@@ -29,13 +31,21 @@ from together.utils import (
29
31
 
30
32
  _CONFIRMATION_MESSAGE = (
31
33
  "You are about to create a fine-tuning job. "
32
- "The cost of your job will be determined by the model size, the number of tokens "
34
+ "The estimated price of this job is {price}. "
35
+ "The actual cost of your job will be determined by the model size, the number of tokens "
33
36
  "in the training file, the number of tokens in the validation file, the number of epochs, and "
34
- "the number of evaluations. Visit https://www.together.ai/pricing to get a price estimate.\n"
37
+ "the number of evaluations. Visit https://www.together.ai/pricing to learn more about fine-tuning pricing.\n"
38
+ "{warning}"
35
39
  "You can pass `-y` or `--confirm` to your command to skip this message.\n\n"
36
40
  "Do you want to proceed?"
37
41
  )
38
42
 
43
+ _WARNING_MESSAGE_INSUFFICIENT_FUNDS = (
44
+ "The estimated price of this job is significantly greater than your current credit limit and balance combined. "
45
+ "It will likely get cancelled due to insufficient funds. "
46
+ "Consider increasing your credit limit at https://api.together.xyz/settings/profile\n"
47
+ )
48
+
39
49
 
40
50
  class DownloadCheckpointTypeChoice(click.Choice):
41
51
  def __init__(self) -> None:
@@ -357,12 +367,36 @@ def create(
357
367
  "You have specified a number of evaluation loops but no validation file."
358
368
  )
359
369
 
360
- if confirm or click.confirm(_CONFIRMATION_MESSAGE, default=True, show_default=True):
370
+ finetune_price_estimation_result = client.fine_tuning.estimate_price(
371
+ training_file=training_file,
372
+ validation_file=validation_file,
373
+ model=model,
374
+ n_epochs=n_epochs,
375
+ n_evals=n_evals,
376
+ training_type="lora" if lora else "full",
377
+ training_method=training_method,
378
+ )
379
+
380
+ price = click.style(
381
+ f"${finetune_price_estimation_result.estimated_total_price:.2f}",
382
+ bold=True,
383
+ )
384
+
385
+ if not finetune_price_estimation_result.allowed_to_proceed:
386
+ warning = click.style(_WARNING_MESSAGE_INSUFFICIENT_FUNDS, fg="red", bold=True)
387
+ else:
388
+ warning = ""
389
+
390
+ confirmation_message = _CONFIRMATION_MESSAGE.format(
391
+ price=price,
392
+ warning=warning,
393
+ )
394
+
395
+ if confirm or click.confirm(confirmation_message, default=True, show_default=True):
361
396
  response = client.fine_tuning.create(
362
397
  **training_args,
363
398
  verbose=True,
364
399
  )
365
-
366
400
  report_string = f"Successfully submitted a fine-tuning job {response.id}"
367
401
  if response.created_at is not None:
368
402
  created_time = datetime.strptime(
@@ -20,6 +20,8 @@ from together.types import (
20
20
  FinetuneLRScheduler,
21
21
  FinetuneRequest,
22
22
  FinetuneResponse,
23
+ FinetunePriceEstimationRequest,
24
+ FinetunePriceEstimationResponse,
23
25
  FinetuneTrainingLimits,
24
26
  FullTrainingType,
25
27
  LinearLRScheduler,
@@ -31,7 +33,7 @@ from together.types import (
31
33
  TrainingMethodSFT,
32
34
  TrainingType,
33
35
  )
34
- from together.types.finetune import DownloadCheckpointType
36
+ from together.types.finetune import DownloadCheckpointType, TrainingMethod
35
37
  from together.utils import log_warn_once, normalize_key
36
38
 
37
39
 
@@ -42,6 +44,12 @@ AVAILABLE_TRAINING_METHODS = {
42
44
  TrainingMethodSFT().method,
43
45
  TrainingMethodDPO().method,
44
46
  }
47
+ _WARNING_MESSAGE_INSUFFICIENT_FUNDS = (
48
+ "The estimated price of the fine-tuning job is {} which is significantly "
49
+ "greater than your current credit limit and balance combined. "
50
+ "It will likely get cancelled due to insufficient funds. "
51
+ "Proceed at your own risk."
52
+ )
45
53
 
46
54
 
47
55
  def create_finetune_request(
@@ -473,12 +481,34 @@ class FineTuning:
473
481
  hf_api_token=hf_api_token,
474
482
  hf_output_repo_name=hf_output_repo_name,
475
483
  )
484
+ if from_checkpoint is None and from_hf_model is None:
485
+ price_estimation_result = self.estimate_price(
486
+ training_file=training_file,
487
+ validation_file=validation_file,
488
+ model=model_name,
489
+ n_epochs=finetune_request.n_epochs,
490
+ n_evals=finetune_request.n_evals,
491
+ training_type="lora" if lora else "full",
492
+ training_method=training_method,
493
+ )
494
+ price_limit_passed = price_estimation_result.allowed_to_proceed
495
+ else:
496
+ # unsupported case
497
+ price_limit_passed = True
476
498
 
477
499
  if verbose:
478
500
  rprint(
479
501
  "Submitting a fine-tuning job with the following parameters:",
480
502
  finetune_request,
481
503
  )
504
+ if not price_limit_passed:
505
+ rprint(
506
+ "[red]"
507
+ + _WARNING_MESSAGE_INSUFFICIENT_FUNDS.format(
508
+ price_estimation_result.estimated_total_price
509
+ )
510
+ + "[/red]",
511
+ )
482
512
  parameter_payload = finetune_request.model_dump(exclude_none=True)
483
513
 
484
514
  response, _, _ = requestor.request(
@@ -493,6 +523,81 @@ class FineTuning:
493
523
 
494
524
  return FinetuneResponse(**response.data)
495
525
 
526
+ def estimate_price(
527
+ self,
528
+ *,
529
+ training_file: str,
530
+ model: str,
531
+ validation_file: str | None = None,
532
+ n_epochs: int | None = 1,
533
+ n_evals: int | None = 0,
534
+ training_type: str = "lora",
535
+ training_method: str = "sft",
536
+ ) -> FinetunePriceEstimationResponse:
537
+ """
538
+ Estimates the price of a fine-tuning job
539
+
540
+ Args:
541
+ training_file (str): File-ID of a file uploaded to the Together API
542
+ model (str): Name of the base model to run fine-tune job on
543
+ validation_file (str, optional): File ID of a file uploaded to the Together API for validation.
544
+ n_epochs (int, optional): Number of epochs for fine-tuning. Defaults to 1.
545
+ n_evals (int, optional): Number of evaluation loops to run. Defaults to 0.
546
+ training_type (str, optional): Training type. Defaults to "lora".
547
+ training_method (str, optional): Training method. Defaults to "sft".
548
+
549
+ Returns:
550
+ FinetunePriceEstimationResponse: Object containing the price estimation result.
551
+ """
552
+ training_type_cls: TrainingType
553
+ training_method_cls: TrainingMethod
554
+
555
+ if training_method == "sft":
556
+ training_method_cls = TrainingMethodSFT(method="sft")
557
+ elif training_method == "dpo":
558
+ training_method_cls = TrainingMethodDPO(method="dpo")
559
+ else:
560
+ raise ValueError(f"Unknown training method: {training_method}")
561
+
562
+ if training_type.lower() == "lora":
563
+ # parameters of lora are unused in price estimation
564
+ # but we need to set them to valid values
565
+ training_type_cls = LoRATrainingType(
566
+ type="Lora",
567
+ lora_r=16,
568
+ lora_alpha=16,
569
+ lora_dropout=0.0,
570
+ lora_trainable_modules="all-linear",
571
+ )
572
+ elif training_type.lower() == "full":
573
+ training_type_cls = FullTrainingType(type="Full")
574
+ else:
575
+ raise ValueError(f"Unknown training type: {training_type}")
576
+
577
+ request = FinetunePriceEstimationRequest(
578
+ training_file=training_file,
579
+ validation_file=validation_file,
580
+ model=model,
581
+ n_epochs=n_epochs,
582
+ n_evals=n_evals,
583
+ training_type=training_type_cls,
584
+ training_method=training_method_cls,
585
+ )
586
+ parameter_payload = request.model_dump(exclude_none=True)
587
+ requestor = api_requestor.APIRequestor(
588
+ client=self._client,
589
+ )
590
+
591
+ response, _, _ = requestor.request(
592
+ options=TogetherRequest(
593
+ method="POST", url="fine-tunes/estimate-price", params=parameter_payload
594
+ ),
595
+ stream=False,
596
+ )
597
+ assert isinstance(response, TogetherResponse)
598
+
599
+ return FinetunePriceEstimationResponse(**response.data)
600
+
496
601
  def list(self) -> FinetuneList:
497
602
  """
498
603
  Lists fine-tune job history
@@ -941,11 +1046,34 @@ class AsyncFineTuning:
941
1046
  hf_output_repo_name=hf_output_repo_name,
942
1047
  )
943
1048
 
1049
+ if from_checkpoint is None and from_hf_model is None:
1050
+ price_estimation_result = await self.estimate_price(
1051
+ training_file=training_file,
1052
+ validation_file=validation_file,
1053
+ model=model_name,
1054
+ n_epochs=finetune_request.n_epochs,
1055
+ n_evals=finetune_request.n_evals,
1056
+ training_type="lora" if lora else "full",
1057
+ training_method=training_method,
1058
+ )
1059
+ price_limit_passed = price_estimation_result.allowed_to_proceed
1060
+ else:
1061
+ # unsupported case
1062
+ price_limit_passed = True
1063
+
944
1064
  if verbose:
945
1065
  rprint(
946
1066
  "Submitting a fine-tuning job with the following parameters:",
947
1067
  finetune_request,
948
1068
  )
1069
+ if not price_limit_passed:
1070
+ rprint(
1071
+ "[red]"
1072
+ + _WARNING_MESSAGE_INSUFFICIENT_FUNDS.format(
1073
+ price_estimation_result.estimated_total_price
1074
+ )
1075
+ + "[/red]",
1076
+ )
949
1077
  parameter_payload = finetune_request.model_dump(exclude_none=True)
950
1078
 
951
1079
  response, _, _ = await requestor.arequest(
@@ -961,6 +1089,81 @@ class AsyncFineTuning:
961
1089
 
962
1090
  return FinetuneResponse(**response.data)
963
1091
 
1092
+ async def estimate_price(
1093
+ self,
1094
+ *,
1095
+ training_file: str,
1096
+ model: str,
1097
+ validation_file: str | None = None,
1098
+ n_epochs: int | None = 1,
1099
+ n_evals: int | None = 0,
1100
+ training_type: str = "lora",
1101
+ training_method: str = "sft",
1102
+ ) -> FinetunePriceEstimationResponse:
1103
+ """
1104
+ Estimates the price of a fine-tuning job
1105
+
1106
+ Args:
1107
+ training_file (str): File-ID of a file uploaded to the Together API
1108
+ model (str): Name of the base model to run fine-tune job on
1109
+ validation_file (str, optional): File ID of a file uploaded to the Together API for validation.
1110
+ n_epochs (int, optional): Number of epochs for fine-tuning. Defaults to 1.
1111
+ n_evals (int, optional): Number of evaluation loops to run. Defaults to 0.
1112
+ training_type (str, optional): Training type. Defaults to "lora".
1113
+ training_method (str, optional): Training method. Defaults to "sft".
1114
+
1115
+ Returns:
1116
+ FinetunePriceEstimationResponse: Object containing the price estimation result.
1117
+ """
1118
+ training_type_cls: TrainingType
1119
+ training_method_cls: TrainingMethod
1120
+
1121
+ if training_method == "sft":
1122
+ training_method_cls = TrainingMethodSFT(method="sft")
1123
+ elif training_method == "dpo":
1124
+ training_method_cls = TrainingMethodDPO(method="dpo")
1125
+ else:
1126
+ raise ValueError(f"Unknown training method: {training_method}")
1127
+
1128
+ if training_type.lower() == "lora":
1129
+ # parameters of lora are unused in price estimation
1130
+ # but we need to set them to valid values
1131
+ training_type_cls = LoRATrainingType(
1132
+ type="Lora",
1133
+ lora_r=16,
1134
+ lora_alpha=16,
1135
+ lora_dropout=0.0,
1136
+ lora_trainable_modules="all-linear",
1137
+ )
1138
+ elif training_type.lower() == "full":
1139
+ training_type_cls = FullTrainingType(type="Full")
1140
+ else:
1141
+ raise ValueError(f"Unknown training type: {training_type}")
1142
+
1143
+ request = FinetunePriceEstimationRequest(
1144
+ training_file=training_file,
1145
+ validation_file=validation_file,
1146
+ model=model,
1147
+ n_epochs=n_epochs,
1148
+ n_evals=n_evals,
1149
+ training_type=training_type_cls,
1150
+ training_method=training_method_cls,
1151
+ )
1152
+ parameter_payload = request.model_dump(exclude_none=True)
1153
+ requestor = api_requestor.APIRequestor(
1154
+ client=self._client,
1155
+ )
1156
+
1157
+ response, _, _ = await requestor.arequest(
1158
+ options=TogetherRequest(
1159
+ method="POST", url="fine-tunes/estimate-price", params=parameter_payload
1160
+ ),
1161
+ stream=False,
1162
+ )
1163
+ assert isinstance(response, TogetherResponse)
1164
+
1165
+ return FinetunePriceEstimationResponse(**response.data)
1166
+
964
1167
  async def list(self) -> FinetuneList:
965
1168
  """
966
1169
  Async method to list fine-tune job history
@@ -54,6 +54,8 @@ from together.types.finetune import (
54
54
  FinetuneListEvents,
55
55
  FinetuneRequest,
56
56
  FinetuneResponse,
57
+ FinetunePriceEstimationRequest,
58
+ FinetunePriceEstimationResponse,
57
59
  FinetuneDeleteResponse,
58
60
  FinetuneTrainingLimits,
59
61
  FullTrainingType,
@@ -103,6 +105,8 @@ __all__ = [
103
105
  "FinetuneDeleteResponse",
104
106
  "FinetuneDownloadResult",
105
107
  "FinetuneLRScheduler",
108
+ "FinetunePriceEstimationRequest",
109
+ "FinetunePriceEstimationResponse",
106
110
  "LinearLRScheduler",
107
111
  "LinearLRSchedulerArgs",
108
112
  "CosineLRScheduler",
@@ -308,6 +308,32 @@ class FinetuneResponse(BaseModel):
308
308
  raise ValueError("Unknown training type")
309
309
 
310
310
 
311
+ class FinetunePriceEstimationRequest(BaseModel):
312
+ """
313
+ Fine-tune price estimation request type
314
+ """
315
+
316
+ training_file: str
317
+ validation_file: str | None = None
318
+ model: str
319
+ n_epochs: int
320
+ n_evals: int
321
+ training_type: TrainingType
322
+ training_method: TrainingMethod
323
+
324
+
325
+ class FinetunePriceEstimationResponse(BaseModel):
326
+ """
327
+ Fine-tune price estimation response type
328
+ """
329
+
330
+ estimated_total_price: float
331
+ user_limit: float
332
+ estimated_train_token_count: int
333
+ estimated_eval_token_count: int
334
+ allowed_to_proceed: bool
335
+
336
+
311
337
  class FinetuneList(BaseModel):
312
338
  # object type
313
339
  object: Literal["list"] | None = None
@@ -1,72 +0,0 @@
1
- from __future__ import annotations
2
-
3
- from contextvars import ContextVar
4
- from typing import TYPE_CHECKING, Callable
5
-
6
- from together import (
7
- abstract,
8
- client,
9
- constants,
10
- error,
11
- filemanager,
12
- resources,
13
- together_response,
14
- types,
15
- utils,
16
- )
17
- from together.version import VERSION
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
25
-
26
- version = VERSION
27
-
28
- log: str | None = None # Set to either 'debug' or 'info', controls console logging
29
-
30
- if TYPE_CHECKING:
31
- import requests
32
- from aiohttp import ClientSession
33
-
34
- requestssession: "requests.Session" | Callable[[], "requests.Session"] | None = None
35
-
36
- aiosession: ContextVar["ClientSession" | None] = ContextVar(
37
- "aiohttp-session", default=None
38
- )
39
-
40
- from together.client import AsyncClient, AsyncTogether, Client, Together
41
-
42
-
43
- api_key: str | None = None # To be deprecated in the next major release
44
-
45
- # Legacy functions
46
-
47
-
48
- __all__ = [
49
- "aiosession",
50
- "constants",
51
- "version",
52
- "Together",
53
- "AsyncTogether",
54
- "Client",
55
- "AsyncClient",
56
- "resources",
57
- "types",
58
- "abstract",
59
- "filemanager",
60
- "error",
61
- "together_response",
62
- "client",
63
- "utils",
64
- "Complete",
65
- "AsyncComplete",
66
- "Completion",
67
- "Embeddings",
68
- "Files",
69
- "Finetune",
70
- "Image",
71
- "Models",
72
- ]
File without changes