Текущая реализация, которую я использую, заключается в следующем:
Код: Выделить всё
import numpy as np
def softmax_int8(inputs):
inputs = np.array(inputs, dtype=np.int8)
x = inputs.astype(np.int32)
x_max = np.max(x)
x_shifted = x - x_max
scale_factor = 2 ** 14
exp_limit = 16
exp_x = np.clip(x_shifted + exp_limit, 0, None)
exp_x = (1
Подробнее здесь: [url]https://stackoverflow.com/questions/79239232/how-to-implement-softmax-in-python-whereby-the-input-are-signed-8-integers[/url]