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 UMAP sparse input crash #5494

Open
wants to merge 2 commits into
base: branch-23.12
Choose a base branch
from

Conversation

viclafargue
Copy link
Contributor

@viclafargue viclafargue commented Jul 7, 2023

Answers #4984

@viclafargue viclafargue requested a review from a team as a code owner July 7, 2023 12:50
Copy link
Member

@dantegd dantegd left a comment

Choose a reason for hiding this comment

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

Just one small request

size_t requirements = factor * sizeof(float) * index_batch_size * query_batch_size;
if (requirements > free_mem){
index_batch_size = free_mem / (query_batch_size * factor * sizeof(float));
}
Copy link
Member

Choose a reason for hiding this comment

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

Fix looks good to me, can you just add a description of the fix to the PR description and fix the style issues?

Copy link
Member

Choose a reason for hiding this comment

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

Sorry guys, this still isn't quite right.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cjnolet, this is an older comment regarding the previous version. The current version should make use of the workspace_resource_factory to create a limiting_memory_resource with the default amount (total_size / 2 ?) and adjust the index batch size according to available memory. There may totally be things I missed, but could you give more precision to what is required here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated the code slightly. But, since it's a RAFT call, the limiting_memory_resource cannot be used directly. The only thing that is doable is to update the handle, so that it has a resource factory that will in time be used to produce a workspace within the RAFT sparse kNN code. We can produce an estimate of the memory that will be available on the cuML side by calling resource::get_workspace_free_bytes on the handle or get_allocation_limit on the LMR. But, that's about it, isn't it?

@@ -101,6 +101,16 @@ inline void launcher(const raft::handle_t& handle,
const ML::UMAPParams* params,
cudaStream_t stream)
{
size_t free_mem, total_mem;
cudaMemGetInfo(&free_mem, &total_mem);
Copy link
Member

@cjnolet cjnolet Jul 11, 2023

Choose a reason for hiding this comment

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

This is, unfortunately, not a reliable way to query and compute the memory available for batching. It also won't work well with rmm pools.

The challenge here is that the total memory space can quickly become very fragmented, which prevents the reporter free memory from being allocated in a single chunk. Further, if 90% of the memory is allocated to a pool, this is going to report almost no memory available even though the pool could be largely empty.

A better way to approach this problem will be to use the limiting memory resource once its available. This new resource will be applied on top of the workspace resource and will provide a safe and consistent mechanism for us to handle implicit batching on the users behalf in a way that also plays nicely with RMM pools.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cjnolet, the current approach of this PR was to first compute the memory requirements, and then adjust the index batch size if necessary. I understand that getting the free available memory directly from CUDA API is not a good solution as a RMM pool that could/should be used might have already been pre-allocated.

The limiting_resource_adaptor might provide a way to limit downstream memory usage of an upstream device_memory_resource. However, I do not see how this will help solving this issue. The issue is that a complete sparse operation consumes too much memory at once and should be split in multiple operations through batching instead.

Could you give more precision as to how it will provide a safe and consistent mechanism for us to handle implicit batching on the users behalf in a way that also plays nicely with RMM pools?

@viclafargue viclafargue requested review from a team as code owners October 30, 2023 14:05
@copy-pr-bot
Copy link

copy-pr-bot bot commented Oct 30, 2023

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@github-actions github-actions bot added conda conda issue Cython / Python Cython or Python issue CMake ci labels Oct 30, 2023
@viclafargue viclafargue changed the base branch from branch-23.08 to branch-23.12 October 30, 2023 14:20
@github-actions github-actions bot removed conda conda issue Cython / Python Cython or Python issue CMake ci labels Oct 30, 2023
@ajschmidt8 ajschmidt8 removed the request for review from a team December 13, 2023 19:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants