rapidsai / cuml

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

[BUG] Inconsistent checks for columns in fit function across estimators #4254

Open Nanthini10 opened 3 years ago

Nanthini10 commented 3 years ago

Describe the bug Linear and Ridge Regression check for ncols in fit function. https://github.com/rapidsai/cuml/blob/26408d3e3cc19926a957be98c4c27e09a2ec4b5f/python/cuml/linear_model/linear_regression.pyx#L259 https://github.com/rapidsai/cuml/blob/e86a6138db58798323942bccab4cd2ecf7dad40b/python/cuml/linear_model/ridge.pyx#L271 but other estimators including other Linear models do not do this check at a python level. This results in inconsistent error thrown at users.

For Linear and Ridge, it results in a TypeError(which itself does not seem to be the right kind, probably a ValueError might make more sense). For the others, a C++ RuntimeError is generated as the check happens at a C++ level.

Steps/Code to reproduce bug

import cuml
import cupy
mod = cuml.Ridge() # Replace this with Lasso
mod.fit(cupy.array([[],[]]),cupy.array([0,0]))
Ridge ``` --------------------------------------------------------------------------- TypeError Traceback (most recent call last) in 2 import cupy 3 mod = cuml.Ridge() ----> 4 mod.fit(cupy.array([[],[]]),cupy.array([0,0])) /opt/conda/envs/rapids/lib/python3.8/site-packages/cuml/internals/api_decorators.py in inner_with_setters(*args, **kwargs) 407 target_val=target_val) 408 --> 409 return func(*args, **kwargs) 410 411 @wraps(func) cuml/linear_model/ridge.pyx in cuml.linear_model.ridge.Ridge.fit() TypeError: X matrix must have at least a column ```
Lasso ``` --------------------------------------------------------------------------- RuntimeError Traceback (most recent call last) in 2 import cupy 3 mod = cuml.Lasso() ----> 4 mod.fit(cupy.array([[],[]]),cupy.array([0,0])) /opt/conda/envs/rapids/lib/python3.8/site-packages/cuml/internals/api_decorators.py in inner_with_setters(*args, **kwargs) 407 target_val=target_val) 408 --> 409 return func(*args, **kwargs) 410 411 @wraps(func) cuml/linear_model/lasso.pyx in cuml.linear_model.lasso.Lasso.fit() /opt/conda/envs/rapids/lib/python3.8/site-packages/cuml/internals/api_decorators.py in inner_with_setters(*args, **kwargs) 407 target_val=target_val) 408 --> 409 return func(*args, **kwargs) 410 411 @wraps(func) cuml/solvers/cd.pyx in cuml.solvers.cd.CD.fit() RuntimeError: exception occured! file=../src/solver/cd.cuh line=98: Parameter n_cols: number of columns cannot be less than one Obtained 64 stack frames #0 in /opt/conda/envs/rapids/lib/libcuml++.so(_ZN4raft9exception18collect_call_stackEv+0x4e) [0x7f17294835de] #1 in /opt/conda/envs/rapids/lib/libcuml++.so(_ZN4raft9exceptionC2ENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE+0x74) [0x7f1729483d74] #2 in /opt/conda/envs/rapids/lib/libcuml++.so(_ZN2ML6Solver5cdFitIdEEvRKN4raft8handle_tEPT_iiS7_S7_S7_bbiNS_10loss_functES6_S6_bS6_P11CUstream_st+0x695) [0x7f1729a30385] #3 in /opt/conda/envs/rapids/lib/libcuml++.so(_ZN2ML6Solver5cdFitERN4raft8handle_tEPdiiS4_S4_S4_bbiiddbd+0x1a8) [0x7f1729a0c2a8] #4 in /opt/conda/envs/rapids/lib/python3.8/site-packages/cuml/solvers/cd.cpython-38-x86_64-linux-gnu.so(+0x29a49) [0x7f17817d1a49] #5 in /opt/conda/envs/rapids/bin/python(PyObject_Call+0x24d) [0x562df014d11d] #6 in /opt/conda/envs/rapids/bin/python(_PyEval_EvalFrameDefault+0x2113) [0x562df01f6b13] #7 in /opt/conda/envs/rapids/bin/python(_PyEval_EvalCodeWithName+0x2c3) [0x562df01d6ee3] #8 in /opt/conda/envs/rapids/bin/python(_PyFunction_Vectorcall+0x378) [0x562df01d82c8] #9 in /opt/conda/envs/rapids/bin/python(_PyObject_FastCallDict+0x2fd) [0x562df0147bdd] #10 in /opt/conda/envs/rapids/bin/python(_PyObject_Call_Prepend+0x63) [0x562df0152823] #11 in /opt/conda/envs/rapids/lib/python3.8/site-packages/cuml/linear_model/lasso.cpython-38-x86_64-linux-gnu.so(+0x89cd) [0x7f176f26c9cd] #12 in /opt/conda/envs/rapids/bin/python(PyObject_Call+0x24d) [0x562df014d11d] #13 in /opt/conda/envs/rapids/bin/python(_PyEval_EvalFrameDefault+0x2113) [0x562df01f6b13] #14 in /opt/conda/envs/rapids/bin/python(_PyEval_EvalCodeWithName+0x2c3) [0x562df01d6ee3] #15 in /opt/conda/envs/rapids/bin/python(+0x1b09e7) [0x562df01d89e7] #16 in /opt/conda/envs/rapids/bin/python(_PyEval_EvalFrameDefault+0x4d73) [0x562df01f9773] #17 in /opt/conda/envs/rapids/bin/python(_PyEval_EvalCodeWithName+0x2c3) [0x562df01d6ee3] #18 in /opt/conda/envs/rapids/bin/python(PyEval_EvalCodeEx+0x39) [0x562df01d7f49] #19 in /opt/conda/envs/rapids/bin/python(PyEval_EvalCode+0x1b) [0x562df027cbbb] #20 in /opt/conda/envs/rapids/bin/python(+0x27302e) [0x562df029b02e] #21 in /opt/conda/envs/rapids/bin/python(+0x128bdb) [0x562df0150bdb] #22 in /opt/conda/envs/rapids/bin/python(_PyEval_EvalFrameDefault+0x947) [0x562df01f5347] #23 in /opt/conda/envs/rapids/bin/python(+0x1807c3) [0x562df01a87c3] #24 in /opt/conda/envs/rapids/bin/python(_PyEval_EvalFrameDefault+0x1d47) [0x562df01f6747] #25 in /opt/conda/envs/rapids/bin/python(+0x1807c3) [0x562df01a87c3] #26 in /opt/conda/envs/rapids/bin/python(_PyEval_EvalFrameDefault+0x1d47) [0x562df01f6747] #27 in /opt/conda/envs/rapids/bin/python(+0x1807c3) [0x562df01a87c3] #28 in /opt/conda/envs/rapids/bin/python(+0x195069) [0x562df01bd069] #29 in /opt/conda/envs/rapids/bin/python(_PyEval_EvalFrameDefault+0xa63) [0x562df01f5463] #30 in /opt/conda/envs/rapids/bin/python(_PyFunction_Vectorcall+0x1a6) [0x562df01d80f6] #31 in /opt/conda/envs/rapids/bin/python(_PyEval_EvalFrameDefault+0x947) [0x562df01f5347] #32 in /opt/conda/envs/rapids/bin/python(_PyFunction_Vectorcall+0x1a6) [0x562df01d80f6] #33 in /opt/conda/envs/rapids/bin/python(_PyEval_EvalFrameDefault+0xa63) [0x562df01f5463] #34 in /opt/conda/envs/rapids/bin/python(_PyEval_EvalCodeWithName+0x2c3) [0x562df01d6ee3] #35 in /opt/conda/envs/rapids/bin/python(_PyFunction_Vectorcall+0x378) [0x562df01d82c8] #36 in /opt/conda/envs/rapids/bin/python(+0x1b0971) [0x562df01d8971] #37 in /opt/conda/envs/rapids/bin/python(PyObject_Call+0x5e) [0x562df014cf2e] #38 in /opt/conda/envs/rapids/bin/python(_PyEval_EvalFrameDefault+0x2113) [0x562df01f6b13] #39 in /opt/conda/envs/rapids/bin/python(_PyEval_EvalCodeWithName+0x2c3) [0x562df01d6ee3] #40 in /opt/conda/envs/rapids/bin/python(+0x1b09e7) [0x562df01d89e7] #41 in /opt/conda/envs/rapids/bin/python(_PyEval_EvalFrameDefault+0x178e) [0x562df01f618e] #42 in /opt/conda/envs/rapids/bin/python(+0x191cca) [0x562df01b9cca] #43 in /opt/conda/envs/rapids/bin/python(+0x128bdb) [0x562df0150bdb] #44 in /opt/conda/envs/rapids/bin/python(+0x13b64a) [0x562df016364a] #45 in /opt/conda/envs/rapids/bin/python(+0x21c42f) [0x562df024442f] #46 in /opt/conda/envs/rapids/bin/python(+0x128e52) [0x562df0150e52] #47 in /opt/conda/envs/rapids/bin/python(_PyEval_EvalFrameDefault+0x947) [0x562df01f5347] #48 in /opt/conda/envs/rapids/bin/python(_PyEval_EvalCodeWithName+0x2c3) [0x562df01d6ee3] #49 in /opt/conda/envs/rapids/bin/python(_PyFunction_Vectorcall+0x378) [0x562df01d82c8] #50 in /opt/conda/envs/rapids/bin/python(_PyEval_EvalFrameDefault+0xa63) [0x562df01f5463] #51 in /opt/conda/envs/rapids/bin/python(+0x191cca) [0x562df01b9cca] #52 in /opt/conda/envs/rapids/bin/python(+0x128bdb) [0x562df0150bdb] #53 in /opt/conda/envs/rapids/bin/python(+0x13b64a) [0x562df016364a] #54 in /opt/conda/envs/rapids/bin/python(+0x21c42f) [0x562df024442f] #55 in /opt/conda/envs/rapids/bin/python(+0x128e52) [0x562df0150e52] #56 in /opt/conda/envs/rapids/bin/python(_PyEval_EvalFrameDefault+0x947) [0x562df01f5347] #57 in /opt/conda/envs/rapids/bin/python(_PyEval_EvalCodeWithName+0x2c3) [0x562df01d6ee3] #58 in /opt/conda/envs/rapids/bin/python(+0x1b09e7) [0x562df01d89e7] #59 in /opt/conda/envs/rapids/bin/python(_PyEval_EvalFrameDefault+0x947) [0x562df01f5347] #60 in /opt/conda/envs/rapids/bin/python(+0x191cca) [0x562df01b9cca] #61 in /opt/conda/envs/rapids/bin/python(+0x128bdb) [0x562df0150bdb] #62 in /opt/conda/envs/rapids/bin/python(+0x13b64a) [0x562df016364a] #63 in /opt/conda/envs/rapids/bin/python(+0x21c42f) [0x562df024442f] ```

Expected behavior They should do the checks at the same place either at Python level or at C++ level and return the same message.

Environment details (please complete the following information): docker pull rapidsai/rapidsai-core-dev-nightly:21.10-cuda11.0-devel-ubuntu18.04-py3.8

github-actions[bot] commented 2 years ago

This issue has been labeled inactive-30d due to no recent activity in the past 30 days. Please close this issue if no further response or action is needed. Otherwise, please respond with a comment indicating any updates or changes to the original issue and/or confirm this issue still needs to be addressed. This issue will be labeled inactive-90d if there is no activity in the next 60 days.

github-actions[bot] commented 2 years ago

This issue has been labeled inactive-90d due to no recent activity in the past 90 days. Please close this issue if no further response or action is needed. Otherwise, please respond with a comment indicating any updates or changes to the original issue and/or confirm this issue still needs to be addressed.