-
Notifications
You must be signed in to change notification settings - Fork 262
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix problems found when running hugging face text summariztion model …
…on large input. (#929) 1. Pass `batch_mem_size` correctly to storage engines 2. Fix hugging face crash when the number of input token is large then the limit. 👋 Thanks for submitting a Pull Request to EvaDB! 🙌 We want to make contributing to EvaDB as easy and transparent as possible. Here are a few tips to get you started: - 🔍 Search existing EvaDB [PRs](https://github.com/georgia-tech-db/eva/pulls) to see if a similar PR already exists. - 🔗 Link this PR to a EvaDB [issue](https://github.com/georgia-tech-db/eva/issues) to help us understand what bug fix or feature is being implemented. - 📈 Provide before and after profiling results to help us quantify the improvement your PR provides (if applicable). 👉 Please see our ✅ [Contributing Guide](https://evadb.readthedocs.io/en/stable/source/contribute/index.html) for more details.
- Loading branch information
Showing
5 changed files
with
121 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,60 @@ | ||
# coding=utf-8 | ||
# Copyright 2018-2023 EvaDB | ||
# | ||
# 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. | ||
import unittest | ||
from test.util import get_evadb_for_testing | ||
|
||
from mock import ANY, patch | ||
|
||
from evadb.server.command_handler import execute_query_fetch_all | ||
from evadb.storage.sqlite_storage_engine import SQLStorageEngine | ||
|
||
|
||
class BatchMemSizeTest(unittest.TestCase): | ||
@classmethod | ||
def setUpClass(cls): | ||
cls.evadb = get_evadb_for_testing() | ||
# reset the catalog manager before running each test | ||
cls.evadb.catalog().reset() | ||
|
||
@classmethod | ||
def tearDownClass(cls): | ||
execute_query_fetch_all(cls.evadb, "DROP TABLE IF EXISTS MyCSV;") | ||
|
||
def test_batch_mem_size_for_sqlite_storage_engine(self): | ||
""" | ||
This testcase make sure that the `batch_mem_size` is correctly passed to | ||
the storage engine. | ||
""" | ||
test_batch_mem_size = 100 | ||
self.evadb.config.update_value( | ||
"executor", "batch_mem_size", test_batch_mem_size | ||
) | ||
create_table_query = """ | ||
CREATE TABLE IF NOT EXISTS MyCSV ( | ||
id INTEGER UNIQUE, | ||
frame_id INTEGER, | ||
video_id INTEGER, | ||
dataset_name TEXT(30), | ||
label TEXT(30), | ||
bbox NDARRAY FLOAT32(4), | ||
object_id INTEGER | ||
);""" | ||
execute_query_fetch_all(self.evadb, create_table_query) | ||
|
||
select_table_query = "SELECT * FROM MyCSV;" | ||
with patch.object(SQLStorageEngine, "read") as mock_read: | ||
mock_read.__iter__.return_value = [] | ||
execute_query_fetch_all(self.evadb, select_table_query) | ||
mock_read.assert_called_with(ANY, test_batch_mem_size) |
This file contains 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,47 @@ | ||
# coding=utf-8 | ||
# Copyright 2018-2023 EvaDB | ||
# | ||
# 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. | ||
|
||
import unittest | ||
|
||
import pandas as pd | ||
from mock import MagicMock | ||
|
||
from evadb.third_party.huggingface.model import TextHFModel | ||
|
||
|
||
class TestTextHFModel(TextHFModel): | ||
@property | ||
def default_pipeline_args(self) -> dict: | ||
# We need to improve the hugging face interface, passing | ||
# UdfCatalogEntry into UDF is not ideal. | ||
return { | ||
"task": "summarization", | ||
"model": "sshleifer/distilbart-cnn-12-6", | ||
"min_length": 5, | ||
"max_length": 100, | ||
} | ||
|
||
|
||
class HuggingFaceTest(unittest.TestCase): | ||
def test_hugging_face_with_large_input(self): | ||
udf_obj = MagicMock() | ||
udf_obj.metadata = [] | ||
text_summarization_model = TestTextHFModel(udf_obj) | ||
|
||
large_text = pd.DataFrame([{"text": "hello" * 4096}]) | ||
try: | ||
text_summarization_model(large_text) | ||
except IndexError: | ||
self.fail("hugging face with large input raised IndexError.") |