Repository navigation
chore(fine-tuning): Remove Unused fine-tuning module and endpoints #1429
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
Ayush8923
wants to merge
1
commit into
chore/remove-doc-transformation
from
chore/remove-fine-tuning
Open
Changes from all commits
Commits
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
283 changes: 283 additions & 0 deletions
283
backend/app/alembic/versions/097_drop_fine_tuning_and_model_evaluation_tables.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,283 @@ | ||
| """drop fine_tuning and model_evaluation | ||
|
|
||
| Revision ID: 097 | ||
| Revises: 096 | ||
| Create Date: 2026-12-04 00:00:00.000000 | ||
|
|
||
| The Fine-tuning and Model evaluation modules were removed, so nothing reads or | ||
| writes these tables any more. Rows are lost on upgrade; downgrade restores the schema | ||
| as it stood at 096 (empty tables) so older code can boot, not the data. | ||
|
|
||
| model_evaluation references fine_tuning, so it is dropped first and recreated last. | ||
| """ | ||
|
|
||
| import sqlalchemy as sa | ||
| from alembic import op | ||
| from sqlalchemy.dialects import postgresql | ||
|
|
||
| revision = "097" | ||
| down_revision = "096" | ||
| branch_labels = None | ||
| depends_on = None | ||
|
|
||
|
|
||
| def upgrade(): | ||
| op.drop_table("model_evaluation") | ||
| op.drop_table("fine_tuning") | ||
| op.execute("DROP TYPE IF EXISTS modelevaluationstatus") | ||
| op.execute("DROP TYPE IF EXISTS finetuningstatus") | ||
|
|
||
|
|
||
| def downgrade(): | ||
| lifecycle_status = ("pending", "running", "completed", "failed") | ||
| finetuning_status = postgresql.ENUM(*lifecycle_status, name="finetuningstatus") | ||
| modelevaluation_status = postgresql.ENUM( | ||
| *lifecycle_status, name="modelevaluationstatus" | ||
| ) | ||
|
|
||
| op.create_table( | ||
| "fine_tuning", | ||
| sa.Column( | ||
| "base_model", | ||
| sa.String(), | ||
| nullable=False, | ||
| comment="Base model used for fine-tuning", | ||
| ), | ||
| sa.Column( | ||
| "split_ratio", | ||
| sa.Float(), | ||
| nullable=False, | ||
| comment="Train/test split ratio for the dataset", | ||
| ), | ||
| sa.Column( | ||
| "document_id", | ||
| sa.Uuid(), | ||
| nullable=False, | ||
| comment="Reference to the training document", | ||
| ), | ||
| sa.Column( | ||
| "training_file_id", | ||
| sa.String(), | ||
| nullable=True, | ||
| comment="OpenAI training file identifier", | ||
| ), | ||
| sa.Column( | ||
| "system_prompt", | ||
| sa.Text(), | ||
| nullable=False, | ||
| comment="System prompt used during fine-tuning", | ||
| ), | ||
| sa.Column( | ||
| "id", | ||
| sa.Integer(), | ||
| nullable=False, | ||
| comment="Unique identifier for the fine-tuning job", | ||
| ), | ||
| sa.Column( | ||
| "provider_job_id", | ||
| sa.String(), | ||
| nullable=True, | ||
| comment="Fine-tuning job ID returned by the provider", | ||
| ), | ||
| sa.Column( | ||
| "status", | ||
| finetuning_status, | ||
| server_default="pending", | ||
| nullable=False, | ||
| comment="Current status of the fine-tuning job", | ||
| ), | ||
| sa.Column( | ||
| "fine_tuned_model", | ||
| sa.String(), | ||
| nullable=True, | ||
| comment="Name of the resulting fine-tuned model", | ||
| ), | ||
| sa.Column( | ||
| "train_data_s3_object", | ||
| sa.String(), | ||
| nullable=True, | ||
| comment="S3 URL of the training data", | ||
| ), | ||
| sa.Column( | ||
| "test_data_s3_object", | ||
| sa.String(), | ||
| nullable=True, | ||
| comment="S3 URL of the testing data", | ||
| ), | ||
| sa.Column( | ||
| "error_message", | ||
| sa.String(), | ||
| nullable=True, | ||
| comment="Error message if the job failed", | ||
| ), | ||
| sa.Column( | ||
| "project_id", | ||
| sa.Integer(), | ||
| nullable=False, | ||
| comment="Reference to the project", | ||
| ), | ||
| sa.Column( | ||
| "organization_id", | ||
| sa.Integer(), | ||
| nullable=False, | ||
| comment="Reference to the organization", | ||
| ), | ||
| sa.Column( | ||
| "inserted_at", | ||
| sa.DateTime(), | ||
| nullable=False, | ||
| comment="Timestamp when the job was created", | ||
| ), | ||
| sa.Column( | ||
| "updated_at", | ||
| sa.DateTime(), | ||
| nullable=False, | ||
| comment="Timestamp when the job was last updated", | ||
| ), | ||
| sa.Column( | ||
| "deleted_at", | ||
| sa.DateTime(), | ||
| nullable=True, | ||
| comment="Timestamp when the job was deleted", | ||
| ), | ||
| sa.ForeignKeyConstraint(["document_id"], ["document.id"], ondelete="CASCADE"), | ||
| sa.ForeignKeyConstraint( | ||
| ["organization_id"], ["organization.id"], ondelete="CASCADE" | ||
| ), | ||
| sa.ForeignKeyConstraint(["project_id"], ["project.id"], ondelete="CASCADE"), | ||
| sa.PrimaryKeyConstraint("id"), | ||
| ) | ||
| op.create_index("ix_fine_tuning_project_id", "fine_tuning", ["project_id"]) | ||
| op.create_index( | ||
| "ix_fine_tuning_document_project", "fine_tuning", ["document_id", "project_id"] | ||
| ) | ||
|
|
||
| op.create_table( | ||
| "model_evaluation", | ||
| sa.Column( | ||
| "fine_tuning_id", | ||
| sa.Integer(), | ||
| nullable=False, | ||
| comment="Reference to the fine-tuning job", | ||
| ), | ||
| sa.Column( | ||
| "id", | ||
| sa.Integer(), | ||
| nullable=False, | ||
| comment="Unique identifier for the model evaluation", | ||
| ), | ||
| sa.Column( | ||
| "document_id", | ||
| sa.Uuid(), | ||
| nullable=False, | ||
| comment="Reference to the evaluation document", | ||
| ), | ||
| sa.Column( | ||
| "fine_tuned_model", | ||
| sa.String(), | ||
| nullable=False, | ||
| comment="Name of the fine-tuned model being evaluated", | ||
| ), | ||
| sa.Column( | ||
| "test_data_s3_object", | ||
| sa.String(), | ||
| nullable=False, | ||
| comment="S3 URI of the testing data", | ||
| ), | ||
| sa.Column( | ||
| "base_model", | ||
| sa.String(), | ||
| nullable=False, | ||
| comment="Base model used for fine-tuning", | ||
| ), | ||
| sa.Column( | ||
| "split_ratio", | ||
| sa.Float(), | ||
| nullable=False, | ||
| comment="Train/test split ratio used", | ||
| ), | ||
| sa.Column( | ||
| "system_prompt", | ||
| sa.Text(), | ||
| nullable=False, | ||
| comment="System prompt used during evaluation", | ||
| ), | ||
| sa.Column( | ||
| "score", | ||
| sa.JSON(), | ||
| nullable=True, | ||
| comment="Evaluation scores per metric (e.g., MCC)", | ||
| ), | ||
| sa.Column( | ||
| "prediction_data_s3_object", | ||
| sa.String(), | ||
| nullable=True, | ||
| comment="S3 URL where the prediction data is stored", | ||
| ), | ||
| sa.Column( | ||
| "status", | ||
| modelevaluation_status, | ||
| server_default="pending", | ||
| nullable=False, | ||
| comment="Current status of the evaluation", | ||
| ), | ||
| sa.Column( | ||
| "error_message", | ||
| sa.String(), | ||
| nullable=True, | ||
| comment="Error message if evaluation failed", | ||
| ), | ||
| sa.Column( | ||
| "project_id", | ||
| sa.Integer(), | ||
| nullable=False, | ||
| comment="Reference to the project", | ||
| ), | ||
| sa.Column( | ||
| "organization_id", | ||
| sa.Integer(), | ||
| nullable=False, | ||
| comment="Reference to the organization", | ||
| ), | ||
| sa.Column( | ||
| "inserted_at", | ||
| sa.DateTime(), | ||
| nullable=False, | ||
| comment="Timestamp when the evaluation was created", | ||
| ), | ||
| sa.Column( | ||
| "updated_at", | ||
| sa.DateTime(), | ||
| nullable=False, | ||
| comment="Timestamp when the evaluation was last updated", | ||
| ), | ||
| sa.Column( | ||
| "deleted_at", | ||
| sa.DateTime(), | ||
| nullable=True, | ||
| comment="Timestamp when the evaluation was deleted", | ||
| ), | ||
| sa.ForeignKeyConstraint(["document_id"], ["document.id"], ondelete="CASCADE"), | ||
| sa.ForeignKeyConstraint( | ||
| ["fine_tuning_id"], ["fine_tuning.id"], ondelete="CASCADE" | ||
| ), | ||
| sa.ForeignKeyConstraint( | ||
| ["organization_id"], ["organization.id"], ondelete="CASCADE" | ||
| ), | ||
| sa.ForeignKeyConstraint(["project_id"], ["project.id"], ondelete="CASCADE"), | ||
| sa.PrimaryKeyConstraint("id"), | ||
| ) | ||
| op.create_index( | ||
| "ix_model_evaluation_project_id", "model_evaluation", ["project_id"] | ||
| ) | ||
| op.create_index( | ||
| "ix_model_evaluation_fine_tuning_project", | ||
| "model_evaluation", | ||
| ["fine_tuning_id", "project_id"], | ||
| ) | ||
| op.create_index( | ||
| "ix_model_evaluation_document_project_updated_at", | ||
| "model_evaluation", | ||
| ["document_id", "project_id", sa.text("updated_at DESC")], | ||
| postgresql_where=sa.text("deleted_at IS NULL"), | ||
| ) | ||
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 |
|---|---|---|
| @@ -1,8 +1,7 @@ | ||
| Permanently delete a document. | ||
|
|
||
| The file is removed from cloud storage (e.g., S3) and the database record is deleted. This cannot be undone. Records | ||
| that depend on the document, such as its transformed documents, fine-tuning jobs and model | ||
| evaluations, are deleted along with it. | ||
| that depend on the document, such as its transformed documents, are deleted along with it. | ||
|
|
||
| Works on both active and soft-deleted documents. Collections and knowledge bases that contain this document are not | ||
| touched. |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
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.
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.
🟡 (optional) Admins who hard-delete a project or organization during a release rollout get a 500 with "relation fine_tuning does not exist". Migration 097 drops the tables before the ECS rollout replaces the old tasks. Those old tasks still map
Project.fine_tuningwithcascade_delete=True, sosession.delete(project)first SELECTs fromfine_tuning. Fix: remove the code in one release and drop the tables in a later one, so no running version still maps them. One way is to merge this change without 097 and add the drop migration afterwards.Why this was flagged
In .github/workflows/create-release.yml, the "Run database migrations" step runs
alembic upgrade headand waits for it to finish. Only then does "Deploy backend service" start the rollout, which has a 15-minute timeout, so old tasks keep serving traffic in that window. On base, backend/app/models/project.py mapsfine_tuning: list["FineTuning"] = Relationship(back_populates="project", cascade_delete=True)without passive_deletes. Sohard_delete_project(crud/project.py,session.delete(project)) loads that collection, andhard_delete_organizationdoes the same throughOrganization.project(cascade_delete=True). Once 097 upgrade() has droppedfine_tuning, that load raises ProgrammingError UndefinedTable on old tasks. DELETE requests through api/routes/project.py:253 and api/routes/organization.py:166 then return 500, and the delete is rolled back. The FKondelete="CASCADE"at the database level does not help, because the ORM issues the SELECT before any DELETE. Before this PR the tables exist, so these deletes work.Verification: Trigger: an admin hard-deletes a project or organization while old backend tasks are still serving, after migration 097 has run. Old tasks stay in service until the new ones are healthy. In the base crud/project.py (lines 180-181),
hard_delete_projectcallssession.delete(project). The ORM cascade SELECTs from fine_tuning, which migration 097 has dropped, so the request returns a 500.