All Projects → KinglittleQ → Torch Batch Svd

KinglittleQ / Torch Batch Svd

Licence: mit
A 100x faster SVD for PyTorch⚡️

Projects that are alternatives of or similar to Torch Batch Svd

math105A
Numerical analysis course in Python
Stars: ✭ 20 (-81.31%)
Mutual labels:  svd
Surprise
A Python scikit for building and analyzing recommender systems
Stars: ✭ 5,151 (+4714.02%)
Mutual labels:  svd
Deeplearning Mxnet
MXNet for CTR
Stars: ✭ 51 (-52.34%)
Mutual labels:  svd
moses
Streaming, Memory-Limited, r-truncated SVD Revisited!
Stars: ✭ 19 (-82.24%)
Mutual labels:  svd
Nlp
Selected Machine Learning algorithms for natural language processing and semantic analysis in Golang
Stars: ✭ 304 (+184.11%)
Mutual labels:  svd
Ngram2vec
Four word embedding models implemented in Python. Supporting arbitrary context features
Stars: ✭ 703 (+557.01%)
Mutual labels:  svd
ALRA
Imputation method for scRNA-seq based on low-rank approximation
Stars: ✭ 48 (-55.14%)
Mutual labels:  svd
Ml code
A repository for recording the machine learning code
Stars: ✭ 75 (-29.91%)
Mutual labels:  svd
H2o4gpu
H2Oai GPU Edition
Stars: ✭ 416 (+288.79%)
Mutual labels:  svd
Genericsvd.jl
Singular Value Decomposition for generic number types
Stars: ✭ 40 (-62.62%)
Mutual labels:  svd
Tf-Rec
Tf-Rec is a python💻 package for building⚒ Recommender Systems. It is built on top of Keras and Tensorflow 2 to utilize GPU Acceleration during training.
Stars: ✭ 18 (-83.18%)
Mutual labels:  svd
Digital-Image-Watermarking
Digital Image Watermarking Method Based on Hybrid DWT-HD-SVD Technique: Attacks, PSNR, SSIM, NC
Stars: ✭ 37 (-65.42%)
Mutual labels:  svd
Letterboxd recommendations
Scraping publicly-accessible Letterboxd data and creating a movie recommendation model with it that can generate recommendations when provided with a Letterboxd username
Stars: ✭ 23 (-78.5%)
Mutual labels:  svd
RSpectra
R Interface to the Spectra Library for Large Scale Eigenvalue and SVD Problems
Stars: ✭ 68 (-36.45%)
Mutual labels:  svd
Recommender
A recommendation system using tensorflow
Stars: ✭ 69 (-35.51%)
Mutual labels:  svd
tf-recsys
tf-recsys contains collaborative filtering (CF) model based on famous SVD and SVD++ algorithm. Both of them are implemented by tensorflow in order to utilize GPU acceleration.
Stars: ✭ 91 (-14.95%)
Mutual labels:  svd
Prince
👑 Python factor analysis library (PCA, CA, MCA, MFA, FAMD)
Stars: ✭ 591 (+452.34%)
Mutual labels:  svd
Ristretto
Randomized Dimension Reduction Library
Stars: ✭ 92 (-14.02%)
Mutual labels:  svd
Recommend
Python 3.6 下的推荐算法解析,尽量使用简单的语言剖析原理,相似度度量、协同过滤、矩阵分解等
Stars: ✭ 72 (-32.71%)
Mutual labels:  svd
Ailearning
AiLearning: 机器学习 - MachineLearning - ML、深度学习 - DeepLearning - DL、自然语言处理 NLP
Stars: ✭ 32,316 (+30101.87%)
Mutual labels:  svd

Pytorch Batched SVD

1) Introduction

A batched version of SVD in Pytorch implemented using cuSolver including forward and backward function. In terms of speed, it is superior to that of torch.svd.

matrix size torch_batch_svd.svd torch.svd
(10000, 9, 9) 0.043 s 19.352 s
(20000, 9, 9) 0.073 s 34.578 s
import torch
from torch_batch_svd import svd

A = torch.rand(1000000, 3, 3).cuda()
u, s, v = svd(A)
u, s, v = torch.svd(A)  # probably you should take a coffee break here

The catch here is that it only works for matrices whose row and column are smaller than 32. Other than that, torch_batch_svd.svd can be a drop-in for the native one.

The forward function is modified from ShigekiKarita/pytorch-cusolver and I fixed several bugs of it. The backward function is borrowed from the pytorch official svd backward function. I converted it to a batched version.

NOTE: batch_svd supports all torch.half, torch.float and torch.double tensors now.

NOTE: SVD for torch.half is performed by casting to torch.float as there is no CuSolver implementation for c10::half.

NOTE: Sometimes, tests will fail for torch.double tensor due to numerical imprecision.

2) Requirements

  • Pytorch >= 1.0

    diag_embed() is used in torch_batch_svd.cpp at the backward function. Pytorch with version lower than 1.0 does not contain diag_embed(). If you want to use it in a lower version of pytorch, you can replace diag_embed() by some existing functions.

  • CUDA 9.0/10.2 (should work with 10.0/10.1 too)

  • Tested in Pytorch 1.4 & 1.5, with CUDA 10.2

3) Install

Set environment variables

export CUDA_HOME=/your/cuda/home/directory/
export LIBRARY_PATH=$LIBRARY_PATH:/your/cuda/lib64/  (optional)

Run setup.py

python setup.py install

Run test.py

cd tests
python -m pytest test.py

4) Differences between torch.svd()

  • The sign of column vectors at U and V may be different from torch.svd().

  • Much more faster than torch.svd() using loop.

5) Example

See test.py and introduction.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].