Skip to content

Commit

Permalink
Improve report messages with rich
Browse files Browse the repository at this point in the history
  • Loading branch information
mryab committed Sep 24, 2024
1 parent 88902e1 commit f1d3e21
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ repos:
hooks:
- id: mypy
args: [--strict]
additional_dependencies: [types-requests, types-tqdm, types-tabulate, types-click, types-filelock, types-Pillow, pyarrow-stubs, pydantic, aiohttp]
additional_dependencies: [types-requests, types-tqdm, types-tabulate, types-click, types-filelock, types-Pillow, rich, pyarrow-stubs, pydantic, aiohttp]
exclude: ^tests/
18 changes: 12 additions & 6 deletions src/together/cli/api/finetune.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from __future__ import annotations

import json
from datetime import datetime
from textwrap import wrap

import click
from click.core import ParameterSource # type: ignore[attr-defined]
from rich import print as rich_print
from tabulate import tabulate

from together import Together
Expand Down Expand Up @@ -145,14 +147,18 @@ def create(
lora_trainable_modules=lora_trainable_modules,
suffix=suffix,
wandb_api_key=wandb_api_key,
verbose=True,
)

click.echo(json.dumps(response.model_dump(exclude_none=True), indent=4))

# TODO: Remove it after the 21st of August
log_warn(
"The default value of batch size has been changed from 32 to 16 since together version >= 1.2.6"
)
report_string = f"Successfully submitted a fine-tuning job {response.id}"
if response.created_at is not None:
created_time = datetime.strptime(
response.created_at, "%Y-%m-%dT%H:%M:%S.%f%z"
)
# created_at reports UTC time, we use .astimezone() to convert to local time
formatted_time = created_time.astimezone().strftime("%m/%d/%Y, %H:%M:%S")
report_string += f" at {formatted_time}"
rich_print(report_string)
else:
click.echo("No confirmation received, stopping job launch")

Expand Down
14 changes: 11 additions & 3 deletions src/together/resources/finetune.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from pathlib import Path

from rich import print

from together.abstract import api_requestor
from together.filemanager import DownloadManager
from together.together_response import TogetherResponse
Expand Down Expand Up @@ -43,6 +45,7 @@ def create(
lora_trainable_modules: str | None = "all-linear",
suffix: str | None = None,
wandb_api_key: str | None = None,
verbose: bool = False,
) -> FinetuneResponse:
"""
Method to initiate a fine-tuning job
Expand All @@ -67,6 +70,8 @@ def create(
Defaults to None.
wandb_api_key (str, optional): API key for Weights & Biases integration.
Defaults to None.
verbose (bool, optional): whether to print the job parameters before submitting a request.
Defaults to False.
Returns:
FinetuneResponse: Object containing information about fine-tuning job.
Expand All @@ -85,7 +90,7 @@ def create(
lora_trainable_modules=lora_trainable_modules,
)

parameter_payload = FinetuneRequest(
finetune_request = FinetuneRequest(
model=model,
training_file=training_file,
validation_file=validation_file,
Expand All @@ -97,7 +102,10 @@ def create(
training_type=training_type,
suffix=suffix,
wandb_key=wandb_api_key,
).model_dump(exclude_none=True)
)
if verbose:
print(finetune_request)
parameter_payload = finetune_request.model_dump(exclude_none=True)

response, _, _ = requestor.request(
options=TogetherRequest(
Expand Down Expand Up @@ -266,7 +274,7 @@ def download(
raise ValueError(
"Only DEFAULT checkpoint type is allowed for FullTrainingType"
)
url += f"&checkpoint=modelOutputPath"
url += "&checkpoint=modelOutputPath"
elif isinstance(ft_job.training_type, LoRATrainingType):
if checkpoint_type == DownloadCheckpointType.DEFAULT:
checkpoint_type = DownloadCheckpointType.MERGED
Expand Down

0 comments on commit f1d3e21

Please sign in to comment.