-
Notifications
You must be signed in to change notification settings - Fork 23
M 6107719447 check finetuner status #133
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
Merged
thiago-aixplain
merged 5 commits into
development
from
M-6107719447-checkFinetunerStatus
Mar 21, 2024
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b7fa1ec
Finetune status object
c265335
New finetune status checker
a8f9607
Covering some None cases
4322050
Finetune status checker updates and new unit tests
b55b14b
Merge branch 'development' into M-6107719447-checkFinetunerStatus
thiago-aixplain File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,43 @@ | ||
| __author__ = "thiagocastroferreira" | ||
|
|
||
| """ | ||
| Copyright 2024 The aiXplain SDK authors | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
|
|
||
| Author: Duraikrishna Selvaraju, Thiago Castro Ferreira, Shreyas Sharma and Lucas Pavanelli | ||
| Date: February 21st 2024 | ||
| Description: | ||
| Asset Enum | ||
| """ | ||
|
|
||
| from enum import Enum | ||
| from typing import Text | ||
|
|
||
| class AssetStatus(Text, Enum): | ||
| HIDDEN = 'hidden' | ||
| SCHEDULED = 'scheduled' | ||
| ONBOARDING = 'onboarding' | ||
| ONBOARDED = 'onboarded' | ||
| PENDING = 'pending' | ||
| FAILED = 'failed' | ||
| TRAINING = 'training' | ||
| REJECTED = 'rejected' | ||
| ENABLING = 'enabling' | ||
| DELETING = 'deleting' | ||
| DISABLED = 'disabled' | ||
| DELETED = 'deleted' | ||
| IN_PROGRESS = 'in_progress' | ||
| COMPLETED = 'completed' | ||
| CANCELING = 'canceling' | ||
| CANCELED = 'canceled' |
This file contains hidden or 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 hidden or 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,36 @@ | ||
| __author__ = "thiagocastroferreira" | ||
|
|
||
| """ | ||
| Copyright 2024 The aiXplain SDK authors | ||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| Author: Duraikrishna Selvaraju, Thiago Castro Ferreira, Shreyas Sharma and Lucas Pavanelli | ||
| Date: February 21st 2024 | ||
| Description: | ||
| FinetuneCost Class | ||
| """ | ||
|
|
||
| from aixplain.enums.asset_status import AssetStatus | ||
| from dataclasses import dataclass | ||
| from dataclasses_json import dataclass_json | ||
| from typing import Optional, Text | ||
|
|
||
| @dataclass_json | ||
| @dataclass | ||
| class FinetuneStatus(object): | ||
| status: "AssetStatus" | ||
| model_status: "AssetStatus" | ||
| epoch: Optional[float] = None | ||
| training_loss: Optional[float] = None | ||
| validation_loss: Optional[float] = None | ||
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -20,7 +20,6 @@ | |
| Description: | ||
| Model Class | ||
| """ | ||
|
|
||
| import time | ||
| import json | ||
| import logging | ||
|
|
@@ -251,23 +250,65 @@ def run_async(self, data: Union[Text, Dict], name: Text = "model_process", param | |
| response["error"] = msg | ||
| return response | ||
|
|
||
| def check_finetune_status(self): | ||
| def check_finetune_status(self, after_epoch: Optional[int] = None): | ||
|
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. Please add def check_finetune_status(self, after_epoch: Optional[int] = None) -> FinetuneStatus: |
||
| """Check the status of the FineTune model. | ||
|
|
||
| Args: | ||
| after_epoch (Optional[int], optional): status after a given epoch. Defaults to None. | ||
|
|
||
| Raises: | ||
| Exception: If the 'TEAM_API_KEY' is not provided. | ||
|
|
||
| Returns: | ||
| str: The status of the FineTune model. | ||
| FinetuneStatus: The status of the FineTune model. | ||
| """ | ||
| from aixplain.enums.asset_status import AssetStatus | ||
| from aixplain.modules.finetune.status import FinetuneStatus | ||
| headers = {"x-api-key": self.api_key, "Content-Type": "application/json"} | ||
| resp = None | ||
| try: | ||
| url = urljoin(self.backend_url, f"sdk/models/{self.id}") | ||
| url = urljoin(self.backend_url, f"sdk/finetune/{self.id}/ml-logs") | ||
| logging.info(f"Start service for GET Check FineTune status Model - {url} - {headers}") | ||
| r = _request_with_retry("get", url, headers=headers) | ||
| resp = r.json() | ||
| status = resp["status"] | ||
| logging.info(f"Response for GET Check FineTune status Model - Id {self.id} / Status {status}.") | ||
| finetune_status = AssetStatus(resp["finetuneStatus"]) | ||
| model_status = AssetStatus(resp["modelStatus"]) | ||
| logs = sorted(resp["logs"], key=lambda x: float(x["epoch"])) | ||
|
|
||
| target_epoch = None | ||
| if after_epoch is not None: | ||
| logs = [log for log in logs if float(log["epoch"]) > after_epoch] | ||
| if len(logs) > 0: | ||
| target_epoch = float(logs[0]["epoch"]) | ||
| elif len(logs) > 0: | ||
| target_epoch = float(logs[-1]["epoch"]) | ||
|
|
||
| if target_epoch is not None: | ||
| log = None | ||
| for log_ in logs: | ||
| if int(log_["epoch"]) == target_epoch: | ||
| if log is None: | ||
| log = log_ | ||
| else: | ||
| if log_["trainLoss"] is not None: | ||
| log["trainLoss"] = log_["trainLoss"] | ||
| if log_["evalLoss"] is not None: | ||
| log["evalLoss"] = log_["evalLoss"] | ||
|
|
||
| status = FinetuneStatus( | ||
| status=finetune_status, | ||
| model_status=model_status, | ||
| epoch=float(log["epoch"]) if "epoch" in log and log["epoch"] is not None else None, | ||
| training_loss=float(log["trainLoss"]) if "trainLoss" in log and log["trainLoss"] is not None else None, | ||
| validation_loss=float(log["evalLoss"]) if "evalLoss" in log and log["evalLoss"] is not None else None, | ||
| ) | ||
| else: | ||
| status = FinetuneStatus( | ||
| status=finetune_status, | ||
| model_status=model_status, | ||
| ) | ||
|
|
||
| logging.info(f"Response for GET Check FineTune status Model - Id {self.id} / Status {status.status.value}.") | ||
| return status | ||
| except Exception as e: | ||
| message = "" | ||
|
|
||
This file contains hidden or 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 hidden or 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,41 @@ | ||
| { | ||
| "finetuneStatus": "onboarding", | ||
| "modelStatus": "onboarded", | ||
| "logs": [ | ||
| { | ||
| "epoch": 1, | ||
| "learningRate": 9.938725490196079e-05, | ||
| "trainLoss": 0.1, | ||
| "evalLoss": 0.1106, | ||
| "step": 10 | ||
| }, | ||
| { | ||
| "epoch": 2, | ||
| "learningRate": 9.877450980392157e-05, | ||
| "trainLoss": 0.2, | ||
| "evalLoss": 0.0482, | ||
| "step": 20 | ||
| }, | ||
| { | ||
| "epoch": 3, | ||
| "learningRate": 9.816176470588235e-05, | ||
| "trainLoss": 0.3, | ||
| "evalLoss": 0.0251, | ||
| "step": 30 | ||
| }, | ||
| { | ||
| "epoch": 4, | ||
| "learningRate": 9.754901960784314e-05, | ||
| "trainLoss": 0.9, | ||
| "evalLoss": 0.0228, | ||
| "step": 40 | ||
| }, | ||
| { | ||
| "epoch": 5, | ||
| "learningRate": 9.693627450980392e-05, | ||
| "trainLoss": 0.4, | ||
| "evalLoss": 0.0217, | ||
| "step": 50 | ||
| } | ||
| ] | ||
| } |
This file contains hidden or 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,49 @@ | ||
| { | ||
| "id": "65fb26268fe9153a6c9c29c4", | ||
| "finetuneStatus": "in_progress", | ||
| "modelStatus": "training", | ||
| "logs": [ | ||
| { | ||
| "epoch": 1, | ||
| "learningRate": null, | ||
| "trainLoss": null, | ||
| "validationLoss": null, | ||
| "step": null, | ||
| "evalLoss": 2.684150457382, | ||
| "totalFlos": null, | ||
| "evalRuntime": 12.4129, | ||
| "trainRuntime": null, | ||
| "evalStepsPerSecond": 0.322, | ||
| "trainStepsPerSecond": null, | ||
| "evalSamplesPerSecond": 16.112 | ||
| }, | ||
| { | ||
| "epoch": 2, | ||
| "learningRate": null, | ||
| "trainLoss": null, | ||
| "validationLoss": null, | ||
| "step": null, | ||
| "evalLoss": 2.596168756485, | ||
| "totalFlos": null, | ||
| "evalRuntime": 11.8249, | ||
| "trainRuntime": null, | ||
| "evalStepsPerSecond": 0.338, | ||
| "trainStepsPerSecond": null, | ||
| "evalSamplesPerSecond": 16.913 | ||
| }, | ||
| { | ||
| "epoch": 2, | ||
| "learningRate": null, | ||
| "trainLoss": 2.657801408034, | ||
| "validationLoss": null, | ||
| "step": null, | ||
| "evalLoss": null, | ||
| "totalFlos": 11893948284928, | ||
| "evalRuntime": null, | ||
| "trainRuntime": 221.7946, | ||
| "evalStepsPerSecond": null, | ||
| "trainStepsPerSecond": 0.117, | ||
| "evalSamplesPerSecond": null | ||
| } | ||
| ] | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here it should be: