From b5d5d323965d6880acd8ba094d5c9905a1aa67f1 Mon Sep 17 00:00:00 2001 From: Artem Chumachenko Date: Tue, 12 Aug 2025 14:06:02 +0200 Subject: [PATCH 1/4] Add from_hf_model argument --- src/together/cli/api/finetune.py | 17 +++++++++++++++++ src/together/resources/finetune.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/src/together/cli/api/finetune.py b/src/together/cli/api/finetune.py index c397850..acd4c6e 100644 --- a/src/together/cli/api/finetune.py +++ b/src/together/cli/api/finetune.py @@ -200,6 +200,19 @@ def fine_tuning(ctx: click.Context) -> None: "The format: {$JOB_ID/$OUTPUT_MODEL_NAME}:{$STEP}. " "The step value is optional, without it the final checkpoint will be used.", ) +@click.option( + "--from-hf-model", + type=str, + default=None, + help="The Hugging Face repo to start training from. " + "Should be paired with the base model, specified in `model` argument.", +) +@click.option( + "--hf-model-revision", + type=str, + default=None, + help="The revision of the Hugging Face model to continue training from.", +) @click.option( "--hf-api-token", type=str, @@ -246,6 +259,8 @@ def create( rpo_alpha: float | None, simpo_gamma: float | None, from_checkpoint: str, + from_hf_model: str, + hf_model_revision: str, hf_api_token: str | None, hf_output_repo_name: str | None, ) -> None: @@ -284,6 +299,8 @@ def create( rpo_alpha=rpo_alpha, simpo_gamma=simpo_gamma, from_checkpoint=from_checkpoint, + from_hf_model=from_hf_model, + hf_model_revision=hf_model_revision, hf_api_token=hf_api_token, hf_output_repo_name=hf_output_repo_name, ) diff --git a/src/together/resources/finetune.py b/src/together/resources/finetune.py index 8c4d0eb..f7baecd 100644 --- a/src/together/resources/finetune.py +++ b/src/together/resources/finetune.py @@ -76,6 +76,8 @@ def create_finetune_request( rpo_alpha: float | None = None, simpo_gamma: float | None = None, from_checkpoint: str | None = None, + from_hf_model: str | None = None, + hf_model_revision: str | None = None, hf_api_token: str | None = None, hf_output_repo_name: str | None = None, ) -> FinetuneRequest: @@ -87,6 +89,16 @@ def create_finetune_request( if model is None and from_checkpoint is None: raise ValueError("You must specify either a model or a checkpoint") + if from_checkpoint is not None and from_hf_model is not None: + raise ValueError( + "You must specify either a Hugging Face model or a checkpoint to start a job from, not both" + ) + + if from_hf_model is not None and model is None: + raise ValueError( + "You must specify base model to run a fine-tuning job with a Hugging Face model" + ) + model_or_checkpoint = model or from_checkpoint if warmup_ratio is None: @@ -251,6 +263,8 @@ def create_finetune_request( wandb_name=wandb_name, training_method=training_method_cls, from_checkpoint=from_checkpoint, + from_hf_model=from_hf_model, + hf_model_revision=hf_model_revision, hf_api_token=hf_api_token, hf_output_repo_name=hf_output_repo_name, ) @@ -332,6 +346,8 @@ def create( rpo_alpha: float | None = None, simpo_gamma: float | None = None, from_checkpoint: str | None = None, + from_hf_model: str | None = None, + hf_model_revision: str | None = None, hf_api_token: str | None = None, hf_output_repo_name: str | None = None, ) -> FinetuneResponse: @@ -390,6 +406,9 @@ def create( from_checkpoint (str, optional): The checkpoint identifier to continue training from a previous fine-tuning job. The format: {$JOB_ID/$OUTPUT_MODEL_NAME}:{$STEP}. The step value is optional, without it the final checkpoint will be used. + from_hf_model (str, optional): The Hugging Face repo to start training from. + Should be paired with the base model, specified in `model` argument. + hf_model_revision (str, optional): The revision of the Hugging Face model to continue training from. Defaults to None. hf_api_token (str, optional): API key for the Hugging Face Hub. Defaults to None. hf_output_repo_name (str, optional): HF repo to upload the fine-tuned model to. Defaults to None. @@ -445,6 +464,8 @@ def create( rpo_alpha=rpo_alpha, simpo_gamma=simpo_gamma, from_checkpoint=from_checkpoint, + from_hf_model=from_hf_model, + hf_model_revision=hf_model_revision, hf_api_token=hf_api_token, hf_output_repo_name=hf_output_repo_name, ) @@ -759,6 +780,8 @@ async def create( rpo_alpha: float | None = None, simpo_gamma: float | None = None, from_checkpoint: str | None = None, + from_hf_model: str | None = None, + hf_model_revision: str | None = None, hf_api_token: str | None = None, hf_output_repo_name: str | None = None, ) -> FinetuneResponse: @@ -817,6 +840,9 @@ async def create( from_checkpoint (str, optional): The checkpoint identifier to continue training from a previous fine-tuning job. The format: {$JOB_ID/$OUTPUT_MODEL_NAME}:{$STEP}. The step value is optional, without it the final checkpoint will be used. + from_hf_model (str, optional): The Hugging Face repo to start training from. + Should be paired with the base model, specified in `model` argument. + hf_model_revision (str, optional): The revision of the Hugging Face model to continue training from. Defaults to None. hf_api_token (str, optional): API key for the Huggging Face Hub. Defaults to None. hf_output_repo_name (str, optional): HF repo to upload the fine-tuned model to. Defaults to None. @@ -872,6 +898,8 @@ async def create( rpo_alpha=rpo_alpha, simpo_gamma=simpo_gamma, from_checkpoint=from_checkpoint, + from_hf_model=from_hf_model, + hf_model_revision=hf_model_revision, hf_api_token=hf_api_token, hf_output_repo_name=hf_output_repo_name, ) From d97e56a5ee5db29dcd95198c95e3c8fbd178f7c2 Mon Sep 17 00:00:00 2001 From: Artem Chumachenko Date: Tue, 12 Aug 2025 14:36:34 +0200 Subject: [PATCH 2/4] fix docstrings --- src/together/cli/api/finetune.py | 11 ++++++----- src/together/resources/finetune.py | 21 +++++++++++++-------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/together/cli/api/finetune.py b/src/together/cli/api/finetune.py index acd4c6e..2d36f49 100644 --- a/src/together/cli/api/finetune.py +++ b/src/together/cli/api/finetune.py @@ -203,15 +203,16 @@ def fine_tuning(ctx: click.Context) -> None: @click.option( "--from-hf-model", type=str, - default=None, - help="The Hugging Face repo to start training from. " - "Should be paired with the base model, specified in `model` argument.", + help="The Hugging Face Hub repo to start training from. " + "Should be as close as possible to the base model (specified by the `model` argument) in terms of architecture " + "and size with the base model specified by the `model` argument.", ) @click.option( "--hf-model-revision", type=str, - default=None, - help="The revision of the Hugging Face model to continue training from.", + help="The revision of the Hugging Face Hub model to continue training from. " + "Example: hf_model_revision=None (defaults to the latest revision in `main`) " + "or hf_model_revision='607a30d783dfa663caf39e06633721c8d4cfcd7e' (specific commit).", ) @click.option( "--hf-api-token", diff --git a/src/together/resources/finetune.py b/src/together/resources/finetune.py index f7baecd..7700e98 100644 --- a/src/together/resources/finetune.py +++ b/src/together/resources/finetune.py @@ -91,12 +91,13 @@ def create_finetune_request( if from_checkpoint is not None and from_hf_model is not None: raise ValueError( - "You must specify either a Hugging Face model or a checkpoint to start a job from, not both" + "You must specify either a Hugging Face Hub model or a previous checkpoint from " + "Together to start a job from, not both" ) if from_hf_model is not None and model is None: raise ValueError( - "You must specify base model to run a fine-tuning job with a Hugging Face model" + "You must specify the base model to fine-tune a model from the Hugging Face Hub" ) model_or_checkpoint = model or from_checkpoint @@ -406,9 +407,11 @@ def create( from_checkpoint (str, optional): The checkpoint identifier to continue training from a previous fine-tuning job. The format: {$JOB_ID/$OUTPUT_MODEL_NAME}:{$STEP}. The step value is optional, without it the final checkpoint will be used. - from_hf_model (str, optional): The Hugging Face repo to start training from. - Should be paired with the base model, specified in `model` argument. - hf_model_revision (str, optional): The revision of the Hugging Face model to continue training from. Defaults to None. + from_hf_model (str, optional): The Hugging Face Hub repo to start training from. + Should be as close as possible to the base model (specified by the `model` argument) in terms of architecture and size" + hf_model_revision (str, optional): The revision of the Hugging Face Hub model to continue training from. Defaults to None. + Example: hf_model_revision=None (defaults to the latest revision in `main`) or + hf_model_revision="607a30d783dfa663caf39e06633721c8d4cfcd7e" (specific commit). hf_api_token (str, optional): API key for the Hugging Face Hub. Defaults to None. hf_output_repo_name (str, optional): HF repo to upload the fine-tuned model to. Defaults to None. @@ -840,9 +843,11 @@ async def create( from_checkpoint (str, optional): The checkpoint identifier to continue training from a previous fine-tuning job. The format: {$JOB_ID/$OUTPUT_MODEL_NAME}:{$STEP}. The step value is optional, without it the final checkpoint will be used. - from_hf_model (str, optional): The Hugging Face repo to start training from. - Should be paired with the base model, specified in `model` argument. - hf_model_revision (str, optional): The revision of the Hugging Face model to continue training from. Defaults to None. + from_hf_model (str, optional): The Hugging Face Hub repo to start training from. + Should be as close as possible to the base model (specified by the `model` argument) in terms of architecture and size" + hf_model_revision (str, optional): The revision of the Hugging Face Hub model to continue training from. Defaults to None. + Example: hf_model_revision=None (defaults to the latest revision in `main`) or + hf_model_revision="607a30d783dfa663caf39e06633721c8d4cfcd7e" (specific commit). hf_api_token (str, optional): API key for the Huggging Face Hub. Defaults to None. hf_output_repo_name (str, optional): HF repo to upload the fine-tuned model to. Defaults to None. From 78b9dc57b9afaa0ef445f604fbd4bd27263c5ea6 Mon Sep 17 00:00:00 2001 From: Artem Chumachenko Date: Tue, 12 Aug 2025 14:47:06 +0200 Subject: [PATCH 3/4] fixes --- src/together/cli/api/finetune.py | 4 ++-- src/together/resources/finetune.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/together/cli/api/finetune.py b/src/together/cli/api/finetune.py index 2d36f49..f52a14d 100644 --- a/src/together/cli/api/finetune.py +++ b/src/together/cli/api/finetune.py @@ -204,8 +204,8 @@ def fine_tuning(ctx: click.Context) -> None: "--from-hf-model", type=str, help="The Hugging Face Hub repo to start training from. " - "Should be as close as possible to the base model (specified by the `model` argument) in terms of architecture " - "and size with the base model specified by the `model` argument.", + "Should be as close as possible to the base model (specified by the `model` argument) " + "in terms of architecture and size", ) @click.option( "--hf-model-revision", diff --git a/src/together/resources/finetune.py b/src/together/resources/finetune.py index 7700e98..3ebe543 100644 --- a/src/together/resources/finetune.py +++ b/src/together/resources/finetune.py @@ -408,7 +408,7 @@ def create( The format: {$JOB_ID/$OUTPUT_MODEL_NAME}:{$STEP}. The step value is optional, without it the final checkpoint will be used. from_hf_model (str, optional): The Hugging Face Hub repo to start training from. - Should be as close as possible to the base model (specified by the `model` argument) in terms of architecture and size" + Should be as close as possible to the base model (specified by the `model` argument) in terms of architecture and size. hf_model_revision (str, optional): The revision of the Hugging Face Hub model to continue training from. Defaults to None. Example: hf_model_revision=None (defaults to the latest revision in `main`) or hf_model_revision="607a30d783dfa663caf39e06633721c8d4cfcd7e" (specific commit). @@ -844,7 +844,7 @@ async def create( The format: {$JOB_ID/$OUTPUT_MODEL_NAME}:{$STEP}. The step value is optional, without it the final checkpoint will be used. from_hf_model (str, optional): The Hugging Face Hub repo to start training from. - Should be as close as possible to the base model (specified by the `model` argument) in terms of architecture and size" + Should be as close as possible to the base model (specified by the `model` argument) in terms of architecture and size. hf_model_revision (str, optional): The revision of the Hugging Face Hub model to continue training from. Defaults to None. Example: hf_model_revision=None (defaults to the latest revision in `main`) or hf_model_revision="607a30d783dfa663caf39e06633721c8d4cfcd7e" (specific commit). From 9f912d52250dbb94acab91cf08ea7afb1c3a9bd5 Mon Sep 17 00:00:00 2001 From: Artem Chumachenko Date: Tue, 12 Aug 2025 14:48:26 +0200 Subject: [PATCH 4/4] version bump --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 5054e8f..2f75b40 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,7 +12,7 @@ build-backend = "poetry.masonry.api" [tool.poetry] name = "together" -version = "1.5.23" +version = "1.5.24" authors = ["Together AI "] description = "Python client for Together's Cloud Platform!" readme = "README.md"