-
Notifications
You must be signed in to change notification settings - Fork 240
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
_check_data_loader() slows down my code by at least one order of magnitude #1250
Comments
Hi, @rsanchezgarc. Thanks for reporting. Do you have a MWE to prove that the new method caused the slowdown? |
Hi, I just rechecked it, and the slowdown is only in the range of 20%, so please, ignore this issue. |
Still bad! But we'd need proof to work on this :D |
Here is my MWE import time
import torch
import torchio as tio
class FastScalarImage(tio.ScalarImage):
def _check_data_loader(self):
return
class FastLabelMap(tio.LabelMap):
def _check_data_loader(self):
return
#The nested calls are designed to make inspect slower
def ___create_subject(ScalarImage, LabelMap):
x = torch.rand(1, 32, 32, 32)
y = torch.rand(1, 32, 32, 32)
subject = tio.Subject({
"input_data": ScalarImage(tensor=x),
"target_data": LabelMap(tensor=y)
})
return subject
def __create_subject(ScalarImage, LabelMap):
return ___create_subject(ScalarImage, LabelMap)
def _create_subject(ScalarImage, LabelMap):
return __create_subject(ScalarImage, LabelMap)
def create_subject(ScalarImage, LabelMap):
return _create_subject(ScalarImage, LabelMap)
# Benchmark function
def run_benchmark(n_iters=10000):
# Test regular TorchIO classes
s = time.time()
for i in range(n_iters):
_create_subject(tio.ScalarImage, tio.LabelMap)
regular_time = time.time() - s
print(f"Regular implementation: {regular_time:.3f}s")
# Test fast classes
s = time.time()
for i in range(n_iters):
create_subject(FastScalarImage, FastLabelMap)
fast_time = time.time() - s
print(f"Fast implementation: {fast_time:.3f}s")
speedup = (regular_time / fast_time - 1) * 100
print(f"Speedup: {speedup:.1f}%")
if __name__ == "__main__":
run_benchmark() Regular implementation: 4.539s |
hi that's weird ! may be it comes from different dependencies ... ? python <(curl -s https://raw.githubusercontent.com/fepegar/torchio/main/print_system.py) |
I dig a bit into, and for me it comes from the 0.016*10000 iteration * 2 (image and label) = 320 s |
Hi,
I have noticed that in the newer versions, _check_data_loader() is called at the Image.init.
https://github.com/fepegar/torchio/blame/6bb2457fd23ed76156dfd4f4cc84d0cd42e6f081/src/torchio/data/image.py#L177
I have also noticed that this is causing a significant slowdown in my code. Would it be possible to reconsider this check, or, at least, make it optional?
The text was updated successfully, but these errors were encountered: