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

_enforce_nested_string_type() takes too much time for Sequence(Value(...)) #153

Closed
NouamaneTazi opened this issue Jun 21, 2022 · 2 comments

Comments

@NouamaneTazi
Copy link
Member

NouamaneTazi commented Jun 21, 2022

As you can see in the figure below, most of time spent adding a batch is consumed by _enforce_nested_string_type(). Is that necessary?

import logging

import torch
from datasets import Features, Sequence, Value, Array2D

from evaluate.module import EvaluationModule, EvaluationModuleInfo
import time

logging.basicConfig(level=logging.INFO)


class DummyMetric(EvaluationModule):
    def _info(self):
        return EvaluationModuleInfo(
            description="dummy metric for tests",
            citation="insert citation here",
            features=Features(
                {
                    "tensor": Sequence(Value("int64")),
                }
            ),
        )


metric = DummyMetric()
start_time = time.time()
metric.add_batch(
    tensor=torch.randint(0, 10, (1000, 7000)),
)
print(f"time={round(time.time()-start_time, 2)}s") # outputs time=32.41s

image

Related to: #33

@NouamaneTazi
Copy link
Member Author

For my use case, using Array2D yielded a much better performance

import logging

import torch
from datasets import Features, Sequence, Value, Array2D

from evaluate.module import EvaluationModule, EvaluationModuleInfo
import time

logging.basicConfig(level=logging.INFO)


class DummyMetric(EvaluationModule):
    def _info(self):
        return EvaluationModuleInfo(
            description="dummy metric for tests",
            citation="insert citation here",
            features=Features(
                {
                    "tensor": Array2D((None, 7000), "int64"),
                }
            ),
        )


metric = DummyMetric()
start_time = time.time()
metric.add_batch(
    tensor=torch.randint(0, 10, (1, 1000, 7000)),
)
print(f"time={round(time.time()-start_time, 2)}s") # outputs time=0.38s

@lvwerra
Copy link
Member

lvwerra commented Jun 22, 2022

Indeed, that is very slow. We could probably just check it for the first element of the batch instead of all, but as your analysis points out even if the _enforce_nested_string_type is much faster you still spend a significant amount of time on encode_batch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants