Skip to content

Commit f8225fd

Browse files
feat: add fine-tunes preview endpoint
Stainless-Generated-From: ed7c75d5257a7bbf495683f9fede1f07f2eeacc1
1 parent 3546f22 commit f8225fd

9 files changed

Lines changed: 319 additions & 2 deletions

File tree

.stats.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
configured_endpoints: 140
1+
configured_endpoints: 141

api.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,8 @@ Types:
425425

426426
```python
427427
from together.types import (
428+
FineTunePreviewResponse,
429+
FineTunePreviewRow,
428430
FinetuneEvent,
429431
FinetuneEventType,
430432
FinetuneModelLimits,
@@ -452,6 +454,7 @@ Methods:
452454
- <code title="get /fine-tunes/{id}/events">client.fine_tuning.<a href="./src/together/resources/fine_tuning.py">list_events</a>(id) -> <a href="./src/together/types/fine_tuning_list_events_response.py">FineTuningListEventsResponse</a></code>
453455
- <code title="get /fine-tunes/{id}/metrics">client.fine_tuning.<a href="./src/together/resources/fine_tuning.py">list_metrics</a>(id, \*\*<a href="src/together/types/fine_tuning_list_metrics_params.py">params</a>) -> <a href="./src/together/types/fine_tuning_list_metrics_response.py">FineTuningListMetricsResponse</a></code>
454456
- <code title="get /fine-tunes/models/limits">client.fine_tuning.<a href="./src/together/resources/fine_tuning.py">model_limits</a>(\*\*<a href="src/together/types/fine_tuning_model_limits_params.py">params</a>) -> <a href="./src/together/types/finetune_model_limits.py">FinetuneModelLimits</a></code>
457+
- <code title="post /fine-tunes/preview">client.fine_tuning.<a href="./src/together/resources/fine_tuning.py">preview</a>(\*\*<a href="src/together/types/fine_tuning_preview_params.py">params</a>) -> <a href="./src/together/types/fine_tune_preview_response.py">FineTunePreviewResponse</a></code>
455458

456459
# CodeInterpreter
457460

scripts/mock

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

src/together/resources/fine_tuning.py

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from ..types import (
1313
fine_tuning_delete_params,
1414
fine_tuning_content_params,
15+
fine_tuning_preview_params,
1516
fine_tuning_list_metrics_params,
1617
fine_tuning_model_limits_params,
1718
fine_tuning_estimate_price_params,
@@ -40,6 +41,7 @@
4041
from ..lib.resources.fine_tuning import create_finetune_request
4142
from ..types.finetune_model_limits import FinetuneModelLimits
4243
from ..types.fine_tuning_list_response import FineTuningListResponse
44+
from ..types.fine_tune_preview_response import FineTunePreviewResponse
4345
from ..types.fine_tuning_cancel_response import FineTuningCancelResponse
4446
from ..types.fine_tuning_delete_response import FineTuningDeleteResponse
4547
from ..types.fine_tuning_list_events_response import FineTuningListEventsResponse
@@ -748,6 +750,64 @@ def model_limits(
748750
cast_to=FinetuneModelLimits,
749751
)
750752

753+
def preview(
754+
self,
755+
*,
756+
model: str,
757+
training_file: str,
758+
top_k: int | Omit = omit,
759+
train_on_inputs: bool | Omit = omit,
760+
training_method: Literal["sft"] | Omit = omit,
761+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
762+
# The extra values given here take precedence over values defined on the client or passed to this method.
763+
extra_headers: Headers | None = None,
764+
extra_query: Query | None = None,
765+
extra_body: Body | None = None,
766+
timeout: float | httpx.Timeout | None | NotGiven = not_given,
767+
) -> FineTunePreviewResponse:
768+
"""
769+
Preview how sampled rows from a fine-tuning training file will be tokenized
770+
before packing.
771+
772+
Args:
773+
model: Name of the base model whose tokenizer and chat template will be used.
774+
775+
training_file: File-ID of the uploaded JSONL training file to sample for preview.
776+
777+
top_k: Maximum number of rows from the start of the training file to tokenize.
778+
779+
train_on_inputs: Whether prompt or user-message tokens should contribute to training loss in the
780+
preview.
781+
782+
training_method: Fine-tuning method to preview. Only supervised fine-tuning is currently
783+
supported.
784+
785+
extra_headers: Send extra headers
786+
787+
extra_query: Add additional query parameters to the request
788+
789+
extra_body: Add additional JSON properties to the request
790+
791+
timeout: Override the client-level default timeout for this request, in seconds
792+
"""
793+
return self._post(
794+
"/fine-tunes/preview",
795+
body=maybe_transform(
796+
{
797+
"model": model,
798+
"training_file": training_file,
799+
"top_k": top_k,
800+
"train_on_inputs": train_on_inputs,
801+
"training_method": training_method,
802+
},
803+
fine_tuning_preview_params.FineTuningPreviewParams,
804+
),
805+
options=make_request_options(
806+
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
807+
),
808+
cast_to=FineTunePreviewResponse,
809+
)
810+
751811

752812
class AsyncFineTuningResource(AsyncAPIResource):
753813
@cached_property
@@ -1439,6 +1499,64 @@ async def model_limits(
14391499
cast_to=FinetuneModelLimits,
14401500
)
14411501

1502+
async def preview(
1503+
self,
1504+
*,
1505+
model: str,
1506+
training_file: str,
1507+
top_k: int | Omit = omit,
1508+
train_on_inputs: bool | Omit = omit,
1509+
training_method: Literal["sft"] | Omit = omit,
1510+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
1511+
# The extra values given here take precedence over values defined on the client or passed to this method.
1512+
extra_headers: Headers | None = None,
1513+
extra_query: Query | None = None,
1514+
extra_body: Body | None = None,
1515+
timeout: float | httpx.Timeout | None | NotGiven = not_given,
1516+
) -> FineTunePreviewResponse:
1517+
"""
1518+
Preview how sampled rows from a fine-tuning training file will be tokenized
1519+
before packing.
1520+
1521+
Args:
1522+
model: Name of the base model whose tokenizer and chat template will be used.
1523+
1524+
training_file: File-ID of the uploaded JSONL training file to sample for preview.
1525+
1526+
top_k: Maximum number of rows from the start of the training file to tokenize.
1527+
1528+
train_on_inputs: Whether prompt or user-message tokens should contribute to training loss in the
1529+
preview.
1530+
1531+
training_method: Fine-tuning method to preview. Only supervised fine-tuning is currently
1532+
supported.
1533+
1534+
extra_headers: Send extra headers
1535+
1536+
extra_query: Add additional query parameters to the request
1537+
1538+
extra_body: Add additional JSON properties to the request
1539+
1540+
timeout: Override the client-level default timeout for this request, in seconds
1541+
"""
1542+
return await self._post(
1543+
"/fine-tunes/preview",
1544+
body=await async_maybe_transform(
1545+
{
1546+
"model": model,
1547+
"training_file": training_file,
1548+
"top_k": top_k,
1549+
"train_on_inputs": train_on_inputs,
1550+
"training_method": training_method,
1551+
},
1552+
fine_tuning_preview_params.FineTuningPreviewParams,
1553+
),
1554+
options=make_request_options(
1555+
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
1556+
),
1557+
cast_to=FineTunePreviewResponse,
1558+
)
1559+
14421560

14431561
class FineTuningResourceWithRawResponse:
14441562
def __init__(self, fine_tuning: FineTuningResource) -> None:
@@ -1475,6 +1593,9 @@ def __init__(self, fine_tuning: FineTuningResource) -> None:
14751593
self.model_limits = to_raw_response_wrapper(
14761594
fine_tuning.model_limits,
14771595
)
1596+
self.preview = to_raw_response_wrapper(
1597+
fine_tuning.preview,
1598+
)
14781599

14791600

14801601
class AsyncFineTuningResourceWithRawResponse:
@@ -1512,6 +1633,9 @@ def __init__(self, fine_tuning: AsyncFineTuningResource) -> None:
15121633
self.model_limits = async_to_raw_response_wrapper(
15131634
fine_tuning.model_limits,
15141635
)
1636+
self.preview = async_to_raw_response_wrapper(
1637+
fine_tuning.preview,
1638+
)
15151639

15161640

15171641
class FineTuningResourceWithStreamingResponse:
@@ -1549,6 +1673,9 @@ def __init__(self, fine_tuning: FineTuningResource) -> None:
15491673
self.model_limits = to_streamed_response_wrapper(
15501674
fine_tuning.model_limits,
15511675
)
1676+
self.preview = to_streamed_response_wrapper(
1677+
fine_tuning.preview,
1678+
)
15521679

15531680

15541681
class AsyncFineTuningResourceWithStreamingResponse:
@@ -1586,3 +1713,6 @@ def __init__(self, fine_tuning: AsyncFineTuningResource) -> None:
15861713
self.model_limits = async_to_streamed_response_wrapper(
15871714
fine_tuning.model_limits,
15881715
)
1716+
self.preview = async_to_streamed_response_wrapper(
1717+
fine_tuning.preview,
1718+
)

src/together/types/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
from .file_delete_response import FileDeleteResponse as FileDeleteResponse
4444
from .rerank_create_params import RerankCreateParams as RerankCreateParams
4545
from .batch_create_response import BatchCreateResponse as BatchCreateResponse
46+
from .fine_tune_preview_row import FineTunePreviewRow as FineTunePreviewRow
4647
from .finetune_model_limits import FinetuneModelLimits as FinetuneModelLimits
4748
from .image_generate_params import ImageGenerateParams as ImageGenerateParams
4849
from .model_upload_response import ModelUploadResponse as ModelUploadResponse
@@ -55,7 +56,9 @@
5556
from .audio_speech_stream_chunk import AudioSpeechStreamChunk as AudioSpeechStreamChunk
5657
from .fine_tuning_delete_params import FineTuningDeleteParams as FineTuningDeleteParams
5758
from .fine_tuning_list_response import FineTuningListResponse as FineTuningListResponse
59+
from .fine_tune_preview_response import FineTunePreviewResponse as FineTunePreviewResponse
5860
from .fine_tuning_content_params import FineTuningContentParams as FineTuningContentParams
61+
from .fine_tuning_preview_params import FineTuningPreviewParams as FineTuningPreviewParams
5962
from .fine_tuning_cancel_response import FineTuningCancelResponse as FineTuningCancelResponse
6063
from .fine_tuning_delete_response import FineTuningDeleteResponse as FineTuningDeleteResponse
6164
from .endpoint_list_hardware_params import EndpointListHardwareParams as EndpointListHardwareParams
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
from typing import List
4+
from typing_extensions import Literal
5+
6+
from .._models import BaseModel
7+
from .fine_tune_preview_row import FineTunePreviewRow
8+
9+
__all__ = ["FineTunePreviewResponse"]
10+
11+
12+
class FineTunePreviewResponse(BaseModel):
13+
"""Tokenized preview for sampled rows from a fine-tuning training file."""
14+
15+
dataset_format: Literal["general", "conversation", "instruction"]
16+
"""Detected SFT dataset format for the sampled rows."""
17+
18+
max_seq_length: int
19+
"""Maximum sequence length configured for the requested model."""
20+
21+
model: str
22+
"""Name of the base model used to tokenize the sampled rows."""
23+
24+
rows: List[FineTunePreviewRow]
25+
"""Tokenized preview rows, in the same order as the sampled training file rows."""
26+
27+
train_on_inputs: bool
28+
"""Whether prompt or user-message tokens contribute to training loss."""
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
from typing import List
4+
5+
from .._models import BaseModel
6+
7+
__all__ = ["FineTunePreviewRow"]
8+
9+
10+
class FineTunePreviewRow(BaseModel):
11+
"""Tokenized representation of one sampled fine-tuning row."""
12+
13+
input_ids: List[int]
14+
"""Token IDs produced for the sampled row."""
15+
16+
labels: List[int]
17+
"""Training labels for each token; masked tokens use -100."""
18+
19+
num_tokens: int
20+
"""Total number of tokens in the preview row after truncation."""
21+
22+
num_trained_tokens: int
23+
"""Number of tokens in the row that contribute to training loss."""
24+
25+
tokens: List[str]
26+
"""Raw token strings produced for the sampled row."""
27+
28+
trained_spans: List[List[int]]
29+
"""Half-open token index ranges that contribute to training loss."""
30+
31+
truncated: bool
32+
"""Whether the row was truncated to the model maximum sequence length."""
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
from __future__ import annotations
4+
5+
from typing_extensions import Literal, Required, TypedDict
6+
7+
__all__ = ["FineTuningPreviewParams"]
8+
9+
10+
class FineTuningPreviewParams(TypedDict, total=False):
11+
model: Required[str]
12+
"""Name of the base model whose tokenizer and chat template will be used."""
13+
14+
training_file: Required[str]
15+
"""File-ID of the uploaded JSONL training file to sample for preview."""
16+
17+
top_k: int
18+
"""Maximum number of rows from the start of the training file to tokenize."""
19+
20+
train_on_inputs: bool
21+
"""
22+
Whether prompt or user-message tokens should contribute to training loss in the
23+
preview.
24+
"""
25+
26+
training_method: Literal["sft"]
27+
"""Fine-tuning method to preview.
28+
29+
Only supervised fine-tuning is currently supported.
30+
"""

0 commit comments

Comments
 (0)