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

Add VmModule.mmap() to Python API. #14124

Merged
merged 2 commits into from
Jun 15, 2023
Merged

Add VmModule.mmap() to Python API. #14124

merged 2 commits into from
Jun 15, 2023

Conversation

stellaraccident
Copy link
Collaborator

We really need page aligned flatbuffer blobs vs normal malloc alignment. The best way to be loading a file is via mmap, so just make that available as an API.

This could be done in Python by the caller but is error-prone. The public API will make this more robust.

Provides the mechanism to fix #13887

We really need page aligned flatbuffer blobs vs normal malloc alignment. The best way to be loading a file is via mmap, so just make that available as an API.

This could be done in Python by the caller but is error-prone. The public API will make this more robust.

Provides the mechanism to fix #13887
@stellaraccident stellaraccident merged commit 3345b76 into main Jun 15, 2023
@stellaraccident stellaraccident deleted the python_mmap branch June 15, 2023 07:22
@powderluv
Copy link
Collaborator

May need some tweaking for Windows

Abhishek-Varma added a commit to Abhishek-Varma/SHARK that referenced this pull request Jun 15, 2023
-- This commit is based on [VmModule.mmap() API](iree-org/iree#14124).
-- It thereby adds capability to mmap vmfbs in SHARK.

Signed-off-by: Abhishek Varma <[email protected]>
Comment on lines +119 to +122
with tempfile.NamedTemporaryFile() as tf:
tf.write(binary)
tf.flush()
m = iree.runtime.VmModule.mmap(self.instance, tf.name)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May need some tweaking for Windows

Indeed. https://github.com/openxla/iree/actions/runs/5275962562/jobs/9542060597#step:9:2321

ERROR: test_mmap (__main__.VmTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\a\iree\iree\runtime\bindings\python\tests\vm_test.py", line 122, in test_mmap
    m = iree.runtime.VmModule.mmap(self.instance, tf.name)
PermissionError: [Errno 13] Permission denied: 'C:\\Users\\RUNNER~1\\AppData\\Local\\Temp\\tmpr4u5ldjo'

Maybe related to #13148 (comment)

See https://stackoverflow.com/a/23212515 - NamedTemporaryFile creates and opens the file, and the file cannot be opened again... on Windows (it can be opened again on Unix).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a fix for that in SHARK to deal with this very issue - perhaps that can be used.

But the other issue in Windows which I bumped into is mentioned here - it's API related instead of the use case.

CC: @powderluv

Abhishek-Varma added a commit to Abhishek-Varma/SHARK that referenced this pull request Jun 15, 2023
-- This commit is based on [VmModule.mmap() API](iree-org/iree#14124).
-- It thereby adds capability to mmap vmfbs in SHARK.

Signed-off-by: Abhishek Varma <[email protected]>
Abhishek-Varma added a commit to Abhishek-Varma/SHARK that referenced this pull request Jun 15, 2023
-- This commit is based on [VmModule.mmap() API](iree-org/iree#14124).
-- It thereby adds capability to mmap vmfbs in SHARK.

Signed-off-by: Abhishek Varma <[email protected]>
stellaraccident added a commit that referenced this pull request Jun 15, 2023
Python mmap on Windows has a slightly different signature. Reverting for now to unbreak the Windows CI. Will re-apply when have access to test it there.

This reverts commit 3345b76.
Abhishek-Varma added a commit to Abhishek-Varma/SHARK that referenced this pull request Jun 21, 2023
-- This commit is based on [VmModule.mmap() API](iree-org/iree#14124).
-- It thereby adds capability to mmap vmfbs in SHARK.

Signed-off-by: Abhishek Varma <[email protected]>
Abhishek-Varma added a commit to Abhishek-Varma/SHARK that referenced this pull request Jun 21, 2023
-- This commit is based on [VmModule.mmap() API](iree-org/iree#14124).
-- It thereby adds capability to mmap vmfbs in SHARK.

Signed-off-by: Abhishek Varma <[email protected]>
Abhishek-Varma added a commit to Abhishek-Varma/SHARK that referenced this pull request Jun 22, 2023
-- This commit is based on [VmModule.mmap() API](iree-org/iree#14124).
-- It thereby adds capability to mmap vmfbs in SHARK.

Signed-off-by: Abhishek Varma <[email protected]>
Abhishek-Varma added a commit to nod-ai/SHARK-Studio that referenced this pull request Jun 22, 2023
-- This commit is based on [VmModule.mmap() API](iree-org/iree#14124).
-- It thereby adds capability to mmap vmfbs in SHARK.

Signed-off-by: Abhishek Varma <[email protected]>
nhasabni pushed a commit to plaidml/iree that referenced this pull request Aug 24, 2023
We really need page aligned flatbuffer blobs vs normal malloc alignment.
The best way to be loading a file is via mmap, so just make that
available as an API.

This could be done in Python by the caller but is error-prone. The
public API will make this more robust.

Provides the mechanism to fix iree-org#13887
nhasabni pushed a commit to plaidml/iree that referenced this pull request Aug 24, 2023
Python mmap on Windows has a slightly different signature. Reverting for now to unbreak the Windows CI. Will re-apply when have access to test it there.

This reverts commit 3345b76.
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

Successfully merging this pull request may close these issues.

[Python] LLaMA/Vicuna 7B: Different results with iree-run-module and Python for local-sync vs local-task
4 participants