From f70976bef3bd531d6bf969886fbe4315d3189b77 Mon Sep 17 00:00:00 2001 From: Nicholas Broad Date: Tue, 6 May 2025 14:25:26 -0700 Subject: [PATCH 01/11] add .value --- src/together/resources/finetune.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/together/resources/finetune.py b/src/together/resources/finetune.py index 275d6839..0469e1f2 100644 --- a/src/together/resources/finetune.py +++ b/src/together/resources/finetune.py @@ -614,12 +614,12 @@ def download( ) url += "&checkpoint=model_output_path" elif isinstance(ft_job.training_type, LoRATrainingType): - if checkpoint_type == DownloadCheckpointType.DEFAULT: - checkpoint_type = DownloadCheckpointType.MERGED + if checkpoint_type == DownloadCheckpointType.DEFAULT.value: + checkpoint_type = DownloadCheckpointType.MERGED.value - if checkpoint_type == DownloadCheckpointType.MERGED: + if checkpoint_type == DownloadCheckpointType.MERGED.value: url += f"&checkpoint={DownloadCheckpointType.MERGED.value}" - elif checkpoint_type == DownloadCheckpointType.ADAPTER: + elif checkpoint_type == DownloadCheckpointType.ADAPTER.value: url += f"&checkpoint={DownloadCheckpointType.ADAPTER.value}" else: raise ValueError( From eec18ed4a0804ba7c786e9c3f4a3b50329b4b94c Mon Sep 17 00:00:00 2001 From: Nicholas Broad Date: Thu, 8 May 2025 00:27:02 -0700 Subject: [PATCH 02/11] Change type hints to include str, convert to str --- src/together/resources/finetune.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/together/resources/finetune.py b/src/together/resources/finetune.py index 0469e1f2..0696dff1 100644 --- a/src/together/resources/finetune.py +++ b/src/together/resources/finetune.py @@ -2,7 +2,7 @@ import re from pathlib import Path -from typing import List, Literal +from typing import List, Literal, Union from rich import print as rprint @@ -570,7 +570,7 @@ def download( *, output: Path | str | None = None, checkpoint_step: int | None = None, - checkpoint_type: DownloadCheckpointType = DownloadCheckpointType.DEFAULT, + checkpoint_type: Union[DownloadCheckpointType, str] = DownloadCheckpointType.DEFAULT, ) -> FinetuneDownloadResult: """ Downloads compressed fine-tuned model or checkpoint to local disk. @@ -583,7 +583,7 @@ def download( Defaults to None. checkpoint_step (int, optional): Specifies step number for checkpoint to download. Defaults to -1 (download the final model) - checkpoint_type (CheckpointType, optional): Specifies which checkpoint to download. + checkpoint_type (Union[CheckpointType, str], optional): Specifies which checkpoint to download. Defaults to CheckpointType.DEFAULT. Returns: @@ -607,8 +607,12 @@ def download( ft_job = self.retrieve(id) + # convert to str + if isinstance(checkpoint_type, DownloadCheckpointType): + checkpoint_type = checkpoint_type.value + if isinstance(ft_job.training_type, FullTrainingType): - if checkpoint_type != DownloadCheckpointType.DEFAULT: + if checkpoint_type != DownloadCheckpointType.DEFAULT.value: raise ValueError( "Only DEFAULT checkpoint type is allowed for FullTrainingType" ) @@ -617,10 +621,8 @@ def download( if checkpoint_type == DownloadCheckpointType.DEFAULT.value: checkpoint_type = DownloadCheckpointType.MERGED.value - if checkpoint_type == DownloadCheckpointType.MERGED.value: - url += f"&checkpoint={DownloadCheckpointType.MERGED.value}" - elif checkpoint_type == DownloadCheckpointType.ADAPTER.value: - url += f"&checkpoint={DownloadCheckpointType.ADAPTER.value}" + if checkpoint_type in {DownloadCheckpointType.MERGED.value, DownloadCheckpointType.ADAPTER.value}: + url += f"&checkpoint={checkpoint_type}" else: raise ValueError( f"Invalid checkpoint type for LoRATrainingType: {checkpoint_type}" From 90d5a6df7590330e7b0ebaae5e315a35d476052b Mon Sep 17 00:00:00 2001 From: Nicholas Broad Date: Thu, 8 May 2025 00:32:47 -0700 Subject: [PATCH 03/11] Cast to enum instead of str --- src/together/resources/finetune.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/together/resources/finetune.py b/src/together/resources/finetune.py index 0696dff1..ee267518 100644 --- a/src/together/resources/finetune.py +++ b/src/together/resources/finetune.py @@ -608,21 +608,21 @@ def download( ft_job = self.retrieve(id) # convert to str - if isinstance(checkpoint_type, DownloadCheckpointType): - checkpoint_type = checkpoint_type.value + if isinstance(checkpoint_type, str): + checkpoint_type = DownloadCheckpointType(checkpoint_type) if isinstance(ft_job.training_type, FullTrainingType): - if checkpoint_type != DownloadCheckpointType.DEFAULT.value: + if checkpoint_type != DownloadCheckpointType.DEFAULT: raise ValueError( "Only DEFAULT checkpoint type is allowed for FullTrainingType" ) url += "&checkpoint=model_output_path" elif isinstance(ft_job.training_type, LoRATrainingType): - if checkpoint_type == DownloadCheckpointType.DEFAULT.value: - checkpoint_type = DownloadCheckpointType.MERGED.value + if checkpoint_type == DownloadCheckpointType.DEFAULT: + checkpoint_type = DownloadCheckpointType.MERGED - if checkpoint_type in {DownloadCheckpointType.MERGED.value, DownloadCheckpointType.ADAPTER.value}: - url += f"&checkpoint={checkpoint_type}" + if checkpoint_type in {DownloadCheckpointType.MERGED, DownloadCheckpointType.ADAPTER}: + url += f"&checkpoint={checkpoint_type.value}" else: raise ValueError( f"Invalid checkpoint type for LoRATrainingType: {checkpoint_type}" From 9b15370bdc27d70ca7b521fbe7482161fb934692 Mon Sep 17 00:00:00 2001 From: Nicholas Broad Date: Thu, 8 May 2025 00:52:26 -0700 Subject: [PATCH 04/11] format and add try/except --- src/together/resources/finetune.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/together/resources/finetune.py b/src/together/resources/finetune.py index ee267518..b3bb5074 100644 --- a/src/together/resources/finetune.py +++ b/src/together/resources/finetune.py @@ -570,7 +570,9 @@ def download( *, output: Path | str | None = None, checkpoint_step: int | None = None, - checkpoint_type: Union[DownloadCheckpointType, str] = DownloadCheckpointType.DEFAULT, + checkpoint_type: Union[ + DownloadCheckpointType, str + ] = DownloadCheckpointType.DEFAULT, ) -> FinetuneDownloadResult: """ Downloads compressed fine-tuned model or checkpoint to local disk. @@ -609,7 +611,13 @@ def download( # convert to str if isinstance(checkpoint_type, str): - checkpoint_type = DownloadCheckpointType(checkpoint_type) + try: + checkpoint_type = DownloadCheckpointType(checkpoint_type.lower()) + except ValueError: + enum_strs = ", ".join([e.value for e in DownloadCheckpointType]) + raise ValueError( + f"Invalid checkpoint type: {checkpoint_type}. Choose one of {{{enum_strs}}}." + ) if isinstance(ft_job.training_type, FullTrainingType): if checkpoint_type != DownloadCheckpointType.DEFAULT: @@ -621,7 +629,10 @@ def download( if checkpoint_type == DownloadCheckpointType.DEFAULT: checkpoint_type = DownloadCheckpointType.MERGED - if checkpoint_type in {DownloadCheckpointType.MERGED, DownloadCheckpointType.ADAPTER}: + if checkpoint_type in { + DownloadCheckpointType.MERGED, + DownloadCheckpointType.ADAPTER, + }: url += f"&checkpoint={checkpoint_type.value}" else: raise ValueError( From b1fe94ec2e7461ba7115771f593962e0ad1d5269 Mon Sep 17 00:00:00 2001 From: Nicholas Broad Date: Thu, 8 May 2025 15:22:19 -0700 Subject: [PATCH 05/11] fix comment --- src/together/resources/finetune.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/together/resources/finetune.py b/src/together/resources/finetune.py index b3bb5074..20b540ee 100644 --- a/src/together/resources/finetune.py +++ b/src/together/resources/finetune.py @@ -609,7 +609,7 @@ def download( ft_job = self.retrieve(id) - # convert to str + # convert str to DownloadCheckpointType if isinstance(checkpoint_type, str): try: checkpoint_type = DownloadCheckpointType(checkpoint_type.lower()) From 8507a392eeaebba8ff73b44f681479d286b525d7 Mon Sep 17 00:00:00 2001 From: Nicholas Broad Date: Mon, 12 May 2025 10:25:34 -0700 Subject: [PATCH 06/11] remove square brackets in comprehension Co-authored-by: Max Ryabinin --- src/together/resources/finetune.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/together/resources/finetune.py b/src/together/resources/finetune.py index 20b540ee..c87df543 100644 --- a/src/together/resources/finetune.py +++ b/src/together/resources/finetune.py @@ -614,7 +614,7 @@ def download( try: checkpoint_type = DownloadCheckpointType(checkpoint_type.lower()) except ValueError: - enum_strs = ", ".join([e.value for e in DownloadCheckpointType]) + enum_strs = ", ".join(e.value for e in DownloadCheckpointType) raise ValueError( f"Invalid checkpoint type: {checkpoint_type}. Choose one of {{{enum_strs}}}." ) From c966a2156296c67f506bb4825306b89cc5b6515b Mon Sep 17 00:00:00 2001 From: Nicholas Broad Date: Mon, 12 May 2025 10:28:03 -0700 Subject: [PATCH 07/11] version 1.5.7 -> 1.5.8 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 94226c18..2b5ccafd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,7 +12,7 @@ build-backend = "poetry.masonry.api" [tool.poetry] name = "together" -version = "1.5.7" +version = "1.5.8" authors = ["Together AI "] description = "Python client for Together's Cloud Platform!" readme = "README.md" From fb2d097a387e19fda62b17f3c09e6bbd4ac257a7 Mon Sep 17 00:00:00 2001 From: Nicholas Broad Date: Tue, 13 May 2025 11:21:58 -0700 Subject: [PATCH 08/11] fix types --- src/together/resources/finetune.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/together/resources/finetune.py b/src/together/resources/finetune.py index 690ece90..effbfe17 100644 --- a/src/together/resources/finetune.py +++ b/src/together/resources/finetune.py @@ -2,7 +2,7 @@ import re from pathlib import Path -from typing import List, Literal, Union, Literal +from typing import List, Dict, Literal, Union from rich import print as rprint From aede7378b282529e24b75848b77620c1167aac43 Mon Sep 17 00:00:00 2001 From: Nicholas Broad Date: Tue, 13 May 2025 11:23:58 -0700 Subject: [PATCH 09/11] 1.5.8->1.5.9 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 2b5ccafd..a3f5353e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,7 +12,7 @@ build-backend = "poetry.masonry.api" [tool.poetry] name = "together" -version = "1.5.8" +version = "1.5.9" authors = ["Together AI "] description = "Python client for Together's Cloud Platform!" readme = "README.md" From 17a9744afec17ee4f1304dd81de6f2e57d82e864 Mon Sep 17 00:00:00 2001 From: Nicholas Broad Date: Tue, 13 May 2025 11:27:39 -0700 Subject: [PATCH 10/11] union -> | --- src/together/resources/finetune.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/together/resources/finetune.py b/src/together/resources/finetune.py index effbfe17..e239a6d0 100644 --- a/src/together/resources/finetune.py +++ b/src/together/resources/finetune.py @@ -2,7 +2,7 @@ import re from pathlib import Path -from typing import List, Dict, Literal, Union +from typing import List, Dict, Literal from rich import print as rprint @@ -545,9 +545,7 @@ def download( *, output: Path | str | None = None, checkpoint_step: int | None = None, - checkpoint_type: Union[ - DownloadCheckpointType, str - ] = DownloadCheckpointType.DEFAULT, + checkpoint_type: DownloadCheckpointType | str = DownloadCheckpointType.DEFAULT, ) -> FinetuneDownloadResult: """ Downloads compressed fine-tuned model or checkpoint to local disk. From 763ee6df927c2cb12d0cfaa80d54ae3f49c638fa Mon Sep 17 00:00:00 2001 From: Nicholas Broad Date: Tue, 13 May 2025 11:28:20 -0700 Subject: [PATCH 11/11] change union -> | in docstring --- src/together/resources/finetune.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/together/resources/finetune.py b/src/together/resources/finetune.py index e239a6d0..1f494fc1 100644 --- a/src/together/resources/finetune.py +++ b/src/together/resources/finetune.py @@ -558,7 +558,7 @@ def download( Defaults to None. checkpoint_step (int, optional): Specifies step number for checkpoint to download. Defaults to -1 (download the final model) - checkpoint_type (Union[CheckpointType, str], optional): Specifies which checkpoint to download. + checkpoint_type (CheckpointType | str, optional): Specifies which checkpoint to download. Defaults to CheckpointType.DEFAULT. Returns: