-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #133 from IBM/develop
Release 2023.08.21
- Loading branch information
Showing
15 changed files
with
441 additions
and
15 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
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,76 @@ | ||
import os | ||
from pathlib import Path | ||
|
||
from dotenv import load_dotenv | ||
|
||
from genai.credentials import Credentials | ||
from genai.schemas.tunes_params import ( | ||
CreateTuneHyperParams, | ||
CreateTuneParams, | ||
DownloadAssetsParams, | ||
TunesListParams, | ||
) | ||
from genai.services import FileManager, TuneManager | ||
|
||
load_dotenv() | ||
API_KEY = os.getenv("GENAI_KEY", None) | ||
ENDPOINT = os.getenv("GENAI_API", None) | ||
|
||
creds = Credentials(api_key=API_KEY, api_endpoint=ENDPOINT) | ||
|
||
|
||
print("\n=============== UPLOAD LOCAL FILE FOR TUNING ================") | ||
file_path = str(Path(__file__).parent / "file_to_tune.jsonl") | ||
print(" {} \n".format(file_path)) | ||
|
||
file_uploaded = FileManager.upload_file(credentials=creds, file_path=file_path, purpose="tune") | ||
print("File uploaded: \n", file_uploaded) | ||
|
||
|
||
print("\n======================== CREATE TUNE ========================") | ||
file_ids = [file_uploaded.id] | ||
hyperparams = CreateTuneHyperParams(verbalizer='classify { "red", "yellow" } Input: {{input}} Output:') | ||
|
||
params = CreateTuneParams( | ||
name="Tune Manager Classification", | ||
model_id="google/flan-t5-xl", | ||
method_id="mpt", | ||
task_id="classification", | ||
training_file_ids=file_ids, | ||
parameters=hyperparams, | ||
) | ||
|
||
tune_created = TuneManager.create_tune(credentials=creds, params=params) | ||
print("\nNew tune: \n", tune_created) | ||
|
||
|
||
print("\n======================= GET TUNE BY ID ======================") | ||
t = tune_created.id | ||
tune_get = TuneManager.get_tune(credentials=creds, tune_id=t) | ||
print("\nGet tune result: \n", tune_get) | ||
|
||
print("\n======================== LIST TUNES =========================") | ||
list_params = TunesListParams(limit=5, offset=0) | ||
tune_list = TuneManager.list_tunes(credentials=creds, params=list_params) | ||
for t in tune_list.results: | ||
print("\nTune ID:", t.id, ", Tune Name:", t.name) | ||
|
||
|
||
print("\n================ LIST EXISTING TUNE METHODS ================") | ||
tune_methods = TuneManager.get_tune_methods(credentials=creds) | ||
print("\n Available Tune Methods:\n") | ||
for t in tune_methods.results: | ||
print("Method ID:", t.id, ", Method name:", t.name) | ||
|
||
|
||
print("\n=================== DOWNLOAD TUNE ASSETS ===================") | ||
# content can be: logs or enconder. The download will only be available when the tune is complete. | ||
tune = tune_list.results[0].id | ||
assets_params = DownloadAssetsParams(id=tune, content="encoder") | ||
tune_assets = TuneManager.download_tune_assets(credentials=creds, params=assets_params) | ||
print("\n Tune assets:", tune_assets) | ||
|
||
|
||
print("\n======================== DELETE TUNE ========================") | ||
tune_delete = TuneManager.delete_tune(credentials=creds, tune_id=tune) | ||
print("\nDelete tune response: \n", tune_delete) |
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,44 @@ | ||
import os | ||
from pathlib import Path | ||
|
||
from dotenv import load_dotenv | ||
|
||
from genai.credentials import Credentials | ||
from genai.schemas.tunes_params import CreateTuneParams | ||
from genai.services import FileManager, TuneManager | ||
|
||
load_dotenv() | ||
API_KEY = os.getenv("GENAI_KEY", None) | ||
ENDPOINT = os.getenv("GENAI_API", None) | ||
|
||
creds = Credentials(api_key=API_KEY, api_endpoint=ENDPOINT) | ||
|
||
# # UPLOAD FILE | ||
# file_path = "<path-to-file>" | ||
print("======================== UPLOAD LOCAL FILE ========================") | ||
file_path = str(Path(__file__).parent / "file_to_tune.jsonl") | ||
print(" {} \n".format(file_path)) | ||
|
||
upload_file = FileManager.upload_file(credentials=creds, file_path=file_path, purpose="tune") | ||
print("File uploaded: \n", upload_file) | ||
|
||
print("\n===================== GET UPLOADED FILE ID ========================") | ||
file_list = FileManager.list_files(credentials=creds) | ||
for f in file_list.results: | ||
if f.file_name == "file_to_tune.jsonl": | ||
file_id = f.id | ||
break | ||
print("Uploaded file has id = {}\n".format(file_id)) | ||
|
||
print("\n================= CREATE TUNE FOR GENERATION TASK ==================") | ||
|
||
tunes_params = CreateTuneParams( | ||
name="flan-t5-xl", | ||
model_id="google/flan-t5-xl", | ||
method_id="pt", | ||
task_id="generation", | ||
training_file_ids=[file_id], | ||
) | ||
|
||
tune_create = TuneManager.create_tune(credentials=creds, params=tunes_params) | ||
print("Created tune has the id: \n ", tune_create.id) |
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
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
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
Oops, something went wrong.