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

fix pin memory device #755

Merged
merged 2 commits into from
Jan 27, 2025
Merged

fix pin memory device #755

merged 2 commits into from
Jan 27, 2025

Conversation

youkaichao
Copy link
Collaborator

right now flashinfer does not specify the device when creating pin-memory tensor. it will cause error when users changed the default pytorch device.

we should explicitly set the device to be "cpu" for pin-memory tensor.

Signed-off-by: youkaichao <[email protected]>
@youkaichao
Copy link
Collaborator Author

example error trace:

kernels/test_flashinfer.py:229:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/usr/local/lib/python3.12/dist-packages/flashinfer/prefill.py:1099: in __init__
    self._pin_memory_int_workspace_buffer = torch.empty(
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <torch.utils._device.DeviceContext object at 0x7ff7263fde50>, func = <built-in method empty of type object at 0x7ff8c8c5e280>
types = (), args = (torch.Size([8388608]),), kwargs = {'device': device(type='cuda'), 'dtype': torch.uint8, 'pin_memory': True}

    def __torch_function__(self, func, types, args=(), kwargs=None):
        kwargs = kwargs or {}
        if func in _device_constructors() and kwargs.get('device') is None:
            kwargs['device'] = self.device
>       return func(*args, **kwargs)
E       RuntimeError: Only dense CPU tensors can be pinned

Signed-off-by: youkaichao <[email protected]>
Copy link
Collaborator

@yzh119 yzh119 left a comment

Choose a reason for hiding this comment

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

LGTM, thank you!

@yzh119 yzh119 merged commit 5243043 into flashinfer-ai:main Jan 27, 2025
@youkaichao youkaichao deleted the fix_buffer branch January 27, 2025 03:20
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.

2 participants