-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
66 changed files
with
4,889 additions
and
319 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
server/exllamav2_kernels/exllamav2_kernels/cpp/quantize_func.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#include "quantize_func.h" | ||
#include "../cuda/quantize.cuh" | ||
|
||
void quantize_range | ||
( | ||
torch::Tensor quant, | ||
torch::Tensor scale, | ||
torch::Tensor out_q, | ||
float qzero, | ||
float maxq, | ||
torch::Tensor hessian_inv, | ||
torch::Tensor weights, | ||
torch::Tensor error, | ||
int a, | ||
int b | ||
) | ||
{ | ||
int columns = weights.size(1); | ||
int hcolumns = hessian_inv.size(1); | ||
TORCH_CHECK(hcolumns == weights.size(0), "H shape mismatch") | ||
|
||
for (int c = a; c < b; c++) | ||
{ | ||
fused_quantize_adjust_cuda | ||
( | ||
(const float*) weights.data_ptr(), | ||
(float*) quant.data_ptr(), | ||
(const float*) scale.data_ptr(), | ||
out_q.device().is_meta() ? NULL : (uint16_t*) out_q.data_ptr(), | ||
(const float*) hessian_inv.data_ptr(), | ||
(float*) error.data_ptr(), | ||
c, // row | ||
hcolumns, // rows | ||
columns, | ||
qzero, | ||
maxq | ||
); | ||
|
||
vv_mul_sub_cuda | ||
( | ||
((const float*) hessian_inv.data_ptr()) + c * hcolumns + c, | ||
((const float*) error.data_ptr()) + c * columns, | ||
((float*) weights.data_ptr()) + c * columns, | ||
b - c, | ||
columns | ||
); | ||
} | ||
|
||
torch::Tensor x = hessian_inv.slice(0, a, b).slice(1, b).transpose(0, 1); | ||
torch::Tensor y = error.slice(0, a, b); | ||
weights.slice(0, b).addmm_(x, y, 1.0f, -1.0f); | ||
} |
25 changes: 25 additions & 0 deletions
25
server/exllamav2_kernels/exllamav2_kernels/cpp/quantize_func.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#ifndef _quantize_func_h | ||
#define _quantize_func_h | ||
|
||
#include <torch/extension.h> | ||
#include <cuda_runtime.h> | ||
#include <cuda_fp16.h> | ||
#include <ATen/cuda/CUDAContext.h> | ||
#include <cstdint> | ||
#include <cstdio> | ||
|
||
void quantize_range | ||
( | ||
torch::Tensor quant, | ||
torch::Tensor scale, | ||
torch::Tensor out_q, | ||
float qzero, | ||
float maxq, | ||
torch::Tensor hessian_inv, | ||
torch::Tensor weights, | ||
torch::Tensor error, | ||
int a, | ||
int b | ||
); | ||
|
||
#endif |
Oops, something went wrong.