forked from intel/neural-compressor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
query.py
75 lines (64 loc) · 2.33 KB
/
query.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (c) 2021 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from abc import abstractmethod
import logging
class QueryBackendCapability():
"""Base class that defines Query Interface.
Each adaption layer should implement the inherited class for specific backend on their own.
"""
def __init__(self):
pass
@abstractmethod
def get_version(self):
"""Get the current backend's version string.
"""
raise NotImplementedError
@abstractmethod
def get_precisions(self):
"""Get the supported low precisions, e.g ['int8', 'bf16']
"""
raise NotImplementedError
@abstractmethod
def get_op_types(self):
"""Get the op types for specific backend per low precision.
e.g {'2.3.0': {'int8': ['Conv2D', 'MatMuL']}}
"""
raise NotImplementedError
@abstractmethod
def get_fuse_patterns(self):
"""Get the fusion patterns for specified op type for every specific precision
"""
raise NotImplementedError
@abstractmethod
def set_quantization_config(self, q_config):
"""Set the quantization config to backend.
Args:
q_config (yaml content?): set the organized quantization configuration to backend.
"""
raise NotImplementedError
@abstractmethod
def get_quantization_capability(self):
"""Get the quantization capability of low precision op types.
e.g, granularity, scheme and etc.
"""
raise NotImplementedError
@abstractmethod
def get_mixed_precision_combination(self, unsupported_precisions):
"""Get the valid precision combination base on hardware and user' config.
e.g['fp32', 'bf16', 'int8']
"""
raise NotImplementedError