-
Notifications
You must be signed in to change notification settings - Fork 223
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
Less GIL locks speeds things up apparently ? #31
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice add!
self.assertTrue(torch.allclose(v, tv)) | ||
self.assertEqual(v.device, torch.device("cpu")) | ||
|
||
def test_deserialization_safe_gpu(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test should have some kind of decorator to skip it if there is no GPU (will be necessary to get the CI green).
} | ||
} | ||
|
||
fn create_tensor( | ||
py: Python, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is the advantage/reason of removing py
arg & using Python::with_gil(|py| {
?
Was it required for the new changes to work OR it was some clean up?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is the core of the thing.
I must say I don't completely understand but it comes from here:
Basically you want to hold the gil as little as possible to give a chance to pyo3 to release it's objects (which then makes the memory available for follow up tensor creation)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh I see 👍
This PR reduces the locations where the GIL is taken, which at least in appearance speeds up significantly the load speed for PT.
I am now on my local computer ~3x faster to load on CPU.
The PR stems from realizing that trying to load on GPU directly, was consuming a LOT of CPU (it still does).
GPU loading was much slower to load everything on CPU then moving to GPU than directly loading on GPU (tensor per tensor).
GIL definitely seems at play here.
So
safe_open
now receives adevice
argument to that the various functons can return tensors directly on the correct location.No check or concern for TF or Flax has been taken yet (numpy cannot allocate on GPU).
When we do we'll probably have to make
Device
uniform across library.