Skip to content

Commit 6e92279

Browse files
authored
Add from_hf_model argument (#354)
* Add from_hf_model argument * fix docstrings * fixes * version bump
1 parent 16d5141 commit 6e92279

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ build-backend = "poetry.masonry.api"
1212

1313
[tool.poetry]
1414
name = "together"
15-
version = "1.5.23"
15+
version = "1.5.24"
1616
authors = ["Together AI <[email protected]>"]
1717
description = "Python client for Together's Cloud Platform!"
1818
readme = "README.md"

src/together/cli/api/finetune.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,20 @@ def fine_tuning(ctx: click.Context) -> None:
200200
"The format: {$JOB_ID/$OUTPUT_MODEL_NAME}:{$STEP}. "
201201
"The step value is optional, without it the final checkpoint will be used.",
202202
)
203+
@click.option(
204+
"--from-hf-model",
205+
type=str,
206+
help="The Hugging Face Hub repo to start training from. "
207+
"Should be as close as possible to the base model (specified by the `model` argument) "
208+
"in terms of architecture and size",
209+
)
210+
@click.option(
211+
"--hf-model-revision",
212+
type=str,
213+
help="The revision of the Hugging Face Hub model to continue training from. "
214+
"Example: hf_model_revision=None (defaults to the latest revision in `main`) "
215+
"or hf_model_revision='607a30d783dfa663caf39e06633721c8d4cfcd7e' (specific commit).",
216+
)
203217
@click.option(
204218
"--hf-api-token",
205219
type=str,
@@ -246,6 +260,8 @@ def create(
246260
rpo_alpha: float | None,
247261
simpo_gamma: float | None,
248262
from_checkpoint: str,
263+
from_hf_model: str,
264+
hf_model_revision: str,
249265
hf_api_token: str | None,
250266
hf_output_repo_name: str | None,
251267
) -> None:
@@ -284,6 +300,8 @@ def create(
284300
rpo_alpha=rpo_alpha,
285301
simpo_gamma=simpo_gamma,
286302
from_checkpoint=from_checkpoint,
303+
from_hf_model=from_hf_model,
304+
hf_model_revision=hf_model_revision,
287305
hf_api_token=hf_api_token,
288306
hf_output_repo_name=hf_output_repo_name,
289307
)

src/together/resources/finetune.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ def create_finetune_request(
7676
rpo_alpha: float | None = None,
7777
simpo_gamma: float | None = None,
7878
from_checkpoint: str | None = None,
79+
from_hf_model: str | None = None,
80+
hf_model_revision: str | None = None,
7981
hf_api_token: str | None = None,
8082
hf_output_repo_name: str | None = None,
8183
) -> FinetuneRequest:
@@ -87,6 +89,17 @@ def create_finetune_request(
8789
if model is None and from_checkpoint is None:
8890
raise ValueError("You must specify either a model or a checkpoint")
8991

92+
if from_checkpoint is not None and from_hf_model is not None:
93+
raise ValueError(
94+
"You must specify either a Hugging Face Hub model or a previous checkpoint from "
95+
"Together to start a job from, not both"
96+
)
97+
98+
if from_hf_model is not None and model is None:
99+
raise ValueError(
100+
"You must specify the base model to fine-tune a model from the Hugging Face Hub"
101+
)
102+
90103
model_or_checkpoint = model or from_checkpoint
91104

92105
if warmup_ratio is None:
@@ -251,6 +264,8 @@ def create_finetune_request(
251264
wandb_name=wandb_name,
252265
training_method=training_method_cls,
253266
from_checkpoint=from_checkpoint,
267+
from_hf_model=from_hf_model,
268+
hf_model_revision=hf_model_revision,
254269
hf_api_token=hf_api_token,
255270
hf_output_repo_name=hf_output_repo_name,
256271
)
@@ -332,6 +347,8 @@ def create(
332347
rpo_alpha: float | None = None,
333348
simpo_gamma: float | None = None,
334349
from_checkpoint: str | None = None,
350+
from_hf_model: str | None = None,
351+
hf_model_revision: str | None = None,
335352
hf_api_token: str | None = None,
336353
hf_output_repo_name: str | None = None,
337354
) -> FinetuneResponse:
@@ -390,6 +407,11 @@ def create(
390407
from_checkpoint (str, optional): The checkpoint identifier to continue training from a previous fine-tuning job.
391408
The format: {$JOB_ID/$OUTPUT_MODEL_NAME}:{$STEP}.
392409
The step value is optional, without it the final checkpoint will be used.
410+
from_hf_model (str, optional): The Hugging Face Hub repo to start training from.
411+
Should be as close as possible to the base model (specified by the `model` argument) in terms of architecture and size.
412+
hf_model_revision (str, optional): The revision of the Hugging Face Hub model to continue training from. Defaults to None.
413+
Example: hf_model_revision=None (defaults to the latest revision in `main`) or
414+
hf_model_revision="607a30d783dfa663caf39e06633721c8d4cfcd7e" (specific commit).
393415
hf_api_token (str, optional): API key for the Hugging Face Hub. Defaults to None.
394416
hf_output_repo_name (str, optional): HF repo to upload the fine-tuned model to. Defaults to None.
395417
@@ -445,6 +467,8 @@ def create(
445467
rpo_alpha=rpo_alpha,
446468
simpo_gamma=simpo_gamma,
447469
from_checkpoint=from_checkpoint,
470+
from_hf_model=from_hf_model,
471+
hf_model_revision=hf_model_revision,
448472
hf_api_token=hf_api_token,
449473
hf_output_repo_name=hf_output_repo_name,
450474
)
@@ -759,6 +783,8 @@ async def create(
759783
rpo_alpha: float | None = None,
760784
simpo_gamma: float | None = None,
761785
from_checkpoint: str | None = None,
786+
from_hf_model: str | None = None,
787+
hf_model_revision: str | None = None,
762788
hf_api_token: str | None = None,
763789
hf_output_repo_name: str | None = None,
764790
) -> FinetuneResponse:
@@ -817,6 +843,11 @@ async def create(
817843
from_checkpoint (str, optional): The checkpoint identifier to continue training from a previous fine-tuning job.
818844
The format: {$JOB_ID/$OUTPUT_MODEL_NAME}:{$STEP}.
819845
The step value is optional, without it the final checkpoint will be used.
846+
from_hf_model (str, optional): The Hugging Face Hub repo to start training from.
847+
Should be as close as possible to the base model (specified by the `model` argument) in terms of architecture and size.
848+
hf_model_revision (str, optional): The revision of the Hugging Face Hub model to continue training from. Defaults to None.
849+
Example: hf_model_revision=None (defaults to the latest revision in `main`) or
850+
hf_model_revision="607a30d783dfa663caf39e06633721c8d4cfcd7e" (specific commit).
820851
hf_api_token (str, optional): API key for the Huggging Face Hub. Defaults to None.
821852
hf_output_repo_name (str, optional): HF repo to upload the fine-tuned model to. Defaults to None.
822853
@@ -872,6 +903,8 @@ async def create(
872903
rpo_alpha=rpo_alpha,
873904
simpo_gamma=simpo_gamma,
874905
from_checkpoint=from_checkpoint,
906+
from_hf_model=from_hf_model,
907+
hf_model_revision=hf_model_revision,
875908
hf_api_token=hf_api_token,
876909
hf_output_repo_name=hf_output_repo_name,
877910
)

0 commit comments

Comments
 (0)