xref: /aosp_15_r20/external/pytorch/torch/jit/quantized.py (revision da0073e96a02ea20f0ac840b70461e3646d07c45)
1*da0073e9SAndroid Build Coastguard Worker# mypy: allow-untyped-defs
2*da0073e9SAndroid Build Coastguard Workerimport torch
3*da0073e9SAndroid Build Coastguard Worker
4*da0073e9SAndroid Build Coastguard Worker
5*da0073e9SAndroid Build Coastguard Workerclass QuantizedLinear(torch.jit.ScriptModule):
6*da0073e9SAndroid Build Coastguard Worker    def __init__(self, other):
7*da0073e9SAndroid Build Coastguard Worker        raise RuntimeError(
8*da0073e9SAndroid Build Coastguard Worker            "torch.jit.QuantizedLinear is no longer supported. Please use "
9*da0073e9SAndroid Build Coastguard Worker            "torch.ao.nn.quantized.dynamic.Linear instead."
10*da0073e9SAndroid Build Coastguard Worker        )
11*da0073e9SAndroid Build Coastguard Worker
12*da0073e9SAndroid Build Coastguard Worker
13*da0073e9SAndroid Build Coastguard Worker# FP16 weights
14*da0073e9SAndroid Build Coastguard Workerclass QuantizedLinearFP16(torch.jit.ScriptModule):
15*da0073e9SAndroid Build Coastguard Worker    def __init__(self, other):
16*da0073e9SAndroid Build Coastguard Worker        super().__init__()
17*da0073e9SAndroid Build Coastguard Worker        raise RuntimeError(
18*da0073e9SAndroid Build Coastguard Worker            "torch.jit.QuantizedLinearFP16 is no longer supported. "
19*da0073e9SAndroid Build Coastguard Worker            "Please use the torch.ao.nn.quantized.dynamic.Linear instead."
20*da0073e9SAndroid Build Coastguard Worker        )
21*da0073e9SAndroid Build Coastguard Worker
22*da0073e9SAndroid Build Coastguard Worker
23*da0073e9SAndroid Build Coastguard Worker# Quantized RNN cell implementations
24*da0073e9SAndroid Build Coastguard Workerclass QuantizedRNNCellBase(torch.jit.ScriptModule):
25*da0073e9SAndroid Build Coastguard Worker    def __init__(self, other):
26*da0073e9SAndroid Build Coastguard Worker        raise RuntimeError(
27*da0073e9SAndroid Build Coastguard Worker            "torch.jit.QuantizedRNNCellBase is no longer supported. "
28*da0073e9SAndroid Build Coastguard Worker            "Please use the torch.ao.nn.quantized.dynamic.RNNCell instead."
29*da0073e9SAndroid Build Coastguard Worker        )
30*da0073e9SAndroid Build Coastguard Worker
31*da0073e9SAndroid Build Coastguard Worker
32*da0073e9SAndroid Build Coastguard Workerclass QuantizedRNNCell(QuantizedRNNCellBase):
33*da0073e9SAndroid Build Coastguard Worker    def __init__(self, other):
34*da0073e9SAndroid Build Coastguard Worker        raise RuntimeError(
35*da0073e9SAndroid Build Coastguard Worker            "torch.jit.QuantizedRNNCell is no longer supported. "
36*da0073e9SAndroid Build Coastguard Worker            "Please use the torch.ao.nn.quantized.dynamic.RNNCell instead."
37*da0073e9SAndroid Build Coastguard Worker        )
38*da0073e9SAndroid Build Coastguard Worker
39*da0073e9SAndroid Build Coastguard Worker
40*da0073e9SAndroid Build Coastguard Workerclass QuantizedLSTMCell(QuantizedRNNCellBase):
41*da0073e9SAndroid Build Coastguard Worker    def __init__(self, other):
42*da0073e9SAndroid Build Coastguard Worker        super().__init__(other)
43*da0073e9SAndroid Build Coastguard Worker        raise RuntimeError(
44*da0073e9SAndroid Build Coastguard Worker            "torch.jit.QuantizedLSTMCell is no longer supported. "
45*da0073e9SAndroid Build Coastguard Worker            "Please use the torch.ao.nn.quantized.dynamic.LSTMCell instead."
46*da0073e9SAndroid Build Coastguard Worker        )
47*da0073e9SAndroid Build Coastguard Worker
48*da0073e9SAndroid Build Coastguard Worker
49*da0073e9SAndroid Build Coastguard Workerclass QuantizedGRUCell(QuantizedRNNCellBase):
50*da0073e9SAndroid Build Coastguard Worker    def __init__(self, other):
51*da0073e9SAndroid Build Coastguard Worker        super().__init__(other)
52*da0073e9SAndroid Build Coastguard Worker        raise RuntimeError(
53*da0073e9SAndroid Build Coastguard Worker            "torch.jit.QuantizedGRUCell is no longer supported. "
54*da0073e9SAndroid Build Coastguard Worker            "Please use the torch.ao.nn.quantized.dynamic.GRUCell instead."
55*da0073e9SAndroid Build Coastguard Worker        )
56*da0073e9SAndroid Build Coastguard Worker
57*da0073e9SAndroid Build Coastguard Worker
58*da0073e9SAndroid Build Coastguard Workerclass QuantizedRNNBase(torch.jit.ScriptModule):
59*da0073e9SAndroid Build Coastguard Worker    def __init__(self, other, dtype=torch.int8):
60*da0073e9SAndroid Build Coastguard Worker        raise RuntimeError(
61*da0073e9SAndroid Build Coastguard Worker            "torch.jit.QuantizedRNNBase is no longer supported. "
62*da0073e9SAndroid Build Coastguard Worker            "Please use the torch.ao.nn.quantized.dynamic instead."
63*da0073e9SAndroid Build Coastguard Worker        )
64*da0073e9SAndroid Build Coastguard Worker
65*da0073e9SAndroid Build Coastguard Worker
66*da0073e9SAndroid Build Coastguard Workerclass QuantizedLSTM(QuantizedRNNBase):
67*da0073e9SAndroid Build Coastguard Worker    def __init__(self, other, dtype):
68*da0073e9SAndroid Build Coastguard Worker        raise RuntimeError(
69*da0073e9SAndroid Build Coastguard Worker            "torch.jit.QuantizedLSTM is no longer supported. "
70*da0073e9SAndroid Build Coastguard Worker            "Please use the torch.ao.nn.quantized.dynamic.LSTM instead."
71*da0073e9SAndroid Build Coastguard Worker        )
72*da0073e9SAndroid Build Coastguard Worker
73*da0073e9SAndroid Build Coastguard Worker
74*da0073e9SAndroid Build Coastguard Workerclass QuantizedGRU(QuantizedRNNBase):
75*da0073e9SAndroid Build Coastguard Worker    def __init__(self, *args, **kwargs):
76*da0073e9SAndroid Build Coastguard Worker        raise RuntimeError(
77*da0073e9SAndroid Build Coastguard Worker            "torch.jit.QuantizedGRU is no longer supported. "
78*da0073e9SAndroid Build Coastguard Worker            "Please use the torch.ao.nn.quantized.dynamic.GRU instead."
79*da0073e9SAndroid Build Coastguard Worker        )
80*da0073e9SAndroid Build Coastguard Worker
81*da0073e9SAndroid Build Coastguard Worker
82*da0073e9SAndroid Build Coastguard Workerdef quantize_rnn_cell_modules(module):
83*da0073e9SAndroid Build Coastguard Worker    raise RuntimeError(
84*da0073e9SAndroid Build Coastguard Worker        "quantize_rnn_cell_modules function is no longer supported. "
85*da0073e9SAndroid Build Coastguard Worker        "Please use torch.ao.quantization.quantize_dynamic API instead."
86*da0073e9SAndroid Build Coastguard Worker    )
87*da0073e9SAndroid Build Coastguard Worker
88*da0073e9SAndroid Build Coastguard Worker
89*da0073e9SAndroid Build Coastguard Workerdef quantize_linear_modules(module, dtype=torch.int8):
90*da0073e9SAndroid Build Coastguard Worker    raise RuntimeError(
91*da0073e9SAndroid Build Coastguard Worker        "quantize_linear_modules function is no longer supported. "
92*da0073e9SAndroid Build Coastguard Worker        "Please use torch.ao.quantization.quantize_dynamic API instead."
93*da0073e9SAndroid Build Coastguard Worker    )
94*da0073e9SAndroid Build Coastguard Worker
95*da0073e9SAndroid Build Coastguard Worker
96*da0073e9SAndroid Build Coastguard Workerdef quantize_rnn_modules(module, dtype=torch.int8):
97*da0073e9SAndroid Build Coastguard Worker    raise RuntimeError(
98*da0073e9SAndroid Build Coastguard Worker        "quantize_rnn_modules function is no longer supported. "
99*da0073e9SAndroid Build Coastguard Worker        "Please use torch.ao.quantization.quantize_dynamic API instead."
100*da0073e9SAndroid Build Coastguard Worker    )
101