-
Notifications
You must be signed in to change notification settings - Fork 473
Expand file tree
/
Copy pathcommon_spec.py
More file actions
78 lines (56 loc) · 1.85 KB
/
common_spec.py
File metadata and controls
78 lines (56 loc) · 1.85 KB
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
76
77
78
import enum
from ctranslate2.specs import model_spec
# This enum should match the C++ equivalent in include/ctranslate2/ops/activation.h.
class Activation(enum.IntEnum):
"""Activation type."""
RELU = 0
GELUTanh = 1
SWISH = 2
GELU = 3
GELUSigmoid = 4
Tanh = 5
Sigmoid = 6
# This enum should match the C++ equivalent in include/ctranslate2/layers/common.h.
class EmbeddingsMerge(enum.IntEnum):
"""Merge strategy for factors embeddings."""
CONCAT = 0
ADD = 1
class Quantization(enum.IntEnum):
"""Activation type."""
CT2 = 0
AWQ_GEMM = 1
AWQ_GEMV = 2
class LayerNormSpec(model_spec.LayerSpec):
def __init__(self, rms_norm=False):
self.gamma = None
if not rms_norm:
self.beta = None
else:
self.layer_norm_use_residual = model_spec.OPTIONAL
class LinearSpec(model_spec.LayerSpec):
def __init__(self):
self.weight = None
self.weight_scale = model_spec.OPTIONAL
self.weight_zero = model_spec.OPTIONAL
self.bias = model_spec.OPTIONAL
def has_bias(self):
return not isinstance(self.bias, str)
class Conv1DSpec(model_spec.LayerSpec):
def __init__(self):
self.weight = None
self.weight_scale = model_spec.OPTIONAL
self.bias = model_spec.OPTIONAL
class EmbeddingsSpec(model_spec.LayerSpec):
def __init__(self):
self.weight = None
self.weight_scale = model_spec.OPTIONAL
self.multiply_by_sqrt_depth = model_spec.OPTIONAL
class LinearLowRankSpec(model_spec.LayerSpec):
def __init__(self):
self.low_rank_weight_1 = None
self.low_rank_weight_2 = None
self.weight_scale = model_spec.OPTIONAL
self.weight_zero = model_spec.OPTIONAL
self.bias = model_spec.OPTIONAL
def has_bias(self):
return not isinstance(self.bias, str)