-
Notifications
You must be signed in to change notification settings - Fork 3k
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
1 changed file
with
7 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ | |
import importlib | ||
import logging | ||
import os | ||
from typing import List, Optional | ||
from typing import Optional | ||
|
||
import numpy as np | ||
import numpy.typing as npt | ||
|
@@ -155,7 +155,7 @@ def optimize_weights( | |
tensor: np.ndarray, | ||
scale: np.ndarray, | ||
zero: np.ndarray, | ||
min_max: List[int], | ||
min_max: list[int], | ||
axis: int = 0, | ||
opt_params: Optional[dict] = None, | ||
Check warning Code scanning / lintrunner RUFF/UP007 Warning
Use X | Y for type annotations.
See https://docs.astral.sh/ruff/rules/non-pep604-annotation |
||
verbose=False, | ||
|
@@ -184,10 +184,10 @@ def shrink_op(x, beta, p=lp_norm): | |
|
||
best_error = 1e4 | ||
for i in range(iters): | ||
w_q= np.round(w_f * scale + zero).clip(min_max[0], min_max[1]) | ||
w_r = (w_q- zero) / scale | ||
w_q = np.round(w_f * scale + zero).clip(min_max[0], min_max[1]) | ||
w_r = (w_q - zero) / scale | ||
w_e = shrink_op(w_f - w_r, beta) | ||
zero = np.mean(w_q- (w_f - w_e) * scale, axis=axis, keepdims=True) | ||
zero = np.mean(w_q - (w_f - w_e) * scale, axis=axis, keepdims=True) | ||
beta *= kappa | ||
|
||
current_error = float(np.abs(w_f - w_r).mean()) | ||
|
@@ -263,8 +263,8 @@ def quantize_internal( | |
|
||
# Quantize | ||
# Necessary for fake quantization backprop | ||
w_q= np.round(weight * scale + zero).clip(min_max[0], min_max[1]) | ||
w_q= w_q.reshape(shape).astype(np.uint32) | ||
w_q = np.round(weight * scale + zero).clip(min_max[0], min_max[1]) | ||
w_q = w_q.reshape(shape).astype(np.uint32) | ||
|
||
scale = np.reciprocal(scale) | ||
if axis == 1: | ||
|