Skip to content
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

feat(model_upload): Add tokenizer to upload_model_to_dq function #853

Merged
merged 2 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion dataquality/core/finish.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ def finish(
model = helper_data["model"]
model_parameters = helper_data["model_parameters"]
model_kind = helper_data["model_kind"]
upload_model_to_dq(model, model_parameters, model_kind)
tokenizer = helper_data["tokenizer"]
upload_model_to_dq(model, model_parameters, model_kind, tokenizer)
print("Model uploaded successfully.")
else:
print("No model to upload.")
Expand Down
1 change: 1 addition & 0 deletions dataquality/integrations/transformers_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ def watch(
cleanup_manager = RefManager(lambda: unwatch(trainer))
helper_data["cleaner"] = Cleanup(cleanup_manager)
helper_data["model"] = trainer.model
helper_data["tokenizer"] = trainer.tokenizer
helper_data["model_parameters"] = {
"classifier_layer": classifier_layer,
"embedding_dim": embedding_dim,
Expand Down
7 changes: 6 additions & 1 deletion dataquality/utils/upload_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import Any, Dict, Tuple

import requests
from transformers import PreTrainedTokenizer

from dataquality.clients.api import ApiClient
from dataquality.core._config import config
Expand Down Expand Up @@ -34,7 +35,10 @@ def upload_to_minio_using_presigned_url(presigned_url: str, file_path: str) -> T


def upload_model_to_dq(
model: Any, model_parameters: Dict[str, Any], model_kind: ModelUploadType
model: Any,
model_parameters: Dict[str, Any],
model_kind: ModelUploadType,
tokenizer: PreTrainedTokenizer,
) -> None:
"""
Uploads the model to the Galileo platform.
Expand All @@ -52,6 +56,7 @@ def upload_model_to_dq(
# save to temporary folder
with tempfile.TemporaryDirectory() as tmpdirname:
model.save_pretrained(f"{tmpdirname}/model_export")
tokenizer.save_pretrained(f"{tmpdirname}/model_export")
tar_path = f"{tmpdirname}/model.tar.gz"
create_tar_archive(f"{tmpdirname}/model_export", tar_path)
upload_to_minio_using_presigned_url(signed_url, tar_path)
Expand Down
1 change: 1 addition & 0 deletions tests/core/test_finish.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ def test_finish_dq_upload(
)
helper_data = dataquality.core.log.get_model_logger().logger_config.helper_data
helper_data["model"] = "model"
helper_data["tokenizer"] = "model"
helper_data["model_parameters"] = "model_parameters"
helper_data["model_kind"] = "model_kind"
dataquality.finish(upload_model=True)
Expand Down
Loading