-
Notifications
You must be signed in to change notification settings - Fork 0
add price estimation #194
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
add price estimation #194
Changes from all commits
95f72d3
d712a48
43b45d9
63e0899
b35fb31
e520426
e2bffac
d4f9cee
4dfdf92
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,9 +27,16 @@ | |
| async_to_custom_streamed_response_wrapper, | ||
| ) | ||
| from .._base_client import make_request_options | ||
| from ..lib.types.fine_tuning import FinetuneResponse as FinetuneResponseLib, FinetuneTrainingLimits | ||
| from ..lib.types.fine_tuning import ( | ||
| FinetuneResponse as FinetuneResponseLib, | ||
| FinetuneTrainingLimits, | ||
| ) | ||
| from ..types.finetune_response import FinetuneResponse | ||
| from ..lib.resources.fine_tuning import get_model_limits, async_get_model_limits, create_finetune_request | ||
| from ..lib.resources.fine_tuning import ( | ||
| get_model_limits, | ||
| async_get_model_limits, | ||
| create_finetune_request, | ||
| ) | ||
| from ..types.fine_tuning_list_response import FineTuningListResponse | ||
| from ..types.fine_tuning_cancel_response import FineTuningCancelResponse | ||
| from ..types.fine_tuning_delete_response import FineTuningDeleteResponse | ||
|
|
@@ -39,6 +46,12 @@ | |
|
|
||
| __all__ = ["FineTuningResource", "AsyncFineTuningResource"] | ||
|
|
||
| _WARNING_MESSAGE_INSUFFICIENT_FUNDS = ( | ||
| "The estimated price of the fine-tuning job is {} which is significantly " | ||
| "greater than your current credit limit and balance combined. " | ||
| "It will likely get cancelled due to insufficient funds. " | ||
| "Proceed at your own risk." | ||
| ) | ||
|
|
||
| class FineTuningResource(SyncAPIResource): | ||
| @cached_property | ||
|
|
@@ -180,7 +193,7 @@ def create( | |
| pass | ||
| model_limits = get_model_limits(self._client, str(model_name)) | ||
|
|
||
| finetune_request = create_finetune_request( | ||
| finetune_request, training_type_cls, training_method_cls = create_finetune_request( | ||
| model_limits=model_limits, | ||
| training_file=training_file, | ||
| model=model, | ||
|
|
@@ -219,11 +232,32 @@ def create( | |
| hf_output_repo_name=hf_output_repo_name, | ||
| ) | ||
|
|
||
|
|
||
| price_estimation_result = self.estimate_price( | ||
| training_file=training_file, | ||
| from_checkpoint=from_checkpoint or Omit(), | ||
| validation_file=validation_file or Omit(), | ||
| model=model or "", | ||
| n_epochs=finetune_request.n_epochs, | ||
| n_evals=finetune_request.n_evals or 0, | ||
| training_type=training_type_cls, | ||
| training_method=training_method_cls, | ||
| ) | ||
|
|
||
|
|
||
| if verbose: | ||
| rprint( | ||
| "Submitting a fine-tuning job with the following parameters:", | ||
| finetune_request, | ||
| ) | ||
| if not price_estimation_result.allowed_to_proceed: | ||
| rprint( | ||
| "[red]" | ||
| + _WARNING_MESSAGE_INSUFFICIENT_FUNDS.format( | ||
| price_estimation_result.estimated_total_price # pyright: ignore[reportPossiblyUnboundVariable] | ||
| ) | ||
| + "[/red]", | ||
| ) | ||
| parameter_payload = finetune_request.model_dump(exclude_none=True) | ||
|
|
||
| return self._client.post( | ||
|
|
@@ -691,7 +725,7 @@ async def create( | |
| pass | ||
| model_limits = await async_get_model_limits(self._client, str(model_name)) | ||
|
|
||
| finetune_request = create_finetune_request( | ||
| finetune_request, training_type_cls, training_method_cls = create_finetune_request( | ||
| model_limits=model_limits, | ||
| training_file=training_file, | ||
| model=model, | ||
|
|
@@ -730,11 +764,32 @@ async def create( | |
| hf_output_repo_name=hf_output_repo_name, | ||
| ) | ||
|
|
||
|
|
||
| price_estimation_result = await self.estimate_price( | ||
| training_file=training_file, | ||
| from_checkpoint=from_checkpoint or Omit(), | ||
| validation_file=validation_file or Omit(), | ||
| model=model or "", | ||
| n_epochs=finetune_request.n_epochs, | ||
| n_evals=finetune_request.n_evals or 0, | ||
| training_type=training_type_cls, | ||
| training_method=training_method_cls, | ||
| ) | ||
|
|
||
|
|
||
| if verbose: | ||
| rprint( | ||
| "Submitting a fine-tuning job with the following parameters:", | ||
| finetune_request, | ||
| ) | ||
| if not price_estimation_result.allowed_to_proceed: | ||
| rprint( | ||
| "[red]" | ||
| + _WARNING_MESSAGE_INSUFFICIENT_FUNDS.format( | ||
| price_estimation_result.estimated_total_price # pyright: ignore[reportPossiblyUnboundVariable] | ||
| ) | ||
| + "[/red]", | ||
| ) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any way all of this logic could be put inside the This should be fine - but this file is generated, so I think minimizing code within this file while help avoid conflicts.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can't access |
||
| parameter_payload = finetune_request.model_dump(exclude_none=True) | ||
|
|
||
| return await self._client.post( | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.