Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: finetuning CLI #1199

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions truss/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import rich.table
import rich.traceback
import rich_click as click
import yaml
from InquirerPy import inquirer
from rich.console import Console

Expand Down Expand Up @@ -76,6 +77,13 @@
"row_styles": ["red"],
},
},
{
"name": "Finetune",
"commands": ["finetune"],
"table_styles": { # type: ignore
"row_styles": ["orange"],
},
},
]
}

Expand Down Expand Up @@ -814,6 +822,7 @@ def init_chain(
def _load_example_chainlet_code() -> str:
try:
from truss_chains import example_chainlet

# if the example is faulty, a validation error would be raised
except Exception as e:
raise Exception("Failed to load starter code. Please notify support.") from e
Expand Down Expand Up @@ -1326,9 +1335,41 @@ def _get_truss_from_directory(target_directory: Optional[str] = None):
return truss.load(target_directory)


# Finetuning Stuff #########################################################################


@truss_cli.command()
@click.argument("file_path", type=click.Path(exists=True))
@click.argument("name", type=str, required=True)
@click.option(
"--remote",
type=str,
required=False,
help="Name of the remote in .trussrc to push to",
)
def finetune(
file_path: Path,
name: str,
remote: str,
):
"""Finetune on Baseten"""
print(f"We finetuning now with file: {file_path}, name: {name}")

if not remote:
remote = inquire_remote_name(RemoteFactory.get_available_config_names())

remote_provider = RemoteFactory.create(remote=remote)
with open(file_path, "r") as file:
config = yaml.safe_load(file)

id = remote_provider.finetune(name, config)
print(id)


truss_cli.add_command(container)
truss_cli.add_command(image)
truss_cli.add_command(chains)
truss_cli.add_command(finetune)

if __name__ == "__main__":
truss_cli()
22 changes: 22 additions & 0 deletions truss/remote/baseten/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,28 @@ def _post_graphql_query(self, query_string: str) -> dict:
raise ApiError(message, error_code)
return resp_dict

def kickoff_finetuning_job(
self,
name: str,
config: str,
client_version: str,
):
query_string = f"""
mutation {{
kickoff_finetuning_job(
config: "{config}",
client_version: "{client_version}"
name: "{name}"
s3_key: ""
) {{
id
}}
}}
"""

resp = self._post_graphql_query(query_string)
return resp["data"]["kickoff_finetuning_job"]

def model_s3_upload_credentials(self):
query_string = """
{
Expand Down
11 changes: 11 additions & 0 deletions truss/remote/baseten/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from pathlib import Path
from typing import TYPE_CHECKING, List, NamedTuple, Optional, Tuple

import truss
import yaml
from requests import ReadTimeout
from truss.constants import PRODUCTION_ENVIRONMENT_NAME
Expand Down Expand Up @@ -115,6 +116,16 @@ def get_chainlets(
)
]

def finetune(self, name: str, config: dict):
encoded_config_str = base64_encoded_json_str(config)

ft_job_id = self.api.kickoff_finetuning_job(
name=name,
config=encoded_config_str,
client_version=f"truss=={truss.version()}",
)
return ft_job_id

def push( # type: ignore
self,
truss_handle: TrussHandle,
Expand Down
Loading