-
Notifications
You must be signed in to change notification settings - Fork 58
[AQUA][STMD]Updated logic to deploy single ft model #1269
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
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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
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 |
---|---|---|
|
@@ -8,9 +8,10 @@ | |
from pydantic import BaseModel, Field, model_validator | ||
|
||
from ads.aqua import logger | ||
from ads.aqua.common.entities import AquaMultiModelRef | ||
from ads.aqua.common.entities import AquaMultiModelRef, LoraModuleSpec | ||
from ads.aqua.common.enums import Tags | ||
from ads.aqua.common.errors import AquaValueError | ||
from ads.aqua.common.utils import is_valid_ocid | ||
from ads.aqua.config.utils.serializer import Serializable | ||
from ads.aqua.constants import ( | ||
AQUA_FINE_TUNE_MODEL_VERSION, | ||
|
@@ -717,34 +718,65 @@ def validate_ft_model_v2( | |
f"Invalid fine-tuned model ID '{base_model.id}': for fine tuned models like Phi4, the deployment is not supported. " | ||
) | ||
|
||
def validate_base_model(self, model_id: str) -> None: | ||
def validate_base_model(self, model_id: str) -> Union[str, AquaMultiModelRef]: | ||
""" | ||
Validates the input base model for single model deployment configuration. | ||
|
||
Validation Criteria: | ||
- Fine-tuned models are not supported in single model deployment. | ||
- Legacy fine-tuned models will be deployed as single model deployment. | ||
- Fine-tuned models v2 will be deployed as stacked deployment. | ||
|
||
Parameters | ||
---------- | ||
model_id : str | ||
The OCID of DataScienceModel instance. | ||
|
||
Returns | ||
------- | ||
Union[str, AquaMultiModelRef] | ||
A string of model id or an instance of AquaMultiModelRef. | ||
|
||
Raises | ||
------ | ||
ConfigValidationError | ||
If any of the above conditions are violated. | ||
""" | ||
base_model = DataScienceModel.from_id(model_id) | ||
if Tags.AQUA_FINE_TUNED_MODEL_TAG in base_model.freeform_tags: | ||
logger.error( | ||
"Validation failed: Fine-tuned model ID '%s' is not supported for single-model deployment.", | ||
base_model.id, | ||
) | ||
raise ConfigValidationError( | ||
f"Invalid base model ID '{base_model.id}': " | ||
"single-model deployment does not support fine-tuned models. " | ||
f"Please deploy the fine-tuned model '{base_model.id}' as a stacked model deployment instead." | ||
freeform_tags = base_model.freeform_tags | ||
aqua_fine_tuned_model = freeform_tags.get( | ||
Tags.AQUA_FINE_TUNED_MODEL_TAG, UNKNOWN | ||
) | ||
if aqua_fine_tuned_model: | ||
fine_tuned_model_version = freeform_tags.get( | ||
Tags.AQUA_FINE_TUNE_MODEL_VERSION, UNKNOWN | ||
) | ||
# TODO: revisit to block deploying single fine tuned model after AQUA UI is integrated. | ||
if fine_tuned_model_version.lower() == AQUA_FINE_TUNE_MODEL_VERSION: | ||
# extracts base model id from tag 'aqua_fine_tuned_model' and builds AquaMultiModelRef instance for stacked deployment. | ||
logger.debug( | ||
f"Detected base model is fine-tuned model {AQUA_FINE_TUNE_MODEL_VERSION} and switched to stack deployment." | ||
) | ||
segments = aqua_fine_tuned_model.split("#") | ||
if not segments or not is_valid_ocid(segments[0]): | ||
logger.error( | ||
"Validation failed: Fine-tuned model ID '%s' is not supported for model deployment.", | ||
base_model.id, | ||
) | ||
raise ConfigValidationError( | ||
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. I'm not sure if that error makes sense. We might need to give user a better sense what's going on and how to fix the problem. |
||
f"Invalid fine-tuned model ID '{base_model.id}': missing or invalid tag '{Tags.AQUA_FINE_TUNED_MODEL_TAG}' format. " | ||
f"Make sure tag '{Tags.AQUA_FINE_TUNED_MODEL_TAG}' is added with format <service_model_id>#<service_model_name>." | ||
) | ||
# reset the model_id and models in create_model_deployment_details for stack deployment | ||
self.model_id = None | ||
self.models = [ | ||
AquaMultiModelRef( | ||
model_id=segments[0], | ||
fine_tune_weights=[LoraModuleSpec(model_id=base_model.id)], | ||
) | ||
] | ||
return self.models[0] | ||
|
||
return model_id | ||
|
||
class Config: | ||
extra = "allow" | ||
|
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
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.
The return sections is missing in the docstring.
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.
Added