forked from BeastByteAI/scikit-llm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Iryna Kondrashchenko <[email protected]>
- Loading branch information
1 parent
54c70f4
commit 78e6eb0
Showing
19 changed files
with
829 additions
and
417 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -161,3 +161,4 @@ cython_debug/ | |
test.py | ||
tmp.ipynb | ||
tmp.py | ||
*.pickle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
# ordering is important here to prevent circular imports | ||
from skllm.models.gpt_zero_shot_clf import ( | ||
from skllm.models.gpt.gpt_zero_shot_clf import ( | ||
MultiLabelZeroShotGPTClassifier, | ||
ZeroShotGPTClassifier, | ||
) | ||
from skllm.models.gpt_few_shot_clf import FewShotGPTClassifier | ||
from skllm.models.gpt_dyn_few_shot_clf import DynamicFewShotGPTClassifier | ||
from skllm.models.gpt.gpt_few_shot_clf import FewShotGPTClassifier | ||
from skllm.models.gpt.gpt_dyn_few_shot_clf import DynamicFewShotGPTClassifier |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from time import sleep | ||
|
||
from vertexai.preview.language_models import ChatModel, TextGenerationModel | ||
|
||
# TODO reduce code duplication for retrying logic | ||
|
||
|
||
def get_completion(model: str, text: str, max_retries: int = 3): | ||
for _ in range(max_retries): | ||
try: | ||
if model.startswith("text-"): | ||
model = TextGenerationModel.from_pretrained(model) | ||
else: | ||
model = TextGenerationModel.get_tuned_model(model) | ||
response = model.predict(text, temperature=0.0) | ||
return response.text | ||
except Exception as e: | ||
error_msg = str(e) | ||
error_type = type(e).__name__ | ||
sleep(3) | ||
print( | ||
f"Could not obtain the completion after {max_retries} retries: `{error_type} ::" | ||
f" {error_msg}`" | ||
) | ||
|
||
|
||
def get_completion_chat_mode(model: str, context: str, text: str, max_retries: int = 3): | ||
for _ in range(max_retries): | ||
try: | ||
model = ChatModel.from_pretrained(model) | ||
chat = model.start_chat(context=context) | ||
response = chat.send_message(text, temperature=0.0) | ||
return response.text | ||
except Exception as e: | ||
error_msg = str(e) | ||
error_type = type(e).__name__ | ||
sleep(3) | ||
print( | ||
f"Could not obtain the completion after {max_retries} retries: `{error_type} ::" | ||
f" {error_msg}`" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from pandas import DataFrame | ||
from vertexai.preview.language_models import TextGenerationModel | ||
|
||
|
||
def tune(model: str, data: DataFrame, train_steps: int = 100): | ||
model = TextGenerationModel.from_pretrained(model) | ||
model.tune_model( | ||
training_data=data, | ||
train_steps=train_steps, | ||
tuning_job_location="europe-west4", # the only supported training location atm | ||
tuned_model_location="us-central1", # the only supported deployment location atm | ||
) | ||
return model # ._job |
Oops, something went wrong.