faiss/contrib/torch/quantization.py
Matthijs Douze 6baebe2cee begin torch_contrib (#3872)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/3872

The contrib.torch subdirectory is intended to receive modules in python that are useful for similarity search and that apply to CPU or GPU pytorch tensors.

The current version includes CPU clustering on torch tensors. To be added:
* implementation of PQ

Reviewed By: asadoughi

Differential Revision: D62759207

fbshipit-source-id: 87dbaa5083e3f2f4f60526815e22ded4e83e8559
2024-09-20 09:15:27 -07:00

54 lines
1.0 KiB
Python

# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
"""
This contrib module contains Pytorch code for quantization.
"""
import numpy as np
import torch
import faiss
from faiss.contrib import torch_utils
class Quantizer:
def __init__(self, d, code_size):
self.d = d
self.code_size = code_size
def train(self, x):
pass
def encode(self, x):
pass
def decode(self, x):
pass
class VectorQuantizer(Quantizer):
def __init__(self, d, k):
code_size = int(torch.ceil(torch.log2(k) / 8))
Quantizer.__init__(d, code_size)
self.k = k
def train(self, x):
pass
class ProductQuantizer(Quantizer):
def __init__(self, d, M, nbits):
code_size = int(torch.ceil(M * nbits / 8))
Quantizer.__init__(d, code_size)
self.M = M
self.nbits = nbits
def train(self, x):
pass