rapidsai / cuml

cuML - RAPIDS Machine Learning Library
https://docs.rapids.ai/api/cuml/stable/
Apache License 2.0
4.21k stars 530 forks source link

Support for 64-bit indptr data #5582

Open catsargent opened 1 year ago

catsargent commented 1 year ago

I am trying to use rapids_singlecell for analysing a large dataset (> 2 Million cells). When running their function for performing differential gene expression analysis, it works fine for a smaller subset of cells. However, when I run it on all cells, I get the following error:

TypeError                                 Traceback (most recent call last)
File <timed eval>:1

File ~/.conda/envs/rapids_singlecell/lib/python3.10/site-packages/rapids_singlecell/tools/_rank_gene_groups.py:175, in rank_genes_groups_logreg(adata, groupby, groups, use_raw, reference, n_genes, layer, **kwds)
    172     grouping_logreg[np.where(grouping_logreg == cat)] = idx
    174 clf = LogisticRegression(**kwds)
--> 175 clf.fit(X, grouping_logreg)
    176 scores_all = cp.array(clf.coef_)
    178 if len(groups_order) == scores_all.shape[1]:

File ~/.conda/envs/rapids_singlecell/lib/python3.10/site-packages/cuml/internals/api_decorators.py:188, in _make_decorator_function.<locals>.decorator_function.<locals>.decorator_closure.<locals>.wrapper(*args, **kwargs)
    185     set_api_output_dtype(output_dtype)
    187 if process_return:
--> 188     ret = func(*args, **kwargs)
    189 else:
    190     return func(*args, **kwargs)

File ~/.conda/envs/rapids_singlecell/lib/python3.10/site-packages/cuml/internals/api_decorators.py:393, in enable_device_interop.<locals>.dispatch(self, *args, **kwargs)
    391 if hasattr(self, "dispatch_func"):
    392     func_name = gpu_func.__name__
--> 393     return self.dispatch_func(func_name, gpu_func, *args, **kwargs)
    394 else:
    395     return gpu_func(self, *args, **kwargs)

File ~/.conda/envs/rapids_singlecell/lib/python3.10/site-packages/cuml/internals/api_decorators.py:190, in _make_decorator_function.<locals>.decorator_function.<locals>.decorator_closure.<locals>.wrapper(*args, **kwargs)
    188         ret = func(*args, **kwargs)
    189     else:
--> 190         return func(*args, **kwargs)
    192 return cm.process_return(ret)

File base.pyx:665, in cuml.internals.base.UniversalBase.dispatch_func()

File logistic_regression.pyx:346, in cuml.linear_model.logistic_regression.LogisticRegression.fit()

File ~/.conda/envs/rapids_singlecell/lib/python3.10/site-packages/cuml/internals/api_decorators.py:188, in _make_decorator_function.<locals>.decorator_function.<locals>.decorator_closure.<locals>.wrapper(*args, **kwargs)
    185     set_api_output_dtype(output_dtype)
    187 if process_return:
--> 188     ret = func(*args, **kwargs)
    189 else:
    190     return func(*args, **kwargs)

File qn.pyx:465, in cuml.solvers.qn.QN.fit()

File ~/.conda/envs/rapids_singlecell/lib/python3.10/site-packages/cuml/internals/memory_utils.py:87, in with_cupy_rmm.<locals>.cupy_rmm_wrapper(*args, **kwargs)
     85 if GPU_ENABLED:
     86     with cupy_using_allocator(rmm_cupy_allocator):
---> 87         return func(*args, **kwargs)
     88 return func(*args, **kwargs)

File ~/.conda/envs/rapids_singlecell/lib/python3.10/site-packages/nvtx/nvtx.py:101, in annotate.__call__.<locals>.inner(*args, **kwargs)
     98 @wraps(func)
     99 def inner(*args, **kwargs):
    100     libnvtx_push_range(self.attributes, self.domain.handle)
--> 101     result = func(*args, **kwargs)
    102     libnvtx_pop_range(self.domain.handle)
    103     return result

File ~/.conda/envs/rapids_singlecell/lib/python3.10/site-packages/cuml/internals/array_sparse.py:167, in SparseCumlArray.__init__(self, data, convert_to_dtype, convert_to_mem_type, convert_index, convert_format)
    162     convert_index = data.indptr.dtype
    164 # Note: Only 32-bit indexing is supported currently.
    165 # In CUDA11, Cusparse provides 64-bit function calls
    166 # but these are not yet used in RAFT/Cuml
--> 167 self.indptr = CumlArray.from_input(
    168     data.indptr,
    169     convert_to_dtype=convert_index,
    170     convert_to_mem_type=convert_to_mem_type,
    171 )
    173 self.indices = CumlArray.from_input(
    174     data.indices,
    175     convert_to_dtype=convert_index,
    176     convert_to_mem_type=convert_to_mem_type,
    177 )
    179 self.data = CumlArray.from_input(
    180     data.data,
    181     convert_to_dtype=convert_to_dtype,
    182     convert_to_mem_type=convert_to_mem_type,
    183 )

File ~/.conda/envs/rapids_singlecell/lib/python3.10/site-packages/cuml/internals/memory_utils.py:87, in with_cupy_rmm.<locals>.cupy_rmm_wrapper(*args, **kwargs)
     85 if GPU_ENABLED:
     86     with cupy_using_allocator(rmm_cupy_allocator):
---> 87         return func(*args, **kwargs)
     88 return func(*args, **kwargs)

File ~/.conda/envs/rapids_singlecell/lib/python3.10/site-packages/nvtx/nvtx.py:101, in annotate.__call__.<locals>.inner(*args, **kwargs)
     98 @wraps(func)
     99 def inner(*args, **kwargs):
    100     libnvtx_push_range(self.attributes, self.domain.handle)
--> 101     result = func(*args, **kwargs)
    102     libnvtx_pop_range(self.domain.handle)
    103     return result

File ~/.conda/envs/rapids_singlecell/lib/python3.10/site-packages/cuml/internals/array.py:1112, in CumlArray.from_input(cls, X, order, deepcopy, check_dtype, convert_to_dtype, check_mem_type, convert_to_mem_type, safe_dtype_conversion, check_cols, check_rows, fail_on_order, force_contiguous)
   1108             X = cp.asarray(X)
   1109         if (
   1110             (X < target_dtype_range.min) | (X > target_dtype_range.max)
   1111         ).any():
-> 1112             raise TypeError(
   1113                 "Data type conversion on values outside"
   1114                 " representable range of target dtype"
   1115             )
   1116     arr = cls(
   1117         arr.to_output(
   1118             output_dtype=convert_to_dtype,
   (...)
   1123         validate=False,
   1124     )
   1126 make_copy = force_contiguous and not arr.is_contiguous

TypeError: Data type conversion on values outside representable range of target dtype

I believe this is due to 64-bit indptr data not being supported. I would like to request this feature being added, as currently, this limits the size of datasets that can be analysed. Analysing such large datasets without a GPU is extremely slow, so we are really keen to make use of rapids_singlecell.

Many thanks!

dantegd commented 1 year ago

Thanks for the issue @catsargent, overall updating supported index types and being more consistent is part of ongoing work, we will work on this in an upcoming version of cuML.

Intron7 commented 11 months ago

@catsargent can you also link this issue in rapids-singlecell so people know about it.