Skip to content

MapInfra shuffles items even when computing them inline (cluster=None) #349

Open

Description

@LouisJalouzot

Hi, thanks again for exca!

MapInfra shuffles the missing items before calling the decorated method, even with cluster=None, where they are all computed in a single call (exca 0.6.0):

class Model(pydantic.BaseModel):
    infra: exca.MapInfra = exca.MapInfra(folder=tempfile.mkdtemp())

    @infra.apply(item_uid=str)
    def process(self, items: list[str]) -> tp.Iterator[str]:
        items = list(items)
        print(items)  # e.g. ['c0', 'c2', 'c1', 'b1', 'a2', 'a1', 'a0', 'b2', 'b0']
        yield from items

list(Model().process([f"{f}{i}" for f in "abc" for i in range(3)]))

This hurts when consecutive items could share an expensive resource, e.g. loading the same audio or video file.

Would you accept keeping the input order for inline computation (cluster=None)? Suggested change:

             if len(missing) == 1:
                 pool = None
-            # avoid processing same files at same time if several jobs overlap
-            np.random.shuffle(missing)
+            if pool is not None:  # inline computation keeps the input order
+                # avoid processing same files at same time if several jobs overlap
+                np.random.shuffle(missing)

Happy to open a PR with this change and a test.

Side note: the shuffle also advances the global NumPy random state, only on cache misses.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions