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

Protect against infinitely growing content size batcher #4806

Merged
merged 1 commit into from
Sep 17, 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: 3 additions & 0 deletions fiftyone/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1462,6 +1462,9 @@ def __init__(
progress=False,
total=None,
):
# If unset or larger, max batch size must be 1 byte per object
if max_batch_size is None or max_batch_size > target_size:
max_batch_size = target_size
super().__init__(
iterable,
target_size,
Expand Down
24 changes: 13 additions & 11 deletions tests/unittests/utils_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,16 @@ def test_inexhaustible_static_batcher(self):

def test_inexhaustible_content_size_batcher(self):
batcher = fou.ContentSizeDynamicBatcher(
None, init_batch_size=100, target_size=10
None, init_batch_size=100, target_size=1000
)
measurements = [1, 20, 10, 0.1, 11, 0]
measurements = [500, 2000, 1000, 0.1, 1100, 0]
expected_batches = [
100,
1_000,
500,
500,
50_000,
int(round(10 / 11 * 50_000)),
200,
100,
100,
1000, # capped at 1000 or 1B per object
int(round(10 / 11 * 1000)),
]
batches = []
for m in measurements:
Expand Down Expand Up @@ -474,8 +474,9 @@ class TestLoadDataset(unittest.TestCase):
@patch("fiftyone.core.dataset.dataset_exists")
@patch("fiftyone.core.odm.get_db_conn")
@patch("fiftyone.core.dataset.Dataset")
def test_load_dataset_by_id(self, mock_dataset, mock_get_db_conn,
dataset_exists):
def test_load_dataset_by_id(
self, mock_dataset, mock_get_db_conn, dataset_exists
):
# Setup
identifier = ObjectId()
mock_db = MagicMock()
Expand All @@ -500,8 +501,9 @@ def test_load_dataset_by_id(self, mock_dataset, mock_get_db_conn,
@patch("fiftyone.core.dataset.dataset_exists")
@patch("fiftyone.core.odm.get_db_conn")
@patch("fiftyone.core.dataset.Dataset")
def test_load_dataset_by_alt_id(self, mock_dataset, mock_get_db_conn,
dataset_exists):
def test_load_dataset_by_alt_id(
self, mock_dataset, mock_get_db_conn, dataset_exists
):
# Setup
identifier = "alt_id"
mock_db = MagicMock()
Expand Down
Loading