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] cuml PCA transform() requires n_rows > 1 #2804

Closed
ngs2410 opened this issue Sep 9, 2020 · 2 comments · Fixed by #2829
Closed

[BUG] cuml PCA transform() requires n_rows > 1 #2804

ngs2410 opened this issue Sep 9, 2020 · 2 comments · Fixed by #2829
Assignees
Labels
bug Something isn't working

Comments

@ngs2410
Copy link

ngs2410 commented Sep 9, 2020

Describe the bug
cuml PCA .transform() requires n_rows > 1 which is surprising as sklearn PCA doesn't have the same requirement.

I caught this trying to make predictions using a previously saved model that included a pipeline with a cuml PCA model. In my case, predictions are over a single example. My workaround will be to tile the example but it feels like this should not be necessary.

Traceback (most recent call last):
  File "test3.py", line 9, in <module>
    y = model.transform(predict)
  File "/home/ngs/miniconda3/envs/cuml14/lib/python3.7/site-packages/cuml/common/memory_utils.py", line 56, in cupy_rmm_wrapper
    return func(*args, **kwargs)
  File "cuml/decomposition/pca.pyx", line 716, in cuml.decomposition.pca.PCA.transform
RuntimeError: Exception occured! file=/opt/conda/envs/rapids/conda-bld/libcuml_1598033241212/work/cpp/src/pca/pca.cuh line=230: Parameter n_rows: number of rows cannot be less than two

Steps/Code to reproduce bug

This code throws the exception using cuml PCA but works fine using sklearn PCA:

import numpy as np
# from sklearn.decomposition import PCA
from cuml.decomposition import PCA

train = np.asfortranarray(np.random.randn(10,10))
predict = np.asfortranarray(np.random.randn(1,10))
model = PCA(n_components=4)
model.fit(train)
y = model.transform(predict)

Expected behavior
I expected cuml PCA transform() to be able to transform a single example.

Environment details:

Click here to see environment details
 **git***
 Not inside a git repository
 
 ***OS Information***
 DISTRIB_ID=Ubuntu
 DISTRIB_RELEASE=20.04
 DISTRIB_CODENAME=focal
 DISTRIB_DESCRIPTION="Ubuntu 20.04.1 LTS"
 NAME="Ubuntu"
 VERSION="20.04.1 LTS (Focal Fossa)"
 ID=ubuntu
 ID_LIKE=debian
 PRETTY_NAME="Ubuntu 20.04.1 LTS"
 VERSION_ID="20.04"
 HOME_URL="https://www.ubuntu.com/"
 SUPPORT_URL="https://help.ubuntu.com/"
 BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
 PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
 VERSION_CODENAME=focal
 UBUNTU_CODENAME=focal
 Linux boots 5.4.0-42-generic #46-Ubuntu SMP Fri Jul 10 00:24:02 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
 
 ***GPU Information***
 Tue Sep  8 17:42:25 2020
 +-----------------------------------------------------------------------------+
 | NVIDIA-SMI 440.100      Driver Version: 440.100      CUDA Version: 10.2     |
 |-------------------------------+----------------------+----------------------+
 | GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
 | Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
 |===============================+======================+======================|
 |   0  GeForce GTX 166...  Off  | 00000000:01:00.0  On |                  N/A |
 |  0%   49C    P8    15W / 120W |   1275MiB /  5936MiB |      6%      Default |
 +-------------------------------+----------------------+----------------------+
 |   1  GeForce GTX 108...  Off  | 00000000:21:00.0 Off |                  N/A |
 |  0%   42C    P8    10W / 250W |     12MiB / 11178MiB |      0%      Default |
 +-------------------------------+----------------------+----------------------+
 
 +-----------------------------------------------------------------------------+
 | Processes:                                                       GPU Memory |
 |  GPU       PID   Type   Process name                             Usage      |
 |=============================================================================|
 |    0      2065      G   /usr/lib/xorg/Xorg                           198MiB |
 |    0      3002      G   /usr/lib/xorg/Xorg                           538MiB |
 |    0      3205      G   /usr/bin/gnome-shell                         296MiB |
 |    0      5636      G   ...quest-channel-token=7969671501842603176   228MiB |
 +-----------------------------------------------------------------------------+
 
 ***CPU***
 Architecture:                    x86_64
 CPU op-mode(s):                  32-bit, 64-bit
 Byte Order:                      Little Endian
 Address sizes:                   43 bits physical, 48 bits virtual
 CPU(s):                          128
 On-line CPU(s) list:             0-127
 Thread(s) per core:              2
 Core(s) per socket:              64
 Socket(s):                       1
 NUMA node(s):                    1
 Vendor ID:                       AuthenticAMD
 CPU family:                      23
 Model:                           49
 Model name:                      AMD Ryzen Threadripper 3990X 64-Core Processor
 Stepping:                        0
 Frequency boost:                 enabled
 CPU MHz:                         2208.591
 CPU max MHz:                     2900.0000
 CPU min MHz:                     2200.0000
 BogoMIPS:                        5800.23
 Virtualization:                  AMD-V
 L1d cache:                       2 MiB
 L1i cache:                       2 MiB
 L2 cache:                        32 MiB
 L3 cache:                        256 MiB
 NUMA node0 CPU(s):               0-127
 Vulnerability Itlb multihit:     Not affected
 Vulnerability L1tf:              Not affected
 Vulnerability Mds:               Not affected
 Vulnerability Meltdown:          Not affected
 Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl and seccomp
 Vulnerability Spectre v1:        Mitigation; usercopy/swapgs barriers and __user pointer sanitization
 Vulnerability Spectre v2:        Mitigation; Full AMD retpoline, IBPB conditional, STIBP conditional, RSB filling
 Vulnerability Srbds:             Not affected
 Vulnerability Tsx async abort:   Not affected
 Flags:                           fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm constant_tsc rep_good nopl nonstop_tsc cpuid extd_apicid aperfmperf pni pclmulqdq monitor ssse3 fma cx16 sse4_1 sse4_2 movbe popcnt aes xsave avx f16c rdrand lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw ibs skinit wdt tce topoext perfctr_core perfctr_nb bpext perfctr_llc mwaitx cpb cat_l3 cdp_l3 hw_pstate sme ssbd mba sev ibpb stibp vmmcall fsgsbase bmi1 avx2 smep bmi2 cqm rdt_a rdseed adx smap clflushopt clwb sha_ni xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local clzero irperf xsaveerptr wbnoinvd arat npt lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid decodeassists pausefilter pfthreshold avic v_vmsave_vmload vgif umip rdpid overflow_recov succor smca
 
 ***CMake***
 
 ***g++***
 /usr/bin/g++
 g++ (Ubuntu 9.3.0-10ubuntu2) 9.3.0
 Copyright (C) 2019 Free Software Foundation, Inc.
 This is free software; see the source for copying conditions.  There is NO
 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
 
 ***nvcc***
 /usr/bin/nvcc
 nvcc: NVIDIA (R) Cuda compiler driver
 Copyright (c) 2005-2019 NVIDIA Corporation
 Built on Sun_Jul_28_19:07:16_PDT_2019
 Cuda compilation tools, release 10.1, V10.1.243
 
 ***Python***
 /home/ngs/miniconda3/envs/cuml14/bin/python
 Python 3.7.7
 
 ***Environment Variables***
 PATH                            : /home/ngs/miniconda3/envs/cuml14/bin:/home/ngs/miniconda3/condabin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
 LD_LIBRARY_PATH                 :
 NUMBAPRO_NVVM                   :
 NUMBAPRO_LIBDEVICE              :
 CONDA_PREFIX                    : /home/ngs/miniconda3/envs/cuml14
 PYTHON_PATH                     :
 
 ***conda packages***
 /home/ngs/miniconda3/condabin/conda
 # packages in environment at /home/ngs/miniconda3/envs/cuml14:
 #
 # Name                    Version                   Build  Channel
 _libgcc_mutex             0.1                 conda_forge    conda-forge
 _openmp_mutex             4.5                       1_gnu    conda-forge
 abseil-cpp                20200225.2           he1b5a44_2    conda-forge
 absl-py                   0.10.0                   pypi_0    pypi
 arrow-cpp                 0.17.1          py37h1234567_11_cuda    conda-forge
 arrow-cpp-proc            1.0.0                      cuda    conda-forge
 astroid                   2.4.2            py37hc8dfbb8_0    conda-forge
 astunparse                1.6.3                    pypi_0    pypi
 aws-sdk-cpp               1.7.164              hba45d7a_2    conda-forge
 bokeh                     2.1.1            py37hc8dfbb8_0    conda-forge
 boost-cpp                 1.72.0               h7b93d67_2    conda-forge
 boto3                     1.14.47            pyh9f0ad1d_0    conda-forge
 botocore                  1.17.47            pyh9f0ad1d_0    conda-forge
 brotli                    1.0.7             he1b5a44_1004    conda-forge
 brotlipy                  0.7.0           py37h8f50634_1000    conda-forge
 bzip2                     1.0.8                h516909a_3    conda-forge
 c-ares                    1.16.1               h516909a_1    conda-forge
 ca-certificates           2020.6.20            hecda079_0    conda-forge
 cachetools                4.1.1                    pypi_0    pypi
 certifi                   2020.6.20        py37hc8dfbb8_0    conda-forge
 cffi                      1.14.1           py37he30daa8_0
 chardet                   3.0.4                    pypi_0    pypi
 click                     7.1.2              pyh9f0ad1d_0    conda-forge
 cloudpickle               1.5.0                      py_0    conda-forge
 cryptography              3.0              py37hb09aad4_0    conda-forge
 cudatoolkit               10.1.243             h6bb024c_0    nvidia
 cudf                      0.15.0a200821   cuda_10.1_py37_g1a3b3f217_4960    rapidsai-nightly
 cudnn                     7.6.0                cuda10.1_0    nvidia
 cuml                      0.15.0a200821   cuda10.1_py37_g5b13b4a61_2142    rapidsai-nightly
 cupy                      7.8.0            py37h0632833_0    conda-forge
 curl                      7.71.1               he644dc0_5    conda-forge
 cycler                    0.10.0                     py_2    conda-forge
 cytoolz                   0.10.1           py37h516909a_0    conda-forge
 dask                      2.23.0                     py_0    conda-forge
 dask-core                 2.23.0                     py_0    conda-forge
 dask-cudf                 0.15.0a200821   py37_g1a3b3f217_4960    rapidsai-nightly
 distributed               2.23.0           py37hc8dfbb8_0    conda-forge
 dlpack                    0.3                  he1b5a44_1    conda-forge
 dnspython                 1.16.0                     py_1    conda-forge
 docutils                  0.15.2                   py37_0    conda-forge
 double-conversion         3.1.5                he1b5a44_2    conda-forge
 ecdsa                     0.13                       py_0    conda-forge
 faiss-proc                1.0.0                      cuda    rapidsai-nightly
 fastavro                  0.24.2           py37h8f50634_0    conda-forge
 fastrlock                 0.5              py37h3340039_0    conda-forge
 filelock                  3.0.12                   pypi_0    pypi
 flock                     0.1                      pypi_0    pypi
 freetype                  2.10.2               he06d7ca_0    conda-forge
 fsspec                    0.8.0                      py_0    conda-forge
 gast                      0.3.3                    pypi_0    pypi
 gflags                    2.2.2             he1b5a44_1004    conda-forge
 glog                      0.4.0                h49b9bf7_3    conda-forge
 gmp                       6.2.0                he1b5a44_2    conda-forge
 google-auth               1.20.1                   pypi_0    pypi
 google-auth-oauthlib      0.4.1                    pypi_0    pypi
 google-pasta              0.2.0                    pypi_0    pypi
 grpc-cpp                  1.30.2               heedbac9_0    conda-forge
 grpcio                    1.31.0                   pypi_0    pypi
 h5py                      2.10.0                   pypi_0    pypi
 heapdict                  1.0.1                      py_0    conda-forge
 icu                       67.1                 he1b5a44_0    conda-forge
 idna                      2.10               pyh9f0ad1d_0    conda-forge
 iexfinance                0.4.3                    pypi_0    pypi
 importlib-metadata        1.7.0                    pypi_0    pypi
 isort                     4.3.21           py37hc8dfbb8_1    conda-forge
 jinja2                    2.11.2             pyh9f0ad1d_0    conda-forge
 jmespath                  0.10.0             pyh9f0ad1d_0    conda-forge
 joblib                    0.16.0                     py_0    conda-forge
 jpeg                      9d                   h516909a_0    conda-forge
 keras-preprocessing       1.1.2                    pypi_0    pypi
 kiwisolver                1.2.0            py37h99015e2_0    conda-forge
 krb5                      1.17.1               hfafb76e_2    conda-forge
 langdetect                1.0.7                      py_0    conda-forge
 lazy-object-proxy         1.4.3            py37h8f50634_2    conda-forge
 lcms2                     2.11                 hbd6801e_0    conda-forge
 ld_impl_linux-64          2.33.1               h53a641e_7
 libblas                   3.8.0               17_openblas    conda-forge
 libcblas                  3.8.0               17_openblas    conda-forge
 libcudf                   0.15.0a200821   cuda10.1_g1a3b3f217_4960    rapidsai-nightly
 libcuml                   0.15.0a200821   cuda10.1_g5b13b4a61_2142    rapidsai-nightly
 libcumlprims              0.15.0a200820       cuda10.1_61    rapidsai-nightly
 libcurl                   7.71.1               hcdd3856_5    conda-forge
 libedit                   3.1.20191231         h14c3975_1
 libev                     4.33                 h516909a_0    conda-forge
 libevent                  2.1.10               hcdb4288_2    conda-forge
 libfaiss                  1.6.3           he68dc02_1_cuda    conda-forge
 libffi                    3.3                  he6710b0_2
 libgcc-ng                 9.3.0               h24d8f2e_15    conda-forge
 libgfortran-ng            7.5.0               hdf63c60_15    conda-forge
 libgomp                   9.3.0               h24d8f2e_15    conda-forge
 libhwloc                  2.1.0                h3c4fd83_0    conda-forge
 libiconv                  1.16                 h516909a_0    conda-forge
 liblapack                 3.8.0               17_openblas    conda-forge
 libllvm10                 10.0.1               he513fc3_1    conda-forge
 libnghttp2                1.41.0               hab1572f_1    conda-forge
 libopenblas               0.3.10          pthreads_hb3c22a3_4    conda-forge
 libpng                    1.6.37               hed695b0_2    conda-forge
 libprotobuf               3.12.4               h8b12597_0    conda-forge
 librmm                    0.15.0a200821   cuda10.1_g178c2cd_723    rapidsai-nightly
 libssh2                   1.9.0                hab1572f_5    conda-forge
 libstdcxx-ng              9.1.0                hdf63c60_0
 libtiff                   4.1.0                hc7e4089_6    conda-forge
 libwebp-base              1.1.0                h516909a_3    conda-forge
 libxml2                   2.9.10               h68273f3_2    conda-forge
 llvmlite                  0.34.0           py37h5202443_0    conda-forge
 locket                    0.2.0                      py_2    conda-forge
 lz4-c                     1.9.2                he1b5a44_3    conda-forge
 markdown                  3.2.2                    pypi_0    pypi
 markupsafe                1.1.1            py37h8f50634_1    conda-forge
 matplotlib                3.3.1                         1    conda-forge
 matplotlib-base           3.3.1            py37hd478181_1    conda-forge
 mccabe                    0.6.1                      py_1    conda-forge
 msgpack-python            1.0.0            py37h99015e2_1    conda-forge
 mysql-common              8.0.21                        0    conda-forge
 mysql-connector-c         6.1.11            h876a3cc_1006    conda-forge
 mysql-connector-python    8.0.21           py37h023e13c_0    conda-forge
 mysql-libs                8.0.21               hf3661c5_0    conda-forge
 nccl                      2.7.8.1              h51cf6c1_0    conda-forge
 ncurses                   6.2                  he6710b0_1
 numba                     0.51.0           py37h9fdb41a_0    conda-forge
 numpy                     1.19.1           py37h7ea13bd_2    conda-forge
 oauthlib                  3.1.0                    pypi_0    pypi
 olefile                   0.46                       py_0    conda-forge
 openssl                   1.1.1g               h516909a_1    conda-forge
 opt-einsum                3.3.0                    pypi_0    pypi
 packaging                 20.4               pyh9f0ad1d_0    conda-forge
 pandas                    1.1.0            py37h3340039_0    conda-forge
 parquet-cpp               1.5.1                         2    conda-forge
 partd                     1.1.0                      py_0    conda-forge
 pillow                    7.2.0            py37h718be6c_1    conda-forge
 pip                       20.2.2                   py37_0
 protobuf                  3.12.4           py37h3340039_0    conda-forge
 psutil                    5.7.2            py37h8f50634_0    conda-forge
 pyaml                     20.4.0             pyh9f0ad1d_0    conda-forge
 pyarrow                   0.17.1          py37h1234567_11_cuda    conda-forge
 pyasn1                    0.4.8                    pypi_0    pypi
 pyasn1-modules            0.2.8                    pypi_0    pypi
 pycparser                 2.20               pyh9f0ad1d_2    conda-forge
 pycryptodome              3.9.7            py37hb05bdb2_1    conda-forge
 pylint                    2.5.3            py37hc8dfbb8_0    conda-forge
 pyopenssl                 19.1.0                     py_1    conda-forge
 pyparsing                 2.4.7              pyh9f0ad1d_0    conda-forge
 pysocks                   1.7.1            py37hc8dfbb8_1    conda-forge
 python                    3.7.7                hcff3b4d_5
 python-dateutil           2.8.1                      py_0    conda-forge
 python_abi                3.7                     1_cp37m    conda-forge
 pytz                      2020.1             pyh9f0ad1d_0    conda-forge
 pyyaml                    5.3.1            py37h8f50634_0    conda-forge
 re2                       2020.07.06           he1b5a44_1    conda-forge
 readline                  8.0                  h7b6447c_0
 regex                     2020.7.14                pypi_0    pypi
 requests                  2.24.0                   pypi_0    pypi
 requests-oauthlib         1.3.0                    pypi_0    pypi
 rmm                       0.15.0a200821   cuda_10.1_py37_g178c2cd_723    rapidsai-nightly
 rsa                       4.6                      pypi_0    pypi
 s3transfer                0.3.3            py37hc8dfbb8_1    conda-forge
 sacremoses                0.0.43                   pypi_0    pypi
 scikit-learn              0.23.2           py37h6785257_0    conda-forge
 scikit-optimize           0.7.4                      py_0    conda-forge
 scipy                     1.4.1                    pypi_0    pypi
 sentencepiece             0.1.91                   pypi_0    pypi
 setuptools                49.6.0                   py37_0
 six                       1.15.0             pyh9f0ad1d_0    conda-forge
 snakeviz                  2.1.0              pyh9f0ad1d_0    conda-forge
 snappy                    1.1.8                he1b5a44_3    conda-forge
 sortedcontainers          2.2.2              pyh9f0ad1d_0    conda-forge
 spdlog                    1.7.0                hc9558a2_2    conda-forge
 sqlite                    3.33.0               h62c20be_0
 ta                        0.5.25                   pypi_0    pypi
 tblib                     1.6.0                      py_0    conda-forge
 tensorboard               2.3.0                    pypi_0    pypi
 tensorboard-plugin-wit    1.7.0                    pypi_0    pypi
 tensorflow                2.3.0                    pypi_0    pypi
 tensorflow-estimator      2.3.0                    pypi_0    pypi
 tensorflow-hub            0.9.0                    pypi_0    pypi
 tensorflow-text           2.3.0                    pypi_0    pypi
 termcolor                 1.1.0                    pypi_0    pypi
 threadpoolctl             2.1.0              pyh5ca1d4c_0    conda-forge
 thrift-cpp                0.13.0               h62aa4f2_3    conda-forge
 tk                        8.6.10               hbc83047_0
 tokenizers                0.8.1rc1                 pypi_0    pypi
 toml                      0.10.1             pyh9f0ad1d_0    conda-forge
 toolz                     0.10.0                     py_0    conda-forge
 tornado                   6.0.4            py37h8f50634_1    conda-forge
 tqdm                      4.48.2                   pypi_0    pypi
 transformers              3.0.2                    pypi_0    pypi
 treelite                  0.92             py37h023e13c_2    conda-forge
 treelite-runtime          0.92                     pypi_0    pypi
 typed-ast                 1.4.1            py37h516909a_0    conda-forge
 typing_extensions         3.7.4.2                    py_0    conda-forge
 ucx                       1.8.1+g6b29558       ha5db111_0    rapidsai-nightly
 ucx-py                    0.15.0a200820+g6b29558        py37_212    rapidsai-nightly
 uriparser                 0.9.3                he1b5a44_1    conda-forge
 urllib3                   1.25.10                    py_0    conda-forge
 werkzeug                  1.0.1                    pypi_0    pypi
 wheel                     0.34.2                   py37_0
 wrapt                     1.11.2           py37h8f50634_0    conda-forge
 xgboost                   1.1.1                    pypi_0    pypi
 xz                        5.2.5                h7b6447c_0
 yaml                      0.2.5                h516909a_0    conda-forge
 zict                      2.0.0                      py_0    conda-forge
 zipp                      3.1.0                    pypi_0    pypi
 zlib                      1.2.11               h7b6447c_3
 zstd                      1.4.5                h6597ccf_2    conda-forge

@ngs2410 ngs2410 added ? - Needs Triage Need team to review and classify bug Something isn't working labels Sep 9, 2020
@cjnolet cjnolet self-assigned this Sep 10, 2020
@wphicks
Copy link
Contributor

wphicks commented Sep 15, 2020

Failing assertion that leads to the exception is here.

@wphicks wphicks removed the ? - Needs Triage Need team to review and classify label Sep 15, 2020
@wphicks
Copy link
Contributor

wphicks commented Sep 15, 2020

Whoops, submitted that comment before I was done. Adding on... I don't immediately see why this assertion would be necessary except if the whiten option is true. In the case of n_rows == 1, whitening obviously does not make sense, so we can probably add some special handling there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants