Skip to content

Instantly share code, notes, and snippets.

View Smthri's full-sized avatar
🧑‍💻
working

Никита Локшин Smthri

🧑‍💻
working
  • Samsung
  • Moscow, Russia
View GitHub Profile
@Smthri
Smthri / kernel.cpp
Last active October 22, 2020 18:10
template <typename scalar_t, typename idx_t>
void softmaxLUT_kernel(scalar_t* input, scalar_t* output, idx_t n, idx_t c, idx_t sizeC,
idx_t input_sN, idx_t input_sC, idx_t output_sN, idx_t output_sC,
idx_t multiplier, idx_t zero_point, idx_t* exp_table) {
/*
* Perform quantized softmax for one element
*
* output_i = multiplier / sum (table[A_j - A_i + 255] for all j)
*/
import os
import sys
import argparse
import numpy as np
import torch
import torch.quantization as tq
from pathlib import Path
from torch import nn
from _collections_abc import Iterable
from collections import OrderedDict
@Smthri
Smthri / quantization_test.py
Last active August 16, 2021 08:07
Our result is approximately equal to the float output of the non-quantized convolution. However, sometimes PyTorch yields result with a large error.
import numpy as np
import torch
import torch.quantization as tq
from torch import nn
from copy import deepcopy
## Manual quantization
# weight, bias, input
kernel_size = 3