From 691e2a30cd669076831b9ab08105398a319ce302 Mon Sep 17 00:00:00 2001 From: Max Ryabinin Date: Tue, 1 Apr 2025 17:14:09 +0100 Subject: [PATCH 1/9] WIP extend continued FT --- src/together/cli/api/finetune.py | 20 +++++++++++++++++++- src/together/resources/finetune.py | 20 ++++++++++++++++++++ src/together/types/finetune.py | 2 ++ 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/together/cli/api/finetune.py b/src/together/cli/api/finetune.py index 172acdd3..cd9cbbe4 100644 --- a/src/together/cli/api/finetune.py +++ b/src/together/cli/api/finetune.py @@ -200,6 +200,20 @@ 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="Model name from the Hugging Face Hub that will be used to initialize the trained model. " + "The model config is not validated; any model supported by Transformers should work, but the batch size " + "limits are not checked.", +) +@click.option( + "--hf-api-token", + type=str, + default=None, + help="HF API token to use to download a checkpoint from a private repo", +) def create( ctx: click.Context, training_file: str, @@ -234,6 +248,8 @@ def create( rpo_alpha: float | None, simpo_gamma: float | None, from_checkpoint: str, + from_hf_model: str, + hf_api_token: str, ) -> None: """Start fine-tuning""" client: Together = ctx.obj @@ -270,6 +286,8 @@ def create( rpo_alpha=rpo_alpha, simpo_gamma=simpo_gamma, from_checkpoint=from_checkpoint, + from_hf_model=from_hf_model, + hf_api_token=hf_api_token, ) if model is None and from_checkpoint is None: @@ -280,7 +298,7 @@ def create( model_name = from_checkpoint.split(":")[0] model_limits: FinetuneTrainingLimits = client.fine_tuning.get_model_limits( - model=model_name + model=model_name, ) if lora: diff --git a/src/together/resources/finetune.py b/src/together/resources/finetune.py index 27baf2d2..990476bb 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_api_token: str | None = None, ) -> FinetuneRequest: if model is not None and from_checkpoint is not None: raise ValueError( @@ -262,6 +264,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_api_token=hf_api_token, ) return finetune_request @@ -341,6 +345,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_api_token: str | None = None, ) -> FinetuneResponse: """ Method to initiate a fine-tuning job @@ -397,6 +403,10 @@ 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): Model name from the Hugging Face Hub that will be used to initialize the trained model. + The model config is not validated; any model supported by Transformers should work, but the batch size + limits are not checked. Defaults to None. + hf_api_token (str, optional): API key for the Hugging Face Hub. Defaults to None. Returns: FinetuneResponse: Object containing information about fine-tuning job. @@ -450,6 +460,8 @@ def create( rpo_alpha=rpo_alpha, simpo_gamma=simpo_gamma, from_checkpoint=from_checkpoint, + from_hf_model=from_hf_model, + hf_api_token=hf_api_token, ) if verbose: @@ -762,6 +774,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_api_token: str | None = None, ) -> FinetuneResponse: """ Async method to initiate a fine-tuning job @@ -818,6 +832,10 @@ 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): Model name from the Hugging Face Hub that will be used to initialize the trained model. + The model config is not validated; any model supported by Transformers should work, but the batch size + limits are not checked. Defaults to None. + hf_api_token (str, optional): API key for the Huggging Face Hub. Defaults to None. Returns: FinetuneResponse: Object containing information about fine-tuning job. @@ -871,6 +889,8 @@ async def create( rpo_alpha=rpo_alpha, simpo_gamma=simpo_gamma, from_checkpoint=from_checkpoint, + from_hf_model=from_hf_model, + hf_api_token=hf_api_token, ) if verbose: diff --git a/src/together/types/finetune.py b/src/together/types/finetune.py index e8c388f9..390dcaad 100644 --- a/src/together/types/finetune.py +++ b/src/together/types/finetune.py @@ -212,6 +212,8 @@ class FinetuneRequest(BaseModel): ) # from step from_checkpoint: str | None = None + from_hf_model: str | None = None + hf_api_token: str | None = None class FinetuneResponse(BaseModel): From c6453442698e944d9c45e9999cf43497cdd27241 Mon Sep 17 00:00:00 2001 From: Egor Timofeev Date: Thu, 3 Jul 2025 17:31:53 +0200 Subject: [PATCH 2/9] remove the hf training ckpt --- src/together/cli/api/finetune.py | 12 +----------- src/together/resources/finetune.py | 11 ----------- src/together/types/finetune.py | 1 - 3 files changed, 1 insertion(+), 23 deletions(-) diff --git a/src/together/cli/api/finetune.py b/src/together/cli/api/finetune.py index cd9cbbe4..15eed907 100644 --- a/src/together/cli/api/finetune.py +++ b/src/together/cli/api/finetune.py @@ -200,19 +200,11 @@ 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="Model name from the Hugging Face Hub that will be used to initialize the trained model. " - "The model config is not validated; any model supported by Transformers should work, but the batch size " - "limits are not checked.", -) @click.option( "--hf-api-token", type=str, default=None, - help="HF API token to use to download a checkpoint from a private repo", + help="HF API token to use to upload a checkpoint to a private repo", ) def create( ctx: click.Context, @@ -248,7 +240,6 @@ def create( rpo_alpha: float | None, simpo_gamma: float | None, from_checkpoint: str, - from_hf_model: str, hf_api_token: str, ) -> None: """Start fine-tuning""" @@ -286,7 +277,6 @@ def create( rpo_alpha=rpo_alpha, simpo_gamma=simpo_gamma, from_checkpoint=from_checkpoint, - from_hf_model=from_hf_model, hf_api_token=hf_api_token, ) diff --git a/src/together/resources/finetune.py b/src/together/resources/finetune.py index 990476bb..8e3cebb8 100644 --- a/src/together/resources/finetune.py +++ b/src/together/resources/finetune.py @@ -76,7 +76,6 @@ 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_api_token: str | None = None, ) -> FinetuneRequest: if model is not None and from_checkpoint is not None: @@ -264,7 +263,6 @@ def create_finetune_request( wandb_name=wandb_name, training_method=training_method_cls, from_checkpoint=from_checkpoint, - from_hf_model=from_hf_model, hf_api_token=hf_api_token, ) @@ -345,7 +343,6 @@ def create( rpo_alpha: float | None = None, simpo_gamma: float | None = None, from_checkpoint: str | None = None, - from_hf_model: str | None = None, hf_api_token: str | None = None, ) -> FinetuneResponse: """ @@ -403,9 +400,6 @@ 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): Model name from the Hugging Face Hub that will be used to initialize the trained model. - The model config is not validated; any model supported by Transformers should work, but the batch size - limits are not checked. Defaults to None. hf_api_token (str, optional): API key for the Hugging Face Hub. Defaults to None. Returns: @@ -460,7 +454,6 @@ def create( rpo_alpha=rpo_alpha, simpo_gamma=simpo_gamma, from_checkpoint=from_checkpoint, - from_hf_model=from_hf_model, hf_api_token=hf_api_token, ) @@ -774,7 +767,6 @@ 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_api_token: str | None = None, ) -> FinetuneResponse: """ @@ -832,9 +824,6 @@ 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): Model name from the Hugging Face Hub that will be used to initialize the trained model. - The model config is not validated; any model supported by Transformers should work, but the batch size - limits are not checked. Defaults to None. hf_api_token (str, optional): API key for the Huggging Face Hub. Defaults to None. Returns: diff --git a/src/together/types/finetune.py b/src/together/types/finetune.py index 390dcaad..e72abf1e 100644 --- a/src/together/types/finetune.py +++ b/src/together/types/finetune.py @@ -212,7 +212,6 @@ class FinetuneRequest(BaseModel): ) # from step from_checkpoint: str | None = None - from_hf_model: str | None = None hf_api_token: str | None = None From c39a9ad1f9799b5f05b1dbcd8692a55dc6c7df03 Mon Sep 17 00:00:00 2001 From: Egor Timofeev Date: Thu, 3 Jul 2025 17:32:58 +0200 Subject: [PATCH 3/9] Bump version --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 17373042..afd13384 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,7 +12,7 @@ build-backend = "poetry.masonry.api" [tool.poetry] name = "together" -version = "1.5.17" +version = "1.5.18" authors = ["Together AI "] description = "Python client for Together's Cloud Platform!" readme = "README.md" From e670b770f8e56c13a9b0a2338fe4c9f3be6f685a Mon Sep 17 00:00:00 2001 From: Egor Timofeev Date: Thu, 3 Jul 2025 17:37:16 +0200 Subject: [PATCH 4/9] Add fixes --- src/together/cli/api/finetune.py | 10 +++++++++- src/together/resources/finetune.py | 7 ++++++- src/together/types/finetune.py | 2 ++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/together/cli/api/finetune.py b/src/together/cli/api/finetune.py index 15eed907..44be62c6 100644 --- a/src/together/cli/api/finetune.py +++ b/src/together/cli/api/finetune.py @@ -206,6 +206,12 @@ def fine_tuning(ctx: click.Context) -> None: default=None, help="HF API token to use to upload a checkpoint to a private repo", ) +@click.option( + "--hf-repo-to-upload", + type=str, + default=None, + help="HF repo to upload the fine-tuned model to", +) def create( ctx: click.Context, training_file: str, @@ -240,7 +246,8 @@ def create( rpo_alpha: float | None, simpo_gamma: float | None, from_checkpoint: str, - hf_api_token: str, + hf_api_token: str | None, + hf_repo_to_upload: str | None, ) -> None: """Start fine-tuning""" client: Together = ctx.obj @@ -278,6 +285,7 @@ def create( simpo_gamma=simpo_gamma, from_checkpoint=from_checkpoint, hf_api_token=hf_api_token, + hf_repo_to_upload=hf_repo_to_upload, ) if model is None and from_checkpoint is None: diff --git a/src/together/resources/finetune.py b/src/together/resources/finetune.py index 8e3cebb8..a95477c9 100644 --- a/src/together/resources/finetune.py +++ b/src/together/resources/finetune.py @@ -344,6 +344,7 @@ def create( simpo_gamma: float | None = None, from_checkpoint: str | None = None, hf_api_token: str | None = None, + hf_repo_to_upload: str | None = None, ) -> FinetuneResponse: """ Method to initiate a fine-tuning job @@ -401,6 +402,7 @@ def create( The format: {$JOB_ID/$OUTPUT_MODEL_NAME}:{$STEP}. The step value is optional, without it the final checkpoint will be used. hf_api_token (str, optional): API key for the Hugging Face Hub. Defaults to None. + hf_repo_to_upload (str, optional): HF repo to upload the fine-tuned model to. Defaults to None. Returns: FinetuneResponse: Object containing information about fine-tuning job. @@ -455,6 +457,7 @@ def create( simpo_gamma=simpo_gamma, from_checkpoint=from_checkpoint, hf_api_token=hf_api_token, + hf_repo_to_upload=hf_repo_to_upload, ) if verbose: @@ -768,6 +771,7 @@ async def create( simpo_gamma: float | None = None, from_checkpoint: str | None = None, hf_api_token: str | None = None, + hf_repo_to_upload: str | None = None, ) -> FinetuneResponse: """ Async method to initiate a fine-tuning job @@ -825,6 +829,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. hf_api_token (str, optional): API key for the Huggging Face Hub. Defaults to None. + hf_repo_to_upload (str, optional): HF repo to upload the fine-tuned model to. Defaults to None. Returns: FinetuneResponse: Object containing information about fine-tuning job. @@ -878,8 +883,8 @@ async def create( rpo_alpha=rpo_alpha, simpo_gamma=simpo_gamma, from_checkpoint=from_checkpoint, - from_hf_model=from_hf_model, hf_api_token=hf_api_token, + hf_repo_to_upload=hf_repo_to_upload, ) if verbose: diff --git a/src/together/types/finetune.py b/src/together/types/finetune.py index e72abf1e..45838865 100644 --- a/src/together/types/finetune.py +++ b/src/together/types/finetune.py @@ -212,7 +212,9 @@ class FinetuneRequest(BaseModel): ) # from step from_checkpoint: str | None = None + # hf related fields hf_api_token: str | None = None + hf_repo_to_upload: str | None = None class FinetuneResponse(BaseModel): From 65c7ae9650d30ae4d136ed9d496abea2f7b6d880 Mon Sep 17 00:00:00 2001 From: Egor Timofeev Date: Thu, 3 Jul 2025 17:39:10 +0200 Subject: [PATCH 5/9] Add to create finetuning request --- src/together/resources/finetune.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/together/resources/finetune.py b/src/together/resources/finetune.py index a95477c9..57a952f0 100644 --- a/src/together/resources/finetune.py +++ b/src/together/resources/finetune.py @@ -77,6 +77,7 @@ def create_finetune_request( simpo_gamma: float | None = None, from_checkpoint: str | None = None, hf_api_token: str | None = None, + hf_repo_to_upload: str | None = None, ) -> FinetuneRequest: if model is not None and from_checkpoint is not None: raise ValueError( @@ -264,6 +265,7 @@ def create_finetune_request( training_method=training_method_cls, from_checkpoint=from_checkpoint, hf_api_token=hf_api_token, + hf_repo_to_upload=hf_repo_to_upload, ) return finetune_request From 9e6bbc107208365ae60da5246a9abde0f546d489 Mon Sep 17 00:00:00 2001 From: Egor Timofeev Date: Mon, 7 Jul 2025 11:26:01 +0200 Subject: [PATCH 6/9] Fix naming --- src/together/resources/finetune.py | 16 ++++++++-------- src/together/types/finetune.py | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/together/resources/finetune.py b/src/together/resources/finetune.py index 57a952f0..b69c2a3f 100644 --- a/src/together/resources/finetune.py +++ b/src/together/resources/finetune.py @@ -77,7 +77,7 @@ def create_finetune_request( simpo_gamma: float | None = None, from_checkpoint: str | None = None, hf_api_token: str | None = None, - hf_repo_to_upload: str | None = None, + hf_output_repo_name: str | None = None, ) -> FinetuneRequest: if model is not None and from_checkpoint is not None: raise ValueError( @@ -265,7 +265,7 @@ def create_finetune_request( training_method=training_method_cls, from_checkpoint=from_checkpoint, hf_api_token=hf_api_token, - hf_repo_to_upload=hf_repo_to_upload, + hf_output_repo_name=hf_output_repo_name, ) return finetune_request @@ -346,7 +346,7 @@ def create( simpo_gamma: float | None = None, from_checkpoint: str | None = None, hf_api_token: str | None = None, - hf_repo_to_upload: str | None = None, + hf_output_repo_name: str | None = None, ) -> FinetuneResponse: """ Method to initiate a fine-tuning job @@ -404,7 +404,7 @@ def create( The format: {$JOB_ID/$OUTPUT_MODEL_NAME}:{$STEP}. The step value is optional, without it the final checkpoint will be used. hf_api_token (str, optional): API key for the Hugging Face Hub. Defaults to None. - hf_repo_to_upload (str, optional): HF repo to upload the fine-tuned model to. Defaults to None. + hf_output_repo_name (str, optional): HF repo to upload the fine-tuned model to. Defaults to None. Returns: FinetuneResponse: Object containing information about fine-tuning job. @@ -459,7 +459,7 @@ def create( simpo_gamma=simpo_gamma, from_checkpoint=from_checkpoint, hf_api_token=hf_api_token, - hf_repo_to_upload=hf_repo_to_upload, + hf_output_repo_name=hf_output_repo_name, ) if verbose: @@ -773,7 +773,7 @@ async def create( simpo_gamma: float | None = None, from_checkpoint: str | None = None, hf_api_token: str | None = None, - hf_repo_to_upload: str | None = None, + hf_output_repo_name: str | None = None, ) -> FinetuneResponse: """ Async method to initiate a fine-tuning job @@ -831,7 +831,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. hf_api_token (str, optional): API key for the Huggging Face Hub. Defaults to None. - hf_repo_to_upload (str, optional): HF repo to upload the fine-tuned model to. Defaults to None. + hf_output_repo_name (str, optional): HF repo to upload the fine-tuned model to. Defaults to None. Returns: FinetuneResponse: Object containing information about fine-tuning job. @@ -886,7 +886,7 @@ async def create( simpo_gamma=simpo_gamma, from_checkpoint=from_checkpoint, hf_api_token=hf_api_token, - hf_repo_to_upload=hf_repo_to_upload, + hf_output_repo_name=hf_output_repo_name, ) if verbose: diff --git a/src/together/types/finetune.py b/src/together/types/finetune.py index 45838865..ee160eec 100644 --- a/src/together/types/finetune.py +++ b/src/together/types/finetune.py @@ -214,7 +214,7 @@ class FinetuneRequest(BaseModel): from_checkpoint: str | None = None # hf related fields hf_api_token: str | None = None - hf_repo_to_upload: str | None = None + hf_output_repo_name: str | None = None class FinetuneResponse(BaseModel): From f4c020d16a2c6d145d085d281b868f11e9fa9a46 Mon Sep 17 00:00:00 2001 From: Egor Timofeev Date: Mon, 7 Jul 2025 15:19:32 +0200 Subject: [PATCH 7/9] Fix --- src/together/cli/api/finetune.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/together/cli/api/finetune.py b/src/together/cli/api/finetune.py index 44be62c6..673fde71 100644 --- a/src/together/cli/api/finetune.py +++ b/src/together/cli/api/finetune.py @@ -247,7 +247,7 @@ def create( simpo_gamma: float | None, from_checkpoint: str, hf_api_token: str | None, - hf_repo_to_upload: str | None, + hf_output_repo_name: str | None, ) -> None: """Start fine-tuning""" client: Together = ctx.obj @@ -285,7 +285,7 @@ def create( simpo_gamma=simpo_gamma, from_checkpoint=from_checkpoint, hf_api_token=hf_api_token, - hf_repo_to_upload=hf_repo_to_upload, + hf_output_repo_name=hf_output_repo_name, ) if model is None and from_checkpoint is None: From 00b48b49844b787bb9fc1a73f5e8bf12ebc23e19 Mon Sep 17 00:00:00 2001 From: Egor Timofeev Date: Mon, 7 Jul 2025 15:21:22 +0200 Subject: [PATCH 8/9] Fix --- src/together/cli/api/finetune.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/together/cli/api/finetune.py b/src/together/cli/api/finetune.py index 673fde71..417b6ddd 100644 --- a/src/together/cli/api/finetune.py +++ b/src/together/cli/api/finetune.py @@ -207,7 +207,7 @@ def fine_tuning(ctx: click.Context) -> None: help="HF API token to use to upload a checkpoint to a private repo", ) @click.option( - "--hf-repo-to-upload", + "--hf-output-repo-name", type=str, default=None, help="HF repo to upload the fine-tuned model to", From 0fd15769be770f37c9a8994fa52123af65c0f34b Mon Sep 17 00:00:00 2001 From: Egor Timofeev Date: Mon, 7 Jul 2025 17:10:53 +0200 Subject: [PATCH 9/9] Wording --- src/together/cli/api/finetune.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/together/cli/api/finetune.py b/src/together/cli/api/finetune.py index 417b6ddd..eaff63b7 100644 --- a/src/together/cli/api/finetune.py +++ b/src/together/cli/api/finetune.py @@ -204,7 +204,7 @@ def fine_tuning(ctx: click.Context) -> None: "--hf-api-token", type=str, default=None, - help="HF API token to use to upload a checkpoint to a private repo", + help="HF API token to use for uploading a checkpoint to a private repo", ) @click.option( "--hf-output-repo-name",