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: enable ray by default #787

Merged
merged 25 commits into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
add parallelizable UDF decorators
  • Loading branch information
xzdandy committed Jun 1, 2023
commit 84ba13e34fc28dc0f44d9b24c8fd43e0808c3c62
2 changes: 1 addition & 1 deletion eva/udfs/abstract/tracker_abstract_udf.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class EVATrackerAbstractUDF(AbstractUDF):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

@setup(cacheable=False, udf_type="object_tracker", batchable=False)
@setup(cacheable=False, udf_type="object_tracker", batchable=False, parallelizable=False)
def setup(self, *args, **kwargs):
super().setup(*args, **kwargs)

Expand Down
2 changes: 1 addition & 1 deletion eva/udfs/chatgpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class ChatGPT(AbstractUDF):
def name(self) -> str:
return "ChatGPT"

@setup(cacheable=False, udf_type="chat-completion", batchable=True)
@setup(cacheable=False, udf_type="chat-completion", batchable=True, parallelizable=False)
def setup(
self,
model="gpt-3.5-turbo",
Expand Down
8 changes: 5 additions & 3 deletions eva/udfs/decorators/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@
from eva.udfs.decorators.io_descriptors.abstract_types import IOArgument


def setup(cacheable: bool = False, udf_type: str = "Abstract", batchable: bool = True):
def setup(cacheable: bool = False, udf_type: str = "Abstract", batchable: bool = True, parallelizable: bool = True):
"""decorator for the setup function. It will be used to set the cache, batching and
udf_type parameters in the catalog

Args:
use_cache (bool): True if the udf should be cached
cacheable (bool): True if the udf should be cached
udf_type (str): Type of the udf
batch (bool): True if the udf should be batched
batchable (bool): True if the udf should be batched
parallelizable (bool): True if the udf can be parallelized during the evaluation
"""

def inner_fn(arg_fn):
Expand All @@ -38,6 +39,7 @@ def wrapper(*args, **kwargs):
tags["cacheable"] = cacheable
tags["udf_type"] = udf_type
tags["batchable"] = batchable
tags["parallelizable"] = parallelizable
wrapper.tags = tags
return wrapper

Expand Down
2 changes: 1 addition & 1 deletion eva/udfs/ndarray/annotate.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@


class Annotate(AbstractUDF):
@setup(cacheable=False, udf_type="cv2-transformation", batchable=True)
@setup(cacheable=False, udf_type="cv2-transformation", batchable=True, parallelizable=True)
def setup(self):
pass

Expand Down
3 changes: 2 additions & 1 deletion eva/udfs/ndarray/array_count.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@
import pandas as pd

from eva.udfs.abstract.abstract_udf import AbstractUDF

from eva.udfs.decorators.decorators import forward, setup

class ArrayCount(AbstractUDF):
@property
def name(self) -> str:
return "ArrayCount"

@setup(parallelizable=False)
def setup(self):
pass

Expand Down
2 changes: 2 additions & 0 deletions eva/udfs/ndarray/crop.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
import pandas as pd

from eva.udfs.abstract.abstract_udf import AbstractUDF
from eva.udfs.decorators.decorators import forward, setup


class Crop(AbstractUDF):
@setup(parallelizable=False)
def setup(self):
pass

Expand Down
1 change: 1 addition & 0 deletions eva/udfs/ndarray/fuzzy_join.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@


class FuzzDistance(AbstractUDF):
@setup(parallelizable=True)
def setup(self):
pass

Expand Down
2 changes: 1 addition & 1 deletion eva/udfs/ndarray/gaussian_blur.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@


class GaussianBlur(AbstractUDF):
@setup(cacheable=False, udf_type="cv2-transformation", batchable=True)
@setup(cacheable=False, udf_type="cv2-transformation", batchable=True, parallelizable=True)
def setup(self):
pass

Expand Down
2 changes: 1 addition & 1 deletion eva/udfs/ndarray/horizontal_flip.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@


class HorizontalFlip(AbstractUDF):
@setup(cacheable=False, udf_type="cv2-transformation", batchable=True)
@setup(cacheable=False, udf_type="cv2-transformation", batchable=True, parallelizable=True)
def setup(self):
pass

Expand Down
2 changes: 2 additions & 0 deletions eva/udfs/ndarray/open.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
import pandas as pd

from eva.udfs.abstract.abstract_udf import AbstractUDF
from eva.udfs.decorators.decorators import forward, setup


class Open(AbstractUDF):
@setup(parallelizable=True)
def setup(self):
# cache data to avoid expensive open files on disk
self._data_cache = dict()
Expand Down
1 change: 1 addition & 0 deletions eva/udfs/ndarray/similarity.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Similarity(AbstractUDF):
def _get_distance(self, numpy_distance):
return numpy_distance[0][0]

@setup(parallelizable=True)
def setup(self):
pass

Expand Down
2 changes: 1 addition & 1 deletion eva/udfs/ndarray/to_grayscale.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@


class ToGrayscale(AbstractUDF):
@setup(cacheable=False, udf_type="cv2-transformation", batchable=True)
@setup(cacheable=False, udf_type="cv2-transformation", batchable=True, parallelizable=True)
def setup(self):
pass

Expand Down
2 changes: 1 addition & 1 deletion eva/udfs/ndarray/vertical_flip.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@


class VerticalFlip(AbstractUDF):
@setup(cacheable=False, udf_type="cv2-transformation", batchable=True)
@setup(cacheable=False, udf_type="cv2-transformation", batchable=True, parallelizable=True)
def setup(self):
pass

Expand Down
4 changes: 3 additions & 1 deletion test/udfs/decorators/test_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@

class DecoratorTests(unittest.TestCase):
def test_setup_flags_are_updated(self):
@setup(cacheable=True, udf_type="classification", batchable=True)
@setup(cacheable=True, udf_type="classification", batchable=True, parallelizable=False)
def setup_func():
pass

setup_func()
self.assertTrue(setup_func.tags["cacheable"])
self.assertTrue(setup_func.tags["batchable"])
self.assertEqual(setup_func.tags["udf_type"], "classification")
self.assertEqual(setup_func.tags["parallelizable"], False)

def test_setup_flags_are_updated_with_default_values(self):
@setup()
Expand All @@ -39,6 +40,7 @@ def setup_func():
self.assertFalse(setup_func.tags["cacheable"])
self.assertTrue(setup_func.tags["batchable"])
self.assertEqual(setup_func.tags["udf_type"], "Abstract")
self.assertEqual(setup_func.tags["parallelizable"], True)

def test_forward_flags_are_updated(self):
input_type = PandasDataframe(
Expand Down