2022-08-30 08:32:09 +00:00
|
|
|
import operator
|
|
|
|
|
2022-10-25 06:32:01 +00:00
|
|
|
import torch
|
|
|
|
|
2022-08-30 08:32:09 +00:00
|
|
|
__all__ = [
|
2022-09-14 02:25:45 +00:00
|
|
|
'ELEMENTWISE_MODULE_OP', 'ELEMENTWISE_FUNC_OP', 'RESHAPE_FUNC_OP', 'CONV_MODULE_OP', 'CONV_FUNC_OP',
|
2022-09-23 04:00:25 +00:00
|
|
|
'LINEAR_MODULE_OP', 'LINEAR_FUNC_OP', 'BATCHNORM_MODULE_OP', 'POOL_MODULE_OP', 'NON_PARAM_FUNC_OP', 'BCAST_FUNC_OP',
|
2022-09-23 05:31:15 +00:00
|
|
|
'EMBEDDING_MODULE_OP', 'LAYERNORM_MODULE_OP', 'ELEMENTWISE_METHOD_OP', 'RESHAPE_METHOD_OP', 'INFINITY_COST'
|
2022-08-30 08:32:09 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
ELEMENTWISE_MODULE_OP = [torch.nn.Dropout, torch.nn.ReLU]
|
|
|
|
ELEMENTWISE_FUNC_OP = [
|
2022-09-28 03:17:26 +00:00
|
|
|
torch.abs,
|
|
|
|
torch.cos,
|
|
|
|
torch.exp,
|
|
|
|
operator.neg,
|
|
|
|
torch.multiply,
|
|
|
|
torch.nn.functional.relu,
|
|
|
|
torch.nn.functional.dropout,
|
|
|
|
# softmax should not be here
|
|
|
|
torch.nn.functional.softmax
|
2022-08-30 08:32:09 +00:00
|
|
|
]
|
2022-09-23 04:00:25 +00:00
|
|
|
ELEMENTWISE_METHOD_OP = [
|
|
|
|
torch.Tensor.to,
|
|
|
|
torch.Tensor.type,
|
2022-09-28 03:17:26 +00:00
|
|
|
# TODO: contiguous maybe need some extra processes.
|
|
|
|
torch.Tensor.contiguous
|
2022-09-23 04:00:25 +00:00
|
|
|
]
|
|
|
|
RESHAPE_FUNC_OP = [torch.flatten, torch.reshape]
|
|
|
|
RESHAPE_METHOD_OP = [
|
|
|
|
torch.Tensor.view,
|
|
|
|
torch.Tensor.unsqueeze,
|
|
|
|
torch.Tensor.split,
|
|
|
|
torch.Tensor.permute,
|
|
|
|
torch.Tensor.transpose,
|
|
|
|
]
|
2022-09-16 03:33:01 +00:00
|
|
|
BCAST_FUNC_OP = [
|
|
|
|
torch.add, torch.sub, torch.mul, torch.div, torch.floor_divide, torch.true_divide, operator.add, operator.sub,
|
2022-10-25 06:32:01 +00:00
|
|
|
operator.mul, operator.floordiv, operator.truediv, torch.matmul, operator.pow, torch.pow
|
2022-09-16 03:33:01 +00:00
|
|
|
]
|
2022-08-30 08:32:09 +00:00
|
|
|
CONV_MODULE_OP = [
|
|
|
|
torch.nn.Conv1d, torch.nn.Conv2d, torch.nn.Conv3d, torch.nn.ConvTranspose1d, torch.nn.ConvTranspose2d,
|
|
|
|
torch.nn.ConvTranspose3d
|
|
|
|
]
|
|
|
|
CONV_FUNC_OP = [
|
|
|
|
torch.conv1d, torch.conv2d, torch.conv3d, torch.conv_transpose1d, torch.conv_transpose2d, torch.conv_transpose3d
|
|
|
|
]
|
2022-09-23 04:00:25 +00:00
|
|
|
EMBEDDING_MODULE_OP = [torch.nn.modules.sparse.Embedding]
|
2022-08-30 08:32:09 +00:00
|
|
|
LINEAR_MODULE_OP = [torch.nn.Linear]
|
|
|
|
LINEAR_FUNC_OP = [torch.nn.functional.linear, torch.matmul, torch.bmm]
|
2022-09-13 04:07:09 +00:00
|
|
|
BATCHNORM_MODULE_OP = [torch.nn.BatchNorm1d, torch.nn.BatchNorm2d, torch.nn.BatchNorm3d, torch.nn.SyncBatchNorm]
|
2022-09-23 04:00:25 +00:00
|
|
|
LAYERNORM_MODULE_OP = [torch.nn.LayerNorm]
|
2022-09-13 04:07:09 +00:00
|
|
|
POOL_MODULE_OP = [torch.nn.MaxPool1d, torch.nn.MaxPool2d, torch.nn.MaxPool3d, torch.nn.AdaptiveAvgPool2d]
|
2022-09-28 03:17:26 +00:00
|
|
|
NON_PARAM_FUNC_OP = [
|
|
|
|
torch.flatten,
|
|
|
|
torch.reshape,
|
|
|
|
torch.abs,
|
|
|
|
torch.cos,
|
|
|
|
torch.exp,
|
|
|
|
operator.neg,
|
|
|
|
torch.multiply,
|
|
|
|
torch.nn.functional.relu,
|
|
|
|
torch.nn.functional.dropout,
|
|
|
|
torch.flatten,
|
|
|
|
torch.where,
|
|
|
|
operator.pow,
|
|
|
|
torch.pow,
|
|
|
|
torch.tanh,
|
|
|
|
torch.add,
|
|
|
|
torch.sub,
|
|
|
|
torch.mul,
|
|
|
|
torch.div,
|
|
|
|
torch.floor_divide,
|
|
|
|
torch.true_divide,
|
|
|
|
operator.add,
|
|
|
|
operator.sub,
|
|
|
|
operator.mul,
|
|
|
|
operator.floordiv,
|
|
|
|
operator.truediv,
|
|
|
|
# softmax should not be here
|
|
|
|
torch.nn.functional.softmax
|
|
|
|
]
|
2022-09-13 04:07:09 +00:00
|
|
|
|
|
|
|
INFINITY_COST = 1e13
|