-
Notifications
You must be signed in to change notification settings - Fork 462
Training Configurations Add/Update implementation #4873
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
Open
A-Artemis
wants to merge
4
commits into
develop
Choose a base branch
from
aurelien/training-configuration-endpoint
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
4 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
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
97 changes: 97 additions & 0 deletions
97
application/backend/app/api/endpoints/training_configurations.py
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,97 @@ | ||
# Copyright (C) 2025 Intel Corporation | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import logging | ||
from typing import Annotated | ||
from uuid import UUID | ||
|
||
from fastapi import APIRouter, Depends, HTTPException, status | ||
|
||
from app.api.dependencies import get_training_configuration_service | ||
from app.schemas import TrainingConfiguration | ||
from app.services import ResourceNotFoundError | ||
from app.services.training_configuration_service import TrainingConfigurationService | ||
|
||
logger = logging.getLogger(__name__) | ||
router = APIRouter(prefix="/api/projects/{project_id}/training_configuration", tags=["Training Configuration"]) | ||
|
||
|
||
@router.get("", response_model=TrainingConfiguration) | ||
def get_training_configuration( | ||
training_configuration_service: Annotated[ | ||
TrainingConfigurationService, Depends(get_training_configuration_service) | ||
], | ||
project_id: UUID, | ||
model_architecture_id: str | None = None, | ||
model_revision_id: UUID | None = None, | ||
) -> TrainingConfiguration: | ||
""" | ||
Get the training configuration for a project. | ||
|
||
If model_architecture_id is provided, returns configuration for that specific model architecture. | ||
If model_revision_id is provided, returns configuration for a specific trained model. | ||
If neither is provided, returns only general task-related configuration. | ||
Note: model_architecture_id and model_revision_id cannot be used together. | ||
|
||
Args: | ||
training_configuration_service (TrainingConfigurationService): The training configuration service. | ||
project_id (UUID): The unique identifier of the project. | ||
model_architecture_id (Optional[str]): The model architecture ID for specific configuration retrieval. | ||
model_revision_id (Optional[UUID]): The model revision ID for specific configuration retrieval. | ||
|
||
Returns: | ||
TrainingConfiguration: The training configuration details. | ||
""" | ||
try: | ||
return training_configuration_service.get_training_configuration( | ||
project_id=project_id, | ||
model_architecture_id=model_architecture_id, | ||
model_revision_id=model_revision_id, | ||
) | ||
except ResourceNotFoundError as e: | ||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=str(e)) | ||
except ValueError as e: | ||
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=str(e)) | ||
|
||
|
||
@router.patch("", status_code=status.HTTP_204_NO_CONTENT) | ||
def update_training_configuration( | ||
training_configuration_service: Annotated[ | ||
TrainingConfigurationService, Depends(get_training_configuration_service) | ||
], | ||
project_id: UUID, | ||
training_config_update: dict, | ||
model_architecture_id: str | None = None, | ||
) -> None: | ||
""" | ||
Update the training configuration for a project. | ||
|
||
- If model_architecture_id is provided, updates configuration for that specific model architecture. | ||
- If not provided, updates the general task-related configuration. | ||
Note: model_architecture_id cannot be used with model_revision_id for updates. | ||
|
||
Request body should contain elements of the configuration hierarchy to update: | ||
```json | ||
{ | ||
"dataset_preparation": {...}, | ||
"training": {...}, | ||
"evaluation": {...} | ||
} | ||
``` | ||
|
||
Args: | ||
training_configuration_service (TrainingConfigurationService): The training configuration service. | ||
project_id (UUID): The unique identifier of the project. | ||
training_config_update (dict): The configuration updates to apply. | ||
model_architecture_id (Optional[str]): The model architecture ID for specific configuration update. | ||
""" | ||
try: | ||
training_configuration_service.update_training_configuration( | ||
project_id=project_id, | ||
training_config_update=training_config_update, | ||
model_architecture_id=model_architecture_id, | ||
) | ||
except ResourceNotFoundError as e: | ||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=str(e)) | ||
except ValueError as e: | ||
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=str(e)) |
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
69 changes: 69 additions & 0 deletions
69
application/backend/app/repositories/training_configuration_repo.py
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,69 @@ | ||
# Copyright (C) 2025 Intel Corporation | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
|
||
from sqlalchemy.orm import Session | ||
|
||
from app.db.schema import TrainingConfigurationDB | ||
from app.repositories.base import BaseRepository | ||
|
||
|
||
class TrainingConfigurationRepository(BaseRepository[TrainingConfigurationDB]): | ||
def __init__(self, db: Session) -> None: | ||
super().__init__(db, TrainingConfigurationDB) | ||
|
||
def get_by_project_and_model_architecture( | ||
self, | ||
project_id: str, | ||
model_architecture_id: str | None = None, | ||
) -> TrainingConfigurationDB | None: | ||
""" | ||
Get training configuration by project ID and optional model architecture ID. | ||
Args: | ||
project_id (str): The ID of the project. | ||
model_architecture_id (str | None): The ID of the model architecture. | ||
""" | ||
return ( | ||
self.db.query(TrainingConfigurationDB) | ||
A-Artemis marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
.filter( | ||
TrainingConfigurationDB.project_id == project_id, | ||
TrainingConfigurationDB.model_architecture_id == model_architecture_id, | ||
) | ||
.first() | ||
) | ||
|
||
def create_or_update( | ||
self, | ||
project_id: str, | ||
model_architecture_id: str | None, | ||
configuration_data: dict, | ||
) -> TrainingConfigurationDB: | ||
""" | ||
Create or update a training configuration. | ||
If a configuration for the given project and model architecture exists, it is updated. | ||
Otherwise, a new configuration is created. | ||
Args: | ||
project_id (str): The ID of the project. | ||
model_architecture_id (str | None): The ID of the model architecture. | ||
configuration_data (dict): The configuration data to store. | ||
Returns: | ||
TrainingConfigurationDB: The created or updated training configuration. | ||
""" | ||
existing = self.get_by_project_and_model_architecture(project_id, model_architecture_id) | ||
|
||
if existing: | ||
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. Do we need |
||
existing.configuration_data = configuration_data | ||
self.save(existing) | ||
return existing | ||
|
||
new_config = TrainingConfigurationDB( | ||
project_id=project_id, | ||
model_architecture_id=model_architecture_id, | ||
configuration_data=configuration_data, | ||
) | ||
self.save(new_config) | ||
return new_config |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.