quantized.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. # mypy: allow-untyped-defs
  2. import torch
  3. class QuantizedLinear(torch.jit.ScriptModule):
  4. def __init__(self, other):
  5. raise RuntimeError(
  6. "torch.jit.QuantizedLinear is no longer supported. Please use "
  7. "torch.ao.nn.quantized.dynamic.Linear instead."
  8. )
  9. # FP16 weights
  10. class QuantizedLinearFP16(torch.jit.ScriptModule):
  11. def __init__(self, other):
  12. super().__init__()
  13. raise RuntimeError(
  14. "torch.jit.QuantizedLinearFP16 is no longer supported. "
  15. "Please use the torch.ao.nn.quantized.dynamic.Linear instead."
  16. )
  17. # Quantized RNN cell implementations
  18. class QuantizedRNNCellBase(torch.jit.ScriptModule):
  19. def __init__(self, other):
  20. raise RuntimeError(
  21. "torch.jit.QuantizedRNNCellBase is no longer supported. "
  22. "Please use the torch.ao.nn.quantized.dynamic.RNNCell instead."
  23. )
  24. class QuantizedRNNCell(QuantizedRNNCellBase):
  25. def __init__(self, other):
  26. raise RuntimeError(
  27. "torch.jit.QuantizedRNNCell is no longer supported. "
  28. "Please use the torch.ao.nn.quantized.dynamic.RNNCell instead."
  29. )
  30. class QuantizedLSTMCell(QuantizedRNNCellBase):
  31. def __init__(self, other):
  32. super().__init__(other)
  33. raise RuntimeError(
  34. "torch.jit.QuantizedLSTMCell is no longer supported. "
  35. "Please use the torch.ao.nn.quantized.dynamic.LSTMCell instead."
  36. )
  37. class QuantizedGRUCell(QuantizedRNNCellBase):
  38. def __init__(self, other):
  39. super().__init__(other)
  40. raise RuntimeError(
  41. "torch.jit.QuantizedGRUCell is no longer supported. "
  42. "Please use the torch.ao.nn.quantized.dynamic.GRUCell instead."
  43. )
  44. class QuantizedRNNBase(torch.jit.ScriptModule):
  45. def __init__(self, other, dtype=torch.int8):
  46. raise RuntimeError(
  47. "torch.jit.QuantizedRNNBase is no longer supported. "
  48. "Please use the torch.ao.nn.quantized.dynamic instead."
  49. )
  50. class QuantizedLSTM(QuantizedRNNBase):
  51. def __init__(self, other, dtype):
  52. raise RuntimeError(
  53. "torch.jit.QuantizedLSTM is no longer supported. "
  54. "Please use the torch.ao.nn.quantized.dynamic.LSTM instead."
  55. )
  56. class QuantizedGRU(QuantizedRNNBase):
  57. def __init__(self, *args, **kwargs):
  58. raise RuntimeError(
  59. "torch.jit.QuantizedGRU is no longer supported. "
  60. "Please use the torch.ao.nn.quantized.dynamic.GRU instead."
  61. )
  62. def quantize_rnn_cell_modules(module):
  63. raise RuntimeError(
  64. "quantize_rnn_cell_modules function is no longer supported. "
  65. "Please use torch.ao.quantization.quantize_dynamic API instead."
  66. )
  67. def quantize_linear_modules(module, dtype=torch.int8):
  68. raise RuntimeError(
  69. "quantize_linear_modules function is no longer supported. "
  70. "Please use torch.ao.quantization.quantize_dynamic API instead."
  71. )
  72. def quantize_rnn_modules(module, dtype=torch.int8):
  73. raise RuntimeError(
  74. "quantize_rnn_modules function is no longer supported. "
  75. "Please use torch.ao.quantization.quantize_dynamic API instead."
  76. )