From 1867bb340fec2907a81cc497ac1b9a97f589239f Mon Sep 17 00:00:00 2001 From: Huan Chen Date: Mon, 8 Jan 2024 19:10:43 +0000 Subject: [PATCH 1/5] fix: update max_output_token limitation. --- bigframes/ml/llm.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/bigframes/ml/llm.py b/bigframes/ml/llm.py index 5beb54a32d..bf3c6f88a0 100644 --- a/bigframes/ml/llm.py +++ b/bigframes/ml/llm.py @@ -138,7 +138,8 @@ def predict( max_output_tokens (int, default 128): Maximum number of tokens that can be generated in the response. Specify a lower value for shorter responses and a higher value for longer responses. A token may be smaller than a word. A token is approximately four characters. 100 tokens correspond to roughly 60-80 words. - Default 128. Possible values [1, 1024]. + Default 128. For the 'text-bison' model, possible values are in the range [1, 1024]. For the 'text-bison-32k' model, possible values are in the range [1, 8196]. + Please ensure that the specified value for max_output_tokens is within the appropriate range for the model being used. top_k (int, default 40): Top-k changes how the model selects tokens for output. A top-k of 1 means the selected token is the most probable among all tokens @@ -162,12 +163,25 @@ def predict( # Params reference: https://cloud.google.com/vertex-ai/docs/generative-ai/learn/models if temperature < 0.0 or temperature > 1.0: raise ValueError(f"temperature must be [0.0, 1.0], but is {temperature}.") - if max_output_tokens not in range(1, 1025): + + if ( + self.model_name == _TEXT_GENERATOR_BISON_ENDPOINT + and max_output_tokens not in range(1, 1025) + ): raise ValueError( - f"max_output_token must be [1, 1024], but is {max_output_tokens}." + f"max_output_token must be [1, 1024] for TextBison model, but is {max_output_tokens}." ) + elif ( + self.model_name == _TEXT_GENERATOR_BISON_32K_ENDPOINT + and max_output_tokens not in range(1, 8197) + ): + raise ValueError( + f"max_output_token must be [1, 8196] for TextBison 32k model, but is {max_output_tokens}." + ) + if top_k not in range(1, 41): raise ValueError(f"top_k must be [1, 40], but is {top_k}.") + if top_p < 0.0 or top_p > 1.0: raise ValueError(f"top_p must be [0.0, 1.0], but is {top_p}.") From 9fe50d3f741398b56e47dc4024775ecebeb69144 Mon Sep 17 00:00:00 2001 From: Huan Chen Date: Mon, 8 Jan 2024 19:17:22 +0000 Subject: [PATCH 2/5] update format --- bigframes/ml/llm.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bigframes/ml/llm.py b/bigframes/ml/llm.py index bf3c6f88a0..7dd0b94a10 100644 --- a/bigframes/ml/llm.py +++ b/bigframes/ml/llm.py @@ -163,7 +163,7 @@ def predict( # Params reference: https://cloud.google.com/vertex-ai/docs/generative-ai/learn/models if temperature < 0.0 or temperature > 1.0: raise ValueError(f"temperature must be [0.0, 1.0], but is {temperature}.") - + if ( self.model_name == _TEXT_GENERATOR_BISON_ENDPOINT and max_output_tokens not in range(1, 1025) @@ -178,7 +178,7 @@ def predict( raise ValueError( f"max_output_token must be [1, 8196] for TextBison 32k model, but is {max_output_tokens}." ) - + if top_k not in range(1, 41): raise ValueError(f"top_k must be [1, 40], but is {top_k}.") From 921d28a1a3b1f8818a543e83a58fb3be59fe74e5 Mon Sep 17 00:00:00 2001 From: Huan Chen Date: Tue, 9 Jan 2024 22:42:02 +0000 Subject: [PATCH 3/5] update if-else condition. --- bigframes/ml/llm.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/bigframes/ml/llm.py b/bigframes/ml/llm.py index 931d8edd91..11f08fc6e5 100644 --- a/bigframes/ml/llm.py +++ b/bigframes/ml/llm.py @@ -193,10 +193,7 @@ def predict( raise ValueError( f"max_output_token must be [1, 1024] for TextBison model, but is {max_output_tokens}." ) - elif ( - self.model_name == _TEXT_GENERATOR_BISON_32K_ENDPOINT - and max_output_tokens not in range(1, 8197) - ): + else: raise ValueError( f"max_output_token must be [1, 8196] for TextBison 32k model, but is {max_output_tokens}." ) From c556dffe39240193410db8c8ffb75ee6fe4da820 Mon Sep 17 00:00:00 2001 From: Huan Chen Date: Tue, 9 Jan 2024 23:41:18 +0000 Subject: [PATCH 4/5] update else --- bigframes/ml/llm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bigframes/ml/llm.py b/bigframes/ml/llm.py index 11f08fc6e5..0ec796ea83 100644 --- a/bigframes/ml/llm.py +++ b/bigframes/ml/llm.py @@ -193,7 +193,7 @@ def predict( raise ValueError( f"max_output_token must be [1, 1024] for TextBison model, but is {max_output_tokens}." ) - else: + elif max_output_tokens not in range(1, 8197): raise ValueError( f"max_output_token must be [1, 8196] for TextBison 32k model, but is {max_output_tokens}." ) From d198ffc0c0b6ba6860af9d2c1afab54009a20ae5 Mon Sep 17 00:00:00 2001 From: Huan Chen Date: Wed, 10 Jan 2024 04:51:19 +0000 Subject: [PATCH 5/5] logic update. --- bigframes/ml/llm.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bigframes/ml/llm.py b/bigframes/ml/llm.py index 0ec796ea83..3607000323 100644 --- a/bigframes/ml/llm.py +++ b/bigframes/ml/llm.py @@ -193,7 +193,11 @@ def predict( raise ValueError( f"max_output_token must be [1, 1024] for TextBison model, but is {max_output_tokens}." ) - elif max_output_tokens not in range(1, 8197): + + if ( + self.model_name == _TEXT_GENERATOR_BISON_32K_ENDPOINT + and max_output_tokens not in range(1, 8197) + ): raise ValueError( f"max_output_token must be [1, 8196] for TextBison 32k model, but is {max_output_tokens}." )