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

[BUG] SVR throwing cuBLAS error during inference #4033

Closed
aerdem4 opened this issue Jul 6, 2021 · 2 comments · Fixed by #4097
Closed

[BUG] SVR throwing cuBLAS error during inference #4033

aerdem4 opened this issue Jul 6, 2021 · 2 comments · Fixed by #4097
Assignees
Labels
? - Needs Triage Need team to review and classify bug Something isn't working

Comments

@aerdem4
Copy link
Contributor

aerdem4 commented Jul 6, 2021

Describe the bug
SVR throws error during inference: RuntimeError: cuBLAS error encountered at: file=../src_prims/matrix/grammatrix.cuh line=134: call='raft::linalg::cublasgemm( cublas_handle, CUBLAS_OP_N, CUBLAS_OP_T, n1, n2, n_cols, &alpha, x1, ld1, x2, ld2, &beta, out, ld_out, stream)', Reason=7:CUBLAS_STATUS_INVALID_VALUE
Obtained 64 stack frames

Steps/Code to reproduce bug
You can reproduce the bug using this Kaggle kernel: https://www.kaggle.com/aerdem4/optiver-rapids-svr-wip

@aerdem4 aerdem4 added ? - Needs Triage Need team to review and classify bug Something isn't working labels Jul 6, 2021
@dantegd
Copy link
Member

dantegd commented Jul 6, 2021

@tfeher might be the best person to take a look at this

@tfeher tfeher self-assigned this Jul 6, 2021
@tfeher
Copy link
Contributor

tfeher commented Jul 22, 2021

Here is a simplified reproducer:

import cupy as cp
import cuml

shape = (10,1)
X = cp.random.uniform(size=shape, dtype=cp.float64)
y = cp.ones(shape)

model = cuml.svm.SVR(kernel="linear", degree=3, C=10, verbose=cuml.common.logger.level_debug)
model.fit(X, y)

print("Fit status:", model._fit_status_)
print("n_support:", model.n_support_)

model.predict(X)

Output:

SMO solver finished after 1 outer iterations, total inner iterations, and diff -0.200000
Fit status: 0
n_support: None

...
RuntimeError: cuBLAS error encountered at: file=../src_prims/matrix/grammatrix.cuh line=165: call='raft::linalg::cublasgemm(cublas_handle, CUBLAS_OP_N, CUBLAS_OP_T, n1, n2, n_cols, &alpha, x1, ld1, x2, ld2, &beta, out, ld_out, stream)', Reason=7:CUBLAS_STATUS_INVALID_VALUE

Note that the SVM is seems to be fitted correctly (fit_status == 0), but the parameters of the SVM is not stored (n_support=None). The example here can be fitted with a bias only. It seems that the classier does not handle the corner case where we have zero support vectors.

I will fix this.

rapids-bot bot pushed a commit that referenced this issue Jul 26, 2021
Fixes #4033

This PR fixes SVM model parameter handling in case the fitted model has no support vectors, only bias.
C++ side changes:
- The bias calculation is updated to calculate the bias as the average function value in this case.
- The prediction function is modified to avoid kernel function calculation in this case.
- Added an SVR unit test to check model fitting and prediction.

Python side changes:
- It was incorrectly assumed that n_support==0 means the model is not fitted correctly, this is removed.
- Model attributes (`dual_coef_`, `support_`, `support_vectors_`) are defined as empty arrays in this case.
- `coef_` attribute is an array of zeros if there are no support vectors.
- Unit test added to check training prediction and model attributes.

Authors:
  - Tamas Bela Feher (https://github.com/tfeher)

Approvers:
  - Dante Gama Dessavre (https://github.com/dantegd)

URL: #4097
vimarsh6739 pushed a commit to vimarsh6739/cuml that referenced this issue Oct 9, 2023
Fixes rapidsai#4033

This PR fixes SVM model parameter handling in case the fitted model has no support vectors, only bias.
C++ side changes:
- The bias calculation is updated to calculate the bias as the average function value in this case.
- The prediction function is modified to avoid kernel function calculation in this case.
- Added an SVR unit test to check model fitting and prediction.

Python side changes:
- It was incorrectly assumed that n_support==0 means the model is not fitted correctly, this is removed.
- Model attributes (`dual_coef_`, `support_`, `support_vectors_`) are defined as empty arrays in this case.
- `coef_` attribute is an array of zeros if there are no support vectors.
- Unit test added to check training prediction and model attributes.

Authors:
  - Tamas Bela Feher (https://github.com/tfeher)

Approvers:
  - Dante Gama Dessavre (https://github.com/dantegd)

URL: rapidsai#4097
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
? - Needs Triage Need team to review and classify bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants