K-Nearest Neighbor in Pytorch

Overview

Pytorch KNN CUDA

  • 2019/11/02 This repository will no longer be maintained as pytorch supports sort() and kthvalue on tensors.
git clone https://github.com/chrischoy/pytorch_knn_cuda
cd pytorch_knn_cuda
make
python __init__.py
You might also like...
RealFormer-Pytorch Implementation of RealFormer using pytorch
RealFormer-Pytorch Implementation of RealFormer using pytorch

RealFormer-Pytorch Implementation of RealFormer using pytorch. Includes comparison with classical Transformer on image classification task (ViT) wrt C

Generic template to bootstrap your PyTorch project with PyTorch Lightning, Hydra, W&B, and DVC.

NN Template Generic template to bootstrap your PyTorch project. Click on Use this Template and avoid writing boilerplate code for: PyTorch Lightning,

A PyTorch Extension: Tools for easy mixed precision and distributed training in Pytorch

This repository holds NVIDIA-maintained utilities to streamline mixed precision and distributed training in Pytorch. Some of the code here will be included in upstream Pytorch eventually. The intention of Apex is to make up-to-date utilities available to users as quickly as possible.

Objective of the repository is to learn and build machine learning models using Pytorch. 30DaysofML Using Pytorch
Objective of the repository is to learn and build machine learning models using Pytorch. 30DaysofML Using Pytorch

30 Days Of Machine Learning Using Pytorch Objective of the repository is to learn and build machine learning models using Pytorch. List of Algorithms

Pretrained SOTA Deep Learning models, callbacks and more for research and production with PyTorch Lightning and PyTorch
Pretrained SOTA Deep Learning models, callbacks and more for research and production with PyTorch Lightning and PyTorch

Pretrained SOTA Deep Learning models, callbacks and more for research and production with PyTorch Lightning and PyTorch

Amazon Forest Computer Vision: Satellite Image tagging code using PyTorch / Keras with lots of PyTorch tricks
Amazon Forest Computer Vision: Satellite Image tagging code using PyTorch / Keras with lots of PyTorch tricks

Amazon Forest Computer Vision Satellite Image tagging code using PyTorch / Keras Here is a sample of images we had to work with Source: https://www.ka

The Incredible PyTorch: a curated list of tutorials, papers, projects, communities and more relating to PyTorch.
The Incredible PyTorch: a curated list of tutorials, papers, projects, communities and more relating to PyTorch.

This is a curated list of tutorials, projects, libraries, videos, papers, books and anything related to the incredible PyTorch. Feel free to make a pu

A PyTorch implementation of the paper Mixup: Beyond Empirical Risk Minimization in PyTorch
A PyTorch implementation of the paper Mixup: Beyond Empirical Risk Minimization in PyTorch

Mixup: Beyond Empirical Risk Minimization in PyTorch This is an unofficial PyTorch implementation of mixup: Beyond Empirical Risk Minimization. The co

A pytorch implementation of  Pytorch-Sketch-RNN
A pytorch implementation of Pytorch-Sketch-RNN

Pytorch-Sketch-RNN A pytorch implementation of https://arxiv.org/abs/1704.03477 In order to draw other things than cats, you will find more drawing da

Comments
  • can not compile this when run make command

    can not compile this when run make command

    root@fbecc9ba5bb2:/pytorch_knn_cuda# make

    Separate cpp shared library that will be loaded to the extern C ffi

    nvcc -c -o build/knn_cuda_kernel.so src/knn_cuda_kernel.cu -x cu -Xcompiler -fPIC -shared -Isrc make: nvcc: Command not found Makefile:34: recipe for target 'build/knn_cuda_kernel.so' failed make: *** [build/knn_cuda_kernel.so] Error 127 root@fbecc9ba5bb2:/pytorch_knn_cuda#

    did anyone got this error as me, I do not know how to fix it.

    opened by EulerWong 1
  • making code compatible with pytorch v0.4.1

    making code compatible with pytorch v0.4.1

    Due to some API changes made in pytorch v0.4.1 pytorch_knn_cuda was no longer able to compile (see issue #3).
    This PR makes the required changes, it now works with pytorch v.0.4.1

    opened by shaibagon 1
  • Cannot compile with pyotrch 0.4.1

    Cannot compile with pyotrch 0.4.1

    Getting error

    gcc -pthread -B /home/bagon/anaconda3/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -DWITH_CUDA -I/home/bagon/anaconda3/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include -I/home/bagon/anaconda3/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/TH -I/home/bagon/anaconda3/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/THC -I/usr/local/cuda/include -I/home/bagon/anaconda3/pkgs/pytorch_knn_cuda/include -I/home/bagon/anaconda3/include/python3.6m -c /home/bagon/anaconda3/pkgs/pytorch_knn_cuda/src/knn_pytorch.c -o ./home/bagon/anaconda3/pkgs/pytorch_knn_cuda/src/knn_pytorch.o -std=c99
    In file included from /home/bagon/anaconda3/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/THC/THCGeneral.h:4:0,
                     from /home/bagon/anaconda3/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/THC/THC.h:4,
                     from /home/bagon/anaconda3/pkgs/pytorch_knn_cuda/src/knn_pytorch.c:1:
    /home/bagon/anaconda3/pkgs/pytorch_knn_cuda/src/knn_pytorch.c: In function ‘knn’:
    /home/bagon/anaconda3/pkgs/pytorch_knn_cuda/src/knn_pytorch.c:11:24: error: dereferencing pointer to incomplete type ‘THTensor {aka struct THTensor}’
       THArgCheck(ref_tensor->nDimension == 2 , 0, "ref_tensor: 2D Tensor expected");
                            ^
    /home/bagon/anaconda3/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/TH/THGeneral.h:111:35: note: in definition of macro ‘THArgCheck’
       _THArgCheck(__FILE__, __LINE__, __VA_ARGS__);
    

    It seems like the definition of struct THTensor was moved from THTensor.h to THTensor.hpp and this causes this issue.

    Any way to workaround this?

    opened by shaibagon 0
  • Illegal memory access with large N*M

    Illegal memory access with large N*M

    Tried on 10,000 reference points, 100 query points, and 3 feature dimensions, this crashes with the error:

    RuntimeError: cuda runtime error (77) : an illegal memory access was encountered at /pytorch/torch/lib/THC/generic/THCTensorCopy.c:70

    The error does not appear when executing the KNN code, but only when trying to assign or access any data on the GPU (including the results) after the code is called. Tested with GeForce GTX 1080 with 8 GB of VRAM.

    opened by agarret7 6
Owner
Chris Choy
Research Scientist @NVIDIA. Previously Ph.D. from Stanford Vision and Learning Lab @StanfordVL (SVL), Stanford AI Lab, SAIL.
Chris Choy
Simple and Effective Few-Shot Named Entity Recognition with Structured Nearest Neighbor Learning

structshot Code and data for paper "Simple and Effective Few-Shot Named Entity Recognition with Structured Nearest Neighbor Learning", Yi Yang and Arz

ASAPP Research 47 Dec 27, 2022
Optimal space decomposition based-product quantization for approximate nearest neighbor search

Optimal space decomposition based-product quantization for approximate nearest neighbor search Abstract Product quantization(PQ) is an effective neare

Mylove 1 Nov 19, 2021
Personal implementation of paper "Approximate Nearest Neighbor Negative Contrastive Learning for Dense Text Retrieval"

Approximate Nearest Neighbor Negative Contrastive Learning for Dense Text Retrieval This repo provides personal implementation of paper Approximate Ne

John 8 Oct 7, 2022
GPU implementation of $k$-Nearest Neighbors and Shared-Nearest Neighbors

GPU implementation of kNN and SNN GPU implementation of $k$-Nearest Neighbors and Shared-Nearest Neighbors Supported by numba cuda and faiss library E

Hyeon Jeon 7 Nov 23, 2022
Code for Subgraph Federated Learning with Missing Neighbor Generation (NeurIPS 2021)

To run the code Unzip the package to your local directory; Run 'pip install -r requirements.txt' to download required packages; Open file ~/nips_code/

null 32 Dec 26, 2022
Approximate Nearest Neighbors in C++/Python optimized for memory usage and loading/saving to disk

Annoy Annoy (Approximate Nearest Neighbors Oh Yeah) is a C++ library with Python bindings to search for points in space that are close to a given quer

Spotify 10.6k Jan 4, 2023
A gesture recognition system powered by OpenPose, k-nearest neighbours, and local outlier factor.

OpenHands OpenHands is a gesture recognition system powered by OpenPose, k-nearest neighbours, and local outlier factor. Currently the system can iden

Paul Treanor 12 Jan 10, 2022
Weighted K Nearest Neighbors (kNN) algorithm implemented on python from scratch.

kNN_From_Scratch I implemented the k nearest neighbors (kNN) classification algorithm on python. This algorithm is used to predict the classes of new

null 1 Dec 14, 2021
An essential implementation of BYOL in PyTorch + PyTorch Lightning

Essential BYOL A simple and complete implementation of Bootstrap your own latent: A new approach to self-supervised Learning in PyTorch + PyTorch Ligh

Enrico Fini 48 Sep 27, 2022