forked from pytorch/ao
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunified.py
35 lines (28 loc) · 930 Bytes
/
unified.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import torch
from typing import Any, List
from abc import ABC, abstractmethod
"""
The vast majority of quantization algorithms follow one of two patterns
1. Single quantize call to create a quantized model with quantized state_dict
2. Flow that needs calibration or training
This file defines the API for both patterns
"""
# API 1, single quantize call to create a quantized model with quantized state_dict
class Quantizer(ABC):
@abstractmethod
def quantize(
self, model: torch.nn.Module, *args: Any, **kwargs: Any
) -> torch.nn.Module:
pass
# API 2, flow that needs calibration or training
class TwoStepQuantizer:
@abstractmethod
def prepare(
self, model: torch.nn.Module, *args: Any, **kwargs: Any
) -> torch.nn.Module:
pass
@abstractmethod
def convert(
self, model: torch.nn.Module, *args: Any, **kwargs: Any
) -> torch.nn.Module:
pass