Skip to content
Merged
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
9 changes: 8 additions & 1 deletion src/together/commands/finetune.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ def _add_create(parser: argparse._SubParsersAction[argparse.ArgumentParser]) ->
required=True,
type=str,
)
subparser.add_argument(
"--estimate-price",
"-e",
help="Estimate the price of the fine tune job",
required=False,
action="store_true",
)
# subparser.add_argument(
# "--validation-file",
# "-v",
Expand Down Expand Up @@ -288,7 +295,7 @@ def _run_create(args: argparse.Namespace) -> None:
# fp16=not args.fp32,
# checkpoint_steps=args.checkpoint_steps,
suffix=args.suffix,
# wandb_api_key=args.wandb_api_key if not args.no_wandb_api_key else None,
estimate_price=args.estimate_price,
)

print(json.dumps(response, indent=4))
Expand Down
64 changes: 62 additions & 2 deletions src/together/finetune.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,35 @@
logger = get_logger(str(__name__), log_level=together.log_level)


# this will change soon to be data driven and give a clearer estimate
def model_param_count(name: str) -> int:
pcount = {
"togethercomputer/RedPajama-INCITE-7B-Chat": 6857302016,
"togethercomputer/RedPajama-INCITE-7B-Base": 6857302016,
"togethercomputer/RedPajama-INCITE-7B-Instruct": 6857302016,
"togethercomputer/RedPajama-INCITE-Chat-3B-v1": 2775864320,
"togethercomputer/RedPajama-INCITE-Base-3B-v1": 2775864320,
"togethercomputer/RedPajama-INCITE-Instruct-3B-v1": 2775864320,
"togethercomputer/Pythia-Chat-Base-7B": 6857302016,
"togethercomputer/llama-2-7b": 6738415616,
"togethercomputer/llama-2-7b-chat": 6738415616,
"togethercomputer/llama-2-13b": 13015864320,
"togethercomputer/llama-2-13b-chat": 13015864320,
"togethercomputer/LLaMA-2-7B-32K": 6738415616,
"togethercomputer/Llama-2-7B-32K-Instruct": 6738415616,
"togethercomputer/CodeLlama-7b": 6738546688,
"togethercomputer/CodeLlama-7b-Python": 6738546688,
"togethercomputer/CodeLlama-7b-Instruct": 6738546688,
"togethercomputer/CodeLlama-13b": 13016028160,
"togethercomputer/CodeLlama-13b-Python": 13016028160,
"togethercomputer/CodeLlama-13b-Instruct": 13016028160,
}
try:
return pcount[name]
except Exception:
return 0


class Finetune:
def __init__(
self,
Expand All @@ -23,7 +52,7 @@ def create(
self,
training_file: str, # training file_id
# validation_file: Optional[str] = None, # validation file_id
model: Optional[str] = None,
model: str,
n_epochs: int = 1,
n_checkpoints: Optional[int] = 1,
batch_size: Optional[int] = 32,
Expand All @@ -37,7 +66,7 @@ def create(
suffix: Optional[
str
] = None, # resulting finetuned model name will include the suffix
# wandb_api_key: Optional[str] = None,
estimate_price: bool = False,
) -> Dict[Any, Any]:
if n_epochs is None or n_epochs < 1:
logger.fatal("The number of epochs must be specified")
Expand Down Expand Up @@ -94,6 +123,37 @@ def create(
logger.critical(training_file_feedback)
raise together.FileTypeError(training_file_feedback)

if estimate_price:
param_size = model_param_count(model)
if param_size == 0:
error = f"Unknown model {model}. Cannot estimate price. Please check the name of the model"
raise together.FileTypeError(error)

for file in uploaded_files["data"]:
if file["id"] == parameter_payload["training_file"]:
## This is the file
byte_count = file["bytes"]
token_estimate = int(int(file["bytes"]) / 4)
data = {
"method": "together_getPrice",
"params": [
model,
"FT",
{
"tokens": token_estimate,
"epochs": n_epochs,
"parameters": model_param_count(model),
},
],
"id": 1,
}
r = requests.post("https://computer.together.xyz/", json=data)
estimate = r.json()["result"]["total"]
estimate /= 1000000000
training_file_feedback = f"A rough price estimate for this job is ${estimate:.2f} USD. The estimated number of tokens is {token_estimate} tokens. Accurate pricing is not available until full tokenization has been performed. The actual price might be higher or lower depending on how the data is tokenized. Our token estimate is based on the number of bytes in the training file, {byte_count} bytes, divided by an average token length of 4 bytes. We currently have a per job minimum of $5.00 USD."
print(training_file_feedback)
exit()

# Send POST request to SUBMIT FINETUNE JOB
# HTTP headers for authorization
headers = {
Expand Down