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

feat(python): gpu based ivf partition training #1361

Merged
merged 13 commits into from
Oct 5, 2023
Merged

Conversation

eddyxu
Copy link
Contributor

@eddyxu eddyxu commented Oct 5, 2023

Use pytorch to train IVF partitions on GPU

ds.create_index(..., accelerator="cuda")

@eddyxu eddyxu marked this pull request as draft October 5, 2023 16:51
@eddyxu eddyxu requested review from wjones127, changhiskhan and westonpace and removed request for wjones127 and changhiskhan October 5, 2023 17:13
@eddyxu eddyxu marked this pull request as ready for review October 5, 2023 17:13
@eddyxu eddyxu self-assigned this Oct 5, 2023
@eddyxu eddyxu added the vector Vector Search label Oct 5, 2023
else:
samples = dataset.sample(k * sample_rate)[column]

if accelerator in ["gpu", "cuda"]:
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: gpu could be MPS or AMD as well, I don't think we should map gpu to cuda.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea, so i was thinking that use gpu to call preferred_device() later to auto detect GPU on the machine

def preferred_device(device: Optional[str] = None):

But it is fair that we don't need to do it now. As mps performance is not good at the moment.

column: str,
k: int,
metric_type: str,
accelerator: str,
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: allow device id here like cuda:0.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

Copy link
Contributor

@chebbyChefNEQ chebbyChefNEQ left a comment

Choose a reason for hiding this comment

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

just two device handling nits

Copy link
Contributor

@westonpace westonpace left a comment

Choose a reason for hiding this comment

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

Minor comment tweaks but this looks good

python/python/lance/dataset.py Outdated Show resolved Hide resolved
python/python/lance/dataset.py Outdated Show resolved Hide resolved
python/python/lance/dataset.py Outdated Show resolved Hide resolved
*,
sample_rate: int = 256,
) -> np.ndarray:
"""Use accelerator (GPU or MPS) to train kmeans."""
Copy link
Contributor

Choose a reason for hiding this comment

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

Is MPS actually supported currently?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, we can run mps today, it is just not as fast as we desired.

sample_rate: int = 256,
) -> np.ndarray:
"""Use accelerator (GPU or MPS) to train kmeans."""

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: should we check for torch is installed before trying to do all the sampling?

@eddyxu eddyxu merged commit 0bed6a1 into main Oct 5, 2023
10 checks passed
@eddyxu eddyxu deleted the lei/create_idx_gpu branch October 5, 2023 18:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
vector Vector Search
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants