-
Notifications
You must be signed in to change notification settings - Fork 29
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
Filling np.array very slow because of Carbontracker #41
Comments
Hi nfurnon, Thanks for your feedback, we appreciate it! This looks like a bug that happens when import time
import numpy as np
from carbontracker.tracker import CarbonTracker
def load_data(length, data_shape):
data = np.zeros((length, *data_shape))
for i in range(length):
data[i] = np.random.random(data_shape)
return data
if __name__ == '__main__':
l = 10000
shape = (16000, )
tt = time.time()
data = load_data(l, shape)
print(f'Without CT : {time.time() - tt} seconds')
tracker = CarbonTracker(epochs=1, monitor_epochs=1, log_dir='./')
tracker.epoch_start()
tt = time.time()
data = load_data(l, shape)
tracker.epoch_end()
print(f'With CT : {time.time() - tt} seconds') Let me know if this helps. |
Thank you for your answer. The time-consuming task was instantiating a Pytorch |
It should be fine to have a for-loop after instantiation like we show in the example in the README.md. The problem is likely when more compute-intensive operations are done without starting the tracker. |
OK, thank you ! |
Reopening this issue as a reminder that instantiating The issue will be closed once it is fixed. |
adding a time.sleep() with a small but big enough time (best value to be determined, I use a quite long time of 1ms but can be shorter I think) in the CarbonTrackerThread() (see below) solved the problem for me. probably avoids clogging up the CPU with billions of accesses to the self.measuring attribute :)
edit: replaced screen capture with code |
In response to feedback about performance slowdowns due to busy-waiting in the |
Filling a pre-allocated array is slowed down by a factor of ~70 when using
carbontracker
. See minimum code below.Am I doing anything wrong ? How can we avoid this ?
The text was updated successfully, but these errors were encountered: