msadapter 0.1.0b0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- msadapter/__init__.py +5 -0
- msadapter/pytorch/__init__.py +52 -0
- msadapter/pytorch/_ref/__init__.py +22 -0
- msadapter/pytorch/_register/__init__.py +48 -0
- msadapter/pytorch/_register/getitem_impl.py +45 -0
- msadapter/pytorch/_register/register_multitype_ops.py +162 -0
- msadapter/pytorch/_register/register_standard_method.py +98 -0
- msadapter/pytorch/_register/register_utils.py +251 -0
- msadapter/pytorch/_six.py +1 -0
- msadapter/pytorch/_utils.py +33 -0
- msadapter/pytorch/autograd/__init__.py +10 -0
- msadapter/pytorch/autograd/function.py +46 -0
- msadapter/pytorch/autograd/variable.py +15 -0
- msadapter/pytorch/common/__init__.py +29 -0
- msadapter/pytorch/common/_inner.py +70 -0
- msadapter/pytorch/common/device.py +9 -0
- msadapter/pytorch/common/dtype.py +73 -0
- msadapter/pytorch/conflict_functional.py +32 -0
- msadapter/pytorch/cuda/__init__.py +32 -0
- msadapter/pytorch/fft/__init__.py +7 -0
- msadapter/pytorch/fft/fft.py +21 -0
- msadapter/pytorch/functional.py +2756 -0
- msadapter/pytorch/hub.py +104 -0
- msadapter/pytorch/linalg/__init__.py +15 -0
- msadapter/pytorch/linalg/linalg.py +71 -0
- msadapter/pytorch/nn/__init__.py +7 -0
- msadapter/pytorch/nn/functional.py +2291 -0
- msadapter/pytorch/nn/init.py +143 -0
- msadapter/pytorch/nn/modules/__init__.py +187 -0
- msadapter/pytorch/nn/modules/activation.py +592 -0
- msadapter/pytorch/nn/modules/adaptive.py +193 -0
- msadapter/pytorch/nn/modules/batchnorm.py +416 -0
- msadapter/pytorch/nn/modules/channelshuffle.py +23 -0
- msadapter/pytorch/nn/modules/container.py +876 -0
- msadapter/pytorch/nn/modules/conv.py +739 -0
- msadapter/pytorch/nn/modules/distance.py +27 -0
- msadapter/pytorch/nn/modules/dropout.py +232 -0
- msadapter/pytorch/nn/modules/flatten.py +37 -0
- msadapter/pytorch/nn/modules/fold.py +43 -0
- msadapter/pytorch/nn/modules/linear.py +148 -0
- msadapter/pytorch/nn/modules/loss.py +327 -0
- msadapter/pytorch/nn/modules/module.py +320 -0
- msadapter/pytorch/nn/modules/normalization.py +136 -0
- msadapter/pytorch/nn/modules/padding.py +295 -0
- msadapter/pytorch/nn/modules/pixel_shuffle.py +26 -0
- msadapter/pytorch/nn/modules/pooling.py +392 -0
- msadapter/pytorch/nn/modules/rnn.py +511 -0
- msadapter/pytorch/nn/modules/sparse.py +93 -0
- msadapter/pytorch/nn/modules/transformer.py +0 -0
- msadapter/pytorch/nn/modules/unpooling.py +34 -0
- msadapter/pytorch/nn/modules/upsampling.py +78 -0
- msadapter/pytorch/nn/modules/utils.py +125 -0
- msadapter/pytorch/nn/parameter.py +377 -0
- msadapter/pytorch/optim/__init__.py +27 -0
- msadapter/pytorch/package_info.py +11 -0
- msadapter/pytorch/random.py +15 -0
- msadapter/pytorch/serialization.py +53 -0
- msadapter/pytorch/storage.py +41 -0
- msadapter/pytorch/tensor.py +3433 -0
- msadapter/pytorch/utils/__init__.py +1 -0
- msadapter/pytorch/utils/data/__init__.py +71 -0
- msadapter/pytorch/utils/data/_utils/__init__.py +58 -0
- msadapter/pytorch/utils/data/_utils/collate.py +331 -0
- msadapter/pytorch/utils/data/_utils/fetch.py +52 -0
- msadapter/pytorch/utils/data/_utils/pin_memory.py +71 -0
- msadapter/pytorch/utils/data/_utils/queue.py +229 -0
- msadapter/pytorch/utils/data/_utils/serialization.py +11 -0
- msadapter/pytorch/utils/data/_utils/signal_handling.py +86 -0
- msadapter/pytorch/utils/data/_utils/worker.py +329 -0
- msadapter/pytorch/utils/data/backward_compatibility.py +5 -0
- msadapter/pytorch/utils/data/communication/__init__.py +6 -0
- msadapter/pytorch/utils/data/communication/eventloop.py +72 -0
- msadapter/pytorch/utils/data/communication/iter.py +183 -0
- msadapter/pytorch/utils/data/communication/map.py +161 -0
- msadapter/pytorch/utils/data/communication/messages.py +75 -0
- msadapter/pytorch/utils/data/communication/protocol.py +207 -0
- msadapter/pytorch/utils/data/communication/queue.py +51 -0
- msadapter/pytorch/utils/data/dataloader.py +1058 -0
- msadapter/pytorch/utils/data/dataloader_experimental.py +152 -0
- msadapter/pytorch/utils/data/datapipes/__init__.py +3 -0
- msadapter/pytorch/utils/data/datapipes/_decorator.py +189 -0
- msadapter/pytorch/utils/data/datapipes/_typing.py +623 -0
- msadapter/pytorch/utils/data/datapipes/dataframe/__init__.py +11 -0
- msadapter/pytorch/utils/data/datapipes/dataframe/dataframe_wrapper.py +110 -0
- msadapter/pytorch/utils/data/datapipes/dataframe/dataframes.py +317 -0
- msadapter/pytorch/utils/data/datapipes/dataframe/datapipes.py +130 -0
- msadapter/pytorch/utils/data/datapipes/dataframe/structures.py +21 -0
- msadapter/pytorch/utils/data/datapipes/datapipe.py +367 -0
- msadapter/pytorch/utils/data/datapipes/gen_pyi.py +231 -0
- msadapter/pytorch/utils/data/datapipes/iter/__init__.py +64 -0
- msadapter/pytorch/utils/data/datapipes/iter/callable.py +171 -0
- msadapter/pytorch/utils/data/datapipes/iter/combinatorics.py +173 -0
- msadapter/pytorch/utils/data/datapipes/iter/combining.py +525 -0
- msadapter/pytorch/utils/data/datapipes/iter/filelister.py +64 -0
- msadapter/pytorch/utils/data/datapipes/iter/fileopener.py +89 -0
- msadapter/pytorch/utils/data/datapipes/iter/grouping.py +310 -0
- msadapter/pytorch/utils/data/datapipes/iter/routeddecoder.py +65 -0
- msadapter/pytorch/utils/data/datapipes/iter/selecting.py +106 -0
- msadapter/pytorch/utils/data/datapipes/iter/streamreader.py +36 -0
- msadapter/pytorch/utils/data/datapipes/iter/utils.py +50 -0
- msadapter/pytorch/utils/data/datapipes/map/__init__.py +17 -0
- msadapter/pytorch/utils/data/datapipes/map/callable.py +58 -0
- msadapter/pytorch/utils/data/datapipes/map/combinatorics.py +63 -0
- msadapter/pytorch/utils/data/datapipes/map/combining.py +101 -0
- msadapter/pytorch/utils/data/datapipes/map/grouping.py +70 -0
- msadapter/pytorch/utils/data/datapipes/map/utils.py +48 -0
- msadapter/pytorch/utils/data/datapipes/utils/__init__.py +0 -0
- msadapter/pytorch/utils/data/datapipes/utils/common.py +214 -0
- msadapter/pytorch/utils/data/datapipes/utils/decoder.py +327 -0
- msadapter/pytorch/utils/data/dataset.py +353 -0
- msadapter/pytorch/utils/data/distributed.py +138 -0
- msadapter/pytorch/utils/data/graph.py +93 -0
- msadapter/pytorch/utils/data/graph_settings.py +71 -0
- msadapter/pytorch/utils/data/sampler.py +267 -0
- msadapter/torchvision/__init__.py +87 -0
- msadapter/torchvision/_internally_replaced_utils.py +68 -0
- msadapter/torchvision/_utils.py +32 -0
- msadapter/torchvision/datasets/__init__.py +108 -0
- msadapter/torchvision/datasets/_optical_flow.py +495 -0
- msadapter/torchvision/datasets/caltech.py +247 -0
- msadapter/torchvision/datasets/celeba.py +203 -0
- msadapter/torchvision/datasets/cifar.py +169 -0
- msadapter/torchvision/datasets/cityscapes.py +221 -0
- msadapter/torchvision/datasets/clevr.py +88 -0
- msadapter/torchvision/datasets/coco.py +104 -0
- msadapter/torchvision/datasets/country211.py +58 -0
- msadapter/torchvision/datasets/dtd.py +100 -0
- msadapter/torchvision/datasets/eurosat.py +58 -0
- msadapter/torchvision/datasets/fakedata.py +68 -0
- msadapter/torchvision/datasets/fer2013.py +75 -0
- msadapter/torchvision/datasets/fgvc_aircraft.py +114 -0
- msadapter/torchvision/datasets/flickr.py +166 -0
- msadapter/torchvision/datasets/flowers102.py +114 -0
- msadapter/torchvision/datasets/folder.py +318 -0
- msadapter/torchvision/datasets/food101.py +93 -0
- msadapter/torchvision/datasets/gtsrb.py +103 -0
- msadapter/torchvision/datasets/hmdb51.py +150 -0
- msadapter/torchvision/datasets/imagenet.py +217 -0
- msadapter/torchvision/datasets/inaturalist.py +241 -0
- msadapter/torchvision/datasets/kinetics.py +326 -0
- msadapter/torchvision/datasets/kitti.py +158 -0
- msadapter/torchvision/datasets/lfw.py +255 -0
- msadapter/torchvision/datasets/lsun.py +167 -0
- msadapter/torchvision/datasets/mnist.py +549 -0
- msadapter/torchvision/datasets/omniglot.py +102 -0
- msadapter/torchvision/datasets/oxford_iiit_pet.py +126 -0
- msadapter/torchvision/datasets/pcam.py +133 -0
- msadapter/torchvision/datasets/phototour.py +231 -0
- msadapter/torchvision/datasets/places365.py +170 -0
- msadapter/torchvision/datasets/rendered_sst2.py +86 -0
- msadapter/torchvision/datasets/samplers/__init__.py +3 -0
- msadapter/torchvision/datasets/samplers/clip_sampler.py +174 -0
- msadapter/torchvision/datasets/sbd.py +123 -0
- msadapter/torchvision/datasets/sbu.py +114 -0
- msadapter/torchvision/datasets/semeion.py +91 -0
- msadapter/torchvision/datasets/stanford_cars.py +121 -0
- msadapter/torchvision/datasets/stl10.py +176 -0
- msadapter/torchvision/datasets/sun397.py +76 -0
- msadapter/torchvision/datasets/svhn.py +129 -0
- msadapter/torchvision/datasets/ucf101.py +129 -0
- msadapter/torchvision/datasets/usps.py +95 -0
- msadapter/torchvision/datasets/utils.py +484 -0
- msadapter/torchvision/datasets/video_utils.py +423 -0
- msadapter/torchvision/datasets/vision.py +110 -0
- msadapter/torchvision/datasets/voc.py +237 -0
- msadapter/torchvision/datasets/widerface.py +199 -0
- msadapter/torchvision/extension.py +89 -0
- msadapter/torchvision/io/__init__.py +67 -0
- msadapter/torchvision/io/_load_gpu_decoder.py +9 -0
- msadapter/torchvision/io/_video_opt.py +505 -0
- msadapter/torchvision/io/image.py +267 -0
- msadapter/torchvision/io/video.py +414 -0
- msadapter/torchvision/io/video_reader.py +181 -0
- msadapter/torchvision/models/__init__.py +17 -0
- msadapter/torchvision/models/_utils.py +66 -0
- msadapter/torchvision/models/alexnet.py +64 -0
- msadapter/torchvision/models/densenet.py +317 -0
- msadapter/torchvision/models/detection/__init__.py +6 -0
- msadapter/torchvision/models/detection/_utils.py +410 -0
- msadapter/torchvision/models/detection/anchor_utils.py +250 -0
- msadapter/torchvision/models/detection/backbone_utils.py +179 -0
- msadapter/torchvision/models/detection/faster_rcnn.py +469 -0
- msadapter/torchvision/models/detection/generalized_rcnn.py +110 -0
- msadapter/torchvision/models/detection/image_list.py +25 -0
- msadapter/torchvision/models/detection/keypoint_rcnn.py +346 -0
- msadapter/torchvision/models/detection/mask_rcnn.py +336 -0
- msadapter/torchvision/models/detection/retinanet.py +628 -0
- msadapter/torchvision/models/detection/roi_heads.py +867 -0
- msadapter/torchvision/models/detection/rpn.py +369 -0
- msadapter/torchvision/models/detection/ssd.py +600 -0
- msadapter/torchvision/models/detection/ssdlite.py +237 -0
- msadapter/torchvision/models/detection/transform.py +294 -0
- msadapter/torchvision/models/googlenet.py +319 -0
- msadapter/torchvision/models/inception.py +465 -0
- msadapter/torchvision/models/mnasnet.py +280 -0
- msadapter/torchvision/models/mobilenet.py +4 -0
- msadapter/torchvision/models/mobilenetv2.py +219 -0
- msadapter/torchvision/models/mobilenetv3.py +278 -0
- msadapter/torchvision/models/quantization/__init__.py +5 -0
- msadapter/torchvision/models/quantization/googlenet.py +9 -0
- msadapter/torchvision/models/quantization/inception.py +11 -0
- msadapter/torchvision/models/quantization/mobilenet.py +4 -0
- msadapter/torchvision/models/quantization/mobilenetv2.py +8 -0
- msadapter/torchvision/models/quantization/mobilenetv3.py +9 -0
- msadapter/torchvision/models/quantization/resnet.py +16 -0
- msadapter/torchvision/models/quantization/shufflenetv2.py +21 -0
- msadapter/torchvision/models/resnet.py +389 -0
- msadapter/torchvision/models/segmentation/__init__.py +4 -0
- msadapter/torchvision/models/segmentation/_utils.py +33 -0
- msadapter/torchvision/models/segmentation/deeplabv3.py +93 -0
- msadapter/torchvision/models/segmentation/fcn.py +36 -0
- msadapter/torchvision/models/segmentation/lraspp.py +69 -0
- msadapter/torchvision/models/segmentation/segmentation.py +196 -0
- msadapter/torchvision/models/shufflenetv2.py +233 -0
- msadapter/torchvision/models/squeezenet.py +149 -0
- msadapter/torchvision/models/utils.py +77 -0
- msadapter/torchvision/models/vgg.py +190 -0
- msadapter/torchvision/models/video/__init__.py +1 -0
- msadapter/torchvision/models/video/resnet.py +343 -0
- msadapter/torchvision/ops/__init__.py +72 -0
- msadapter/torchvision/ops/_box_convert.py +80 -0
- msadapter/torchvision/ops/_utils.py +109 -0
- msadapter/torchvision/ops/boxes.py +395 -0
- msadapter/torchvision/ops/ciou_loss.py +75 -0
- msadapter/torchvision/ops/deform_conv.py +189 -0
- msadapter/torchvision/ops/diou_loss.py +86 -0
- msadapter/torchvision/ops/drop_block.py +152 -0
- msadapter/torchvision/ops/feature_pyramid_network.py +216 -0
- msadapter/torchvision/ops/focal_loss.py +49 -0
- msadapter/torchvision/ops/giou_loss.py +69 -0
- msadapter/torchvision/ops/misc.py +293 -0
- msadapter/torchvision/ops/poolers.py +314 -0
- msadapter/torchvision/ops/ps_roi_align.py +83 -0
- msadapter/torchvision/ops/ps_roi_pool.py +75 -0
- msadapter/torchvision/ops/roi_align.py +106 -0
- msadapter/torchvision/ops/roi_pool.py +61 -0
- msadapter/torchvision/ops/stochastic_depth.py +57 -0
- msadapter/torchvision/transforms/__init__.py +2 -0
- msadapter/torchvision/transforms/_functional_video.py +118 -0
- msadapter/torchvision/transforms/_pil_constants.py +25 -0
- msadapter/torchvision/transforms/_presets.py +210 -0
- msadapter/torchvision/transforms/_transforms_video.py +178 -0
- msadapter/torchvision/transforms/autoaugment.py +644 -0
- msadapter/torchvision/transforms/functional.py +1558 -0
- msadapter/torchvision/transforms/functional_pil.py +426 -0
- msadapter/torchvision/transforms/functional_tensor.py +1053 -0
- msadapter/torchvision/transforms/transforms.py +2363 -0
- msadapter/torchvision/utils.py +524 -0
- msadapter/utils.py +106 -0
- msadapter-0.1.0b0.dist-info/LICENSE +203 -0
- msadapter-0.1.0b0.dist-info/METADATA +216 -0
- msadapter-0.1.0b0.dist-info/RECORD +254 -0
- msadapter-0.1.0b0.dist-info/WHEEL +5 -0
- msadapter-0.1.0b0.dist-info/top_level.txt +1 -0
msadapter/__init__.py
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
|
|
4
|
+
# Register MSAdapter Tensor/Parameter to MindSpore, it should be executed at the top of all.
|
|
5
|
+
from msadapter.pytorch._register import *
|
|
6
|
+
from msadapter.pytorch.common import *
|
|
7
|
+
from msadapter.pytorch.tensor import *
|
|
8
|
+
from msadapter.pytorch import nn
|
|
9
|
+
from msadapter.pytorch import optim
|
|
10
|
+
from msadapter.pytorch.functional import *
|
|
11
|
+
from msadapter.pytorch.utils import data
|
|
12
|
+
from msadapter.pytorch._ref import *
|
|
13
|
+
from msadapter.pytorch import cuda
|
|
14
|
+
from msadapter.pytorch.conflict_functional import *
|
|
15
|
+
import msadapter.pytorch.fft as fft
|
|
16
|
+
from msadapter.pytorch import autograd
|
|
17
|
+
from msadapter.pytorch.package_info import __version__, VERSION, version
|
|
18
|
+
from msadapter.pytorch.random import *
|
|
19
|
+
from msadapter.pytorch.storage import *
|
|
20
|
+
from msadapter.pytorch.serialization import *
|
|
21
|
+
import msadapter.pytorch.linalg as linalg
|
|
22
|
+
from msadapter.pytorch.linalg import *
|
|
23
|
+
|
|
24
|
+
def _assert(condition, message):
|
|
25
|
+
assert condition, message
|
|
26
|
+
|
|
27
|
+
def is_tensor(obj):
|
|
28
|
+
r"""Returns True if `obj` is a msadapter.pytorch tensor.
|
|
29
|
+
|
|
30
|
+
Note that this function is simply doing ``isinstance(obj, Tensor)``.
|
|
31
|
+
Using that ``isinstance`` check is better for typechecking with mypy,
|
|
32
|
+
and more explicit - so it's recommended to use that instead of
|
|
33
|
+
``is_tensor``.
|
|
34
|
+
"""
|
|
35
|
+
return isinstance(obj, Tensor)
|
|
36
|
+
|
|
37
|
+
def is_floating_point(obj):
|
|
38
|
+
if not is_tensor(obj):
|
|
39
|
+
raise TypeError("is_floating_point(): argument 'input' (position 1) must be Tensor, not {}.".format(type(obj)))
|
|
40
|
+
|
|
41
|
+
return obj._dtype in (mstype.float16, mstype.float32, mstype.float64)
|
|
42
|
+
|
|
43
|
+
class Size(tuple):
|
|
44
|
+
def __new__(cls, shape):
|
|
45
|
+
if isinstance(shape, Tensor):
|
|
46
|
+
_shape = shape.tolist()
|
|
47
|
+
else:
|
|
48
|
+
_shape = shape
|
|
49
|
+
if not isinstance(_shape, (tuple, list)):
|
|
50
|
+
raise TypeError("{} object is not supportted.".format(type(shape)))
|
|
51
|
+
|
|
52
|
+
return tuple.__new__(Size, _shape)
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
from msadapter.pytorch.tensor import Tensor
|
|
4
|
+
|
|
5
|
+
def typename(o):
|
|
6
|
+
if isinstance(o, Tensor):
|
|
7
|
+
return o.type()
|
|
8
|
+
|
|
9
|
+
module = ''
|
|
10
|
+
class_name = ''
|
|
11
|
+
if hasattr(o, '__module__') and o.__module__ != 'builtins' \
|
|
12
|
+
and o.__module__ != '__builtin__' and o.__module__ is not None:
|
|
13
|
+
module = o.__module__ + '.'
|
|
14
|
+
|
|
15
|
+
if hasattr(o, '__qualname__'):
|
|
16
|
+
class_name = o.__qualname__
|
|
17
|
+
elif hasattr(o, '__name__'):
|
|
18
|
+
class_name = o.__name__
|
|
19
|
+
else:
|
|
20
|
+
class_name = o.__class__.__name__
|
|
21
|
+
|
|
22
|
+
return module + class_name
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
from mindspore.common.api import set_adapter_config
|
|
4
|
+
from mindspore._extends.parse import trope as T
|
|
5
|
+
from mindspore._extends.parse.resources import convert_object_map
|
|
6
|
+
|
|
7
|
+
from msadapter.pytorch.tensor import Tensor
|
|
8
|
+
from msadapter.pytorch.nn import Parameter
|
|
9
|
+
from msadapter.pytorch._register import register_multitype_ops
|
|
10
|
+
from msadapter.pytorch._register import register_standard_method as S
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
convert_object_map[T.add] = register_multitype_ops.add # x+y
|
|
14
|
+
convert_object_map[T.sub] = register_multitype_ops.sub # x-y
|
|
15
|
+
convert_object_map[T.mul] = register_multitype_ops.mul # x*y
|
|
16
|
+
convert_object_map[T.truediv] = register_multitype_ops.div # x/y
|
|
17
|
+
convert_object_map[T.getitem] = register_multitype_ops.getitem # x[0]
|
|
18
|
+
convert_object_map[T.setitem] = register_multitype_ops.setitem # x[0]=y
|
|
19
|
+
convert_object_map[T.floordiv] = register_multitype_ops.floordiv # x//y
|
|
20
|
+
convert_object_map[T.mod] = register_multitype_ops.mod # x%y
|
|
21
|
+
convert_object_map[T.pow] = register_multitype_ops.pow_ # x**y
|
|
22
|
+
convert_object_map[T.and_] = register_multitype_ops.bitwise_and # x&y
|
|
23
|
+
convert_object_map[T.or_] = register_multitype_ops.bitwise_or # x|y
|
|
24
|
+
convert_object_map[T.xor] = register_multitype_ops.bitwise_xor # x^y
|
|
25
|
+
convert_object_map[T.neg] = register_multitype_ops.negative # -x
|
|
26
|
+
convert_object_map[T.not_] = register_multitype_ops.logical_not # not x
|
|
27
|
+
convert_object_map[T.eq] = register_multitype_ops.equal # x==y
|
|
28
|
+
convert_object_map[T.ne] = register_multitype_ops.not_equal # x!=y
|
|
29
|
+
convert_object_map[T.lt] = register_multitype_ops.less # x < y
|
|
30
|
+
convert_object_map[T.gt] = register_multitype_ops.greater # x > y
|
|
31
|
+
convert_object_map[T.le] = register_multitype_ops.less_equal # x <= y
|
|
32
|
+
convert_object_map[T.ge] = register_multitype_ops.greater_equal # x >= y
|
|
33
|
+
convert_object_map[T.contains] = register_multitype_ops.in_ # x in y
|
|
34
|
+
convert_object_map[T.not_contains] = register_multitype_ops.not_in_ # x not in y
|
|
35
|
+
convert_object_map[T.matmul] = S.adapter_matmul # x @ y
|
|
36
|
+
convert_object_map[T.invert] = S.adapter_invert # ~x
|
|
37
|
+
convert_object_map[T.abs] = S.adapter_abs # abs(x)
|
|
38
|
+
convert_object_map[T.round] = S.adapter_round # round(x)
|
|
39
|
+
convert_object_map[T.max] = S.adapter_max # max(x)
|
|
40
|
+
convert_object_map[T.min] = S.adapter_min # min(x)
|
|
41
|
+
convert_object_map[T.sum] = S.adapter_sum # sum(x)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def register_msadapter_tensor():
|
|
45
|
+
adapter_config = {"Tensor": Tensor, "convert_object_map": convert_object_map}
|
|
46
|
+
set_adapter_config(adapter_config)
|
|
47
|
+
|
|
48
|
+
register_msadapter_tensor()
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
|
|
2
|
+
#!/usr/bin/env python
|
|
3
|
+
# -*- coding: utf-8 -*-
|
|
4
|
+
import mindspore as ms
|
|
5
|
+
from mindspore import dtype as mstype
|
|
6
|
+
from mindspore.ops.composite.multitype_ops import _compile_utils as compile_utils
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def _tensor_getitem_by_tensor(data, tensor_index):
|
|
10
|
+
if tensor_index.dtype == mstype.bool_:
|
|
11
|
+
ms_shape_len = len(data.shape)
|
|
12
|
+
index_shape_len = len(tensor_index.shape)
|
|
13
|
+
out_shape = [-1]
|
|
14
|
+
while index_shape_len < ms_shape_len:
|
|
15
|
+
out_shape.append(data.shape[index_shape_len])
|
|
16
|
+
tensor_index = tensor_index.expand_dims(-1)
|
|
17
|
+
index_shape_len += 1
|
|
18
|
+
out = ms.ops.masked_select(data, tensor_index)
|
|
19
|
+
if len(out_shape) > 1:
|
|
20
|
+
out = out.reshape(out_shape)
|
|
21
|
+
else:
|
|
22
|
+
out = compile_utils.tensor_index_by_tensor(data, tensor_index)
|
|
23
|
+
return out
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _tensor_getitem_by_number(data, number_index):
|
|
27
|
+
if isinstance(number_index, bool):
|
|
28
|
+
if number_index:
|
|
29
|
+
return data.expand_dims(0)
|
|
30
|
+
else:
|
|
31
|
+
index = ms.Tensor(False)
|
|
32
|
+
out = ms.ops.masked_select(data, index)
|
|
33
|
+
return out
|
|
34
|
+
return compile_utils.tensor_index_by_number(data, number_index)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def _tensor_getitem_by_tuple(data, tuple_index):
|
|
38
|
+
if isinstance(tuple_index[0], bool):
|
|
39
|
+
if False in tuple_index:
|
|
40
|
+
index = ms.Tensor(False)
|
|
41
|
+
out = ms.ops.masked_select(data, index)
|
|
42
|
+
return out
|
|
43
|
+
else:
|
|
44
|
+
return data.expand_dims(0)
|
|
45
|
+
return compile_utils.tensor_index_by_tuple(data, tuple_index)
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
from mindspore.ops.composite.multitype_ops.add_impl import add
|
|
4
|
+
from mindspore.ops.composite.multitype_ops.sub_impl import sub
|
|
5
|
+
from mindspore.ops.composite.multitype_ops.mul_impl import mul
|
|
6
|
+
from mindspore.ops.composite.multitype_ops.div_impl import div
|
|
7
|
+
from mindspore.ops.composite.multitype_ops.floordiv_impl import floordiv
|
|
8
|
+
from mindspore.ops.composite.multitype_ops.mod_impl import mod
|
|
9
|
+
from mindspore.ops.composite.multitype_ops.pow_impl import pow_
|
|
10
|
+
from mindspore.ops.composite.multitype_ops.bitwise_and_impl import bitwise_and
|
|
11
|
+
from mindspore.ops.composite.multitype_ops.bitwise_or_impl import bitwise_or
|
|
12
|
+
from mindspore.ops.composite.multitype_ops.bitwise_xor_impl import bitwise_xor
|
|
13
|
+
from mindspore.ops.composite.multitype_ops.negative_impl import negative
|
|
14
|
+
from mindspore.ops.composite.multitype_ops.logic_not_impl import logical_not
|
|
15
|
+
from mindspore.ops.composite.multitype_ops.equal_impl import equal
|
|
16
|
+
from mindspore.ops.composite.multitype_ops.not_equal_impl import not_equal
|
|
17
|
+
from mindspore.ops.composite.multitype_ops.less_impl import less
|
|
18
|
+
from mindspore.ops.composite.multitype_ops.greater_impl import greater
|
|
19
|
+
from mindspore.ops.composite.multitype_ops.less_equal_impl import less_equal
|
|
20
|
+
from mindspore.ops.composite.multitype_ops.greater_equal_impl import greater_equal
|
|
21
|
+
from mindspore.ops.composite.multitype_ops.in_impl import in_
|
|
22
|
+
from mindspore.ops.composite.multitype_ops.not_in_impl import not_in_
|
|
23
|
+
from mindspore.ops.composite.multitype_ops.getitem_impl import getitem
|
|
24
|
+
from mindspore.ops.composite.multitype_ops.setitem_impl import setitem
|
|
25
|
+
from msadapter.pytorch._register import register_utils as utils
|
|
26
|
+
from msadapter.pytorch._register.getitem_impl import _tensor_getitem_by_tensor, _tensor_getitem_by_number, \
|
|
27
|
+
_tensor_getitem_by_tuple
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
# multitype_ops.add
|
|
31
|
+
utils.update_multitype_ops_tensor_tensor(add)
|
|
32
|
+
utils.update_multitype_ops_number_tensor(add)
|
|
33
|
+
utils.update_multitype_ops_tensor_number(add)
|
|
34
|
+
utils.update_multitype_ops_tuple_tensor(add)
|
|
35
|
+
utils.update_multitype_ops_tensor_tuple(add)
|
|
36
|
+
utils.update_multitype_ops_list_tensor(add)
|
|
37
|
+
utils.update_multitype_ops_tensor_list(add)
|
|
38
|
+
|
|
39
|
+
# multitype_ops.sub
|
|
40
|
+
utils.update_multitype_ops_tensor_tensor(sub)
|
|
41
|
+
utils.update_multitype_ops_number_tensor(sub)
|
|
42
|
+
utils.update_multitype_ops_tensor_number(sub)
|
|
43
|
+
utils.update_multitype_ops_tuple_tensor(sub)
|
|
44
|
+
utils.update_multitype_ops_tensor_tuple(sub)
|
|
45
|
+
utils.update_multitype_ops_list_tensor(sub)
|
|
46
|
+
utils.update_multitype_ops_tensor_list(sub)
|
|
47
|
+
|
|
48
|
+
# multitype_ops.mul
|
|
49
|
+
utils.update_multitype_ops_tensor_tensor(mul)
|
|
50
|
+
utils.update_multitype_ops_number_tensor(mul)
|
|
51
|
+
utils.update_multitype_ops_tensor_number(mul)
|
|
52
|
+
utils.update_multitype_ops_tuple_tensor(mul)
|
|
53
|
+
utils.update_multitype_ops_tensor_tuple(mul)
|
|
54
|
+
utils.update_multitype_ops_list_tensor(mul)
|
|
55
|
+
utils.update_multitype_ops_tensor_list(mul)
|
|
56
|
+
|
|
57
|
+
# multitype_ops.div
|
|
58
|
+
utils.update_multitype_ops_tensor_tensor(div)
|
|
59
|
+
utils.update_multitype_ops_number_tensor(div)
|
|
60
|
+
utils.update_multitype_ops_tensor_number(div)
|
|
61
|
+
utils.update_multitype_ops_tuple_tensor(div)
|
|
62
|
+
utils.update_multitype_ops_tensor_tuple(div)
|
|
63
|
+
utils.update_multitype_ops_list_tensor(div)
|
|
64
|
+
utils.update_multitype_ops_tensor_list(div)
|
|
65
|
+
|
|
66
|
+
# multitype_ops.floordiv
|
|
67
|
+
utils.update_multitype_ops_tensor_tensor(floordiv)
|
|
68
|
+
utils.update_multitype_ops_number_tensor(floordiv)
|
|
69
|
+
utils.update_multitype_ops_tensor_number(floordiv)
|
|
70
|
+
utils.update_multitype_ops_tuple_tensor(floordiv)
|
|
71
|
+
utils.update_multitype_ops_tensor_tuple(floordiv)
|
|
72
|
+
utils.update_multitype_ops_list_tensor(floordiv)
|
|
73
|
+
utils.update_multitype_ops_tensor_list(floordiv)
|
|
74
|
+
|
|
75
|
+
# multitype_ops.mod
|
|
76
|
+
utils.update_multitype_ops_tensor_tensor(mod)
|
|
77
|
+
utils.update_multitype_ops_number_tensor(mod)
|
|
78
|
+
utils.update_multitype_ops_tensor_number(mod)
|
|
79
|
+
utils.update_multitype_ops_tuple_tensor(mod)
|
|
80
|
+
utils.update_multitype_ops_tensor_tuple(mod)
|
|
81
|
+
utils.update_multitype_ops_list_tensor(mod)
|
|
82
|
+
utils.update_multitype_ops_tensor_list(mod)
|
|
83
|
+
|
|
84
|
+
# multitype_ops.pow_
|
|
85
|
+
utils.update_multitype_ops_tensor_tensor(pow_)
|
|
86
|
+
utils.update_multitype_ops_number_tensor(pow_)
|
|
87
|
+
utils.update_multitype_ops_tensor_number(pow_)
|
|
88
|
+
utils.update_multitype_ops_tuple_tensor(pow_)
|
|
89
|
+
utils.update_multitype_ops_tensor_tuple(pow_)
|
|
90
|
+
utils.update_multitype_ops_list_tensor(pow_)
|
|
91
|
+
utils.update_multitype_ops_tensor_list(pow_)
|
|
92
|
+
|
|
93
|
+
# multitype_ops.bitwise_and
|
|
94
|
+
utils.update_multitype_ops_tensor_tensor(bitwise_and)
|
|
95
|
+
utils.update_multitype_ops_number_tensor(bitwise_and)
|
|
96
|
+
utils.update_multitype_ops_tensor_number(bitwise_and)
|
|
97
|
+
|
|
98
|
+
# multitype_ops.bitwise_or
|
|
99
|
+
utils.update_multitype_ops_tensor_tensor(bitwise_or)
|
|
100
|
+
utils.update_multitype_ops_number_tensor(bitwise_or)
|
|
101
|
+
utils.update_multitype_ops_tensor_number(bitwise_or)
|
|
102
|
+
|
|
103
|
+
# multitype_ops.bitwise_xor
|
|
104
|
+
utils.update_multitype_ops_tensor_tensor(bitwise_xor)
|
|
105
|
+
utils.update_multitype_ops_number_tensor(bitwise_xor)
|
|
106
|
+
utils.update_multitype_ops_tensor_number(bitwise_xor)
|
|
107
|
+
|
|
108
|
+
# multitype_ops.negative
|
|
109
|
+
utils.update_multitype_ops_tensor(negative)
|
|
110
|
+
|
|
111
|
+
# multitype_ops.logical_not
|
|
112
|
+
# LogicalNot only support Tensor[Bool].
|
|
113
|
+
utils.update_multitype_ops_tensor(logical_not)
|
|
114
|
+
|
|
115
|
+
# multitype_ops.equal
|
|
116
|
+
utils.update_multitype_ops_tensor_tensor(equal)
|
|
117
|
+
utils.update_multitype_ops_number_tensor(equal)
|
|
118
|
+
utils.update_multitype_ops_tensor_number(equal)
|
|
119
|
+
|
|
120
|
+
# multitype_ops.not_equal
|
|
121
|
+
utils.update_multitype_ops_tensor_tensor(not_equal)
|
|
122
|
+
utils.update_multitype_ops_number_tensor(not_equal)
|
|
123
|
+
utils.update_multitype_ops_tensor_number(not_equal)
|
|
124
|
+
|
|
125
|
+
# multitype_ops.less
|
|
126
|
+
utils.update_multitype_ops_tensor_tensor(less)
|
|
127
|
+
utils.update_multitype_ops_number_tensor(less)
|
|
128
|
+
utils.update_multitype_ops_tensor_number(less)
|
|
129
|
+
|
|
130
|
+
# multitype_ops.greater
|
|
131
|
+
utils.update_multitype_ops_tensor_tensor(greater)
|
|
132
|
+
utils.update_multitype_ops_number_tensor(greater)
|
|
133
|
+
utils.update_multitype_ops_tensor_number(greater)
|
|
134
|
+
|
|
135
|
+
# multitype_ops.less_equal
|
|
136
|
+
utils.update_multitype_ops_tensor_tensor(less_equal)
|
|
137
|
+
utils.update_multitype_ops_number_tensor(less_equal)
|
|
138
|
+
utils.update_multitype_ops_tensor_number(less_equal)
|
|
139
|
+
|
|
140
|
+
# multitype_ops.greater_equal
|
|
141
|
+
utils.update_multitype_ops_tensor_tensor(greater_equal)
|
|
142
|
+
utils.update_multitype_ops_number_tensor(greater_equal)
|
|
143
|
+
utils.update_multitype_ops_tensor_number(greater_equal)
|
|
144
|
+
|
|
145
|
+
# multitype_ops.in_
|
|
146
|
+
utils.update_multitype_ops_tensor_tuple(in_)
|
|
147
|
+
utils.update_multitype_ops_tensor_list(in_)
|
|
148
|
+
|
|
149
|
+
# multitype_ops.not_in_
|
|
150
|
+
utils.update_multitype_ops_tensor_tuple(not_in_)
|
|
151
|
+
utils.update_multitype_ops_tensor_list(not_in_)
|
|
152
|
+
|
|
153
|
+
# multitype_ops.getitem
|
|
154
|
+
utils.update_multitype_ops_tensor_list(getitem)
|
|
155
|
+
utils.update_multitype_ops_tensor_none(getitem)
|
|
156
|
+
utils.update_multitype_ops_tensor_slice(getitem)
|
|
157
|
+
utils.update_multitype_ops_tensor_tensor_with_fn(getitem, _tensor_getitem_by_tensor)
|
|
158
|
+
utils.update_multitype_ops_tensor_number_with_fn(getitem, _tensor_getitem_by_number)
|
|
159
|
+
utils.update_multitype_ops_tensor_tuple_with_fn(getitem, _tensor_getitem_by_tuple)
|
|
160
|
+
|
|
161
|
+
# multitype_ops.setitem
|
|
162
|
+
utils.update_multitype_ops_setitem_tensor(setitem)
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
from mindspore import dtype as mstype
|
|
4
|
+
from mindspore._extends.parse import trope as T
|
|
5
|
+
from mindspore._extends.parse.resources import convert_object_map
|
|
6
|
+
from msadapter.pytorch.tensor import Tensor as adapter_Tensor
|
|
7
|
+
from msadapter.pytorch._register.register_utils import convert_to_ms_tensor, convert_to_adapter_tensor
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
matmul_fn = convert_object_map.get(T.matmul)
|
|
11
|
+
invert_fn = convert_object_map.get(T.invert)
|
|
12
|
+
abs_fn = convert_object_map.get(T.abs)
|
|
13
|
+
round_fn = convert_object_map.get(T.round)
|
|
14
|
+
max_fn = convert_object_map.get(T.max)
|
|
15
|
+
min_fn = convert_object_map.get(T.min)
|
|
16
|
+
sum_fn = convert_object_map.get(T.sum)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def adapter_matmul(x, y):
|
|
20
|
+
if isinstance(x, adapter_Tensor) and isinstance(y, adapter_Tensor):
|
|
21
|
+
x = convert_to_ms_tensor(x)
|
|
22
|
+
y = convert_to_ms_tensor(y)
|
|
23
|
+
out = matmul_fn(x, y)
|
|
24
|
+
out = convert_to_adapter_tensor(out)
|
|
25
|
+
else:
|
|
26
|
+
out = matmul_fn(x, y)
|
|
27
|
+
return out
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def adapter_invert(x):
|
|
31
|
+
if isinstance(x, adapter_Tensor):
|
|
32
|
+
x = convert_to_ms_tensor(x)
|
|
33
|
+
if x.dtype != mstype.bool_:
|
|
34
|
+
out = - 1 - x
|
|
35
|
+
else:
|
|
36
|
+
out = invert_fn(x)
|
|
37
|
+
out = convert_to_adapter_tensor(out)
|
|
38
|
+
else:
|
|
39
|
+
out = invert_fn(x)
|
|
40
|
+
return out
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def adapter_abs(x):
|
|
44
|
+
if isinstance(x, adapter_Tensor):
|
|
45
|
+
x = convert_to_ms_tensor(x)
|
|
46
|
+
out = abs_fn(x)
|
|
47
|
+
out = convert_to_adapter_tensor(out)
|
|
48
|
+
else:
|
|
49
|
+
out = abs_fn(x)
|
|
50
|
+
return out
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def adapter_round(*data):
|
|
54
|
+
if (len(data) == 1 and isinstance(data[0], adapter_Tensor)) or \
|
|
55
|
+
(len(data) == 2 and isinstance(data[0], adapter_Tensor) and data[1] is None):
|
|
56
|
+
x = data[0]
|
|
57
|
+
x = convert_to_ms_tensor(x)
|
|
58
|
+
out = round_fn(x)
|
|
59
|
+
out = convert_to_adapter_tensor(out)
|
|
60
|
+
else:
|
|
61
|
+
out = round_fn(*data)
|
|
62
|
+
return out
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def _has_adapter_tensor(*data):
|
|
66
|
+
if len(data) == 1 and isinstance(data[0], adapter_Tensor):
|
|
67
|
+
return True
|
|
68
|
+
for elem in data:
|
|
69
|
+
if isinstance(elem, adapter_Tensor):
|
|
70
|
+
return True
|
|
71
|
+
return False
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def adapter_max(*data):
|
|
75
|
+
if _has_adapter_tensor(*data):
|
|
76
|
+
out = max_fn(*data)
|
|
77
|
+
out = convert_to_adapter_tensor(out)
|
|
78
|
+
else:
|
|
79
|
+
out = max_fn(*data)
|
|
80
|
+
return out
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def adapter_min(*data):
|
|
84
|
+
if _has_adapter_tensor(*data):
|
|
85
|
+
out = min_fn(*data)
|
|
86
|
+
out = convert_to_adapter_tensor(out)
|
|
87
|
+
else:
|
|
88
|
+
out = min_fn(*data)
|
|
89
|
+
return out
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def adapter_sum(*data):
|
|
93
|
+
if _has_adapter_tensor(*data):
|
|
94
|
+
out = sum_fn(*data)
|
|
95
|
+
out = convert_to_adapter_tensor(out)
|
|
96
|
+
else:
|
|
97
|
+
out = sum_fn(*data)
|
|
98
|
+
return out
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
import mindspore as ms
|
|
4
|
+
from mindspore import dtype as mstype
|
|
5
|
+
from mindspore.ops.operations import _inner_ops as inner
|
|
6
|
+
from msadapter.pytorch.tensor import Tensor as adapter_Tensor
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def convert_to_ms_tensor(x):
|
|
10
|
+
return inner.convert_to_ms_tensor(x)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def convert_to_adapter_tensor(x):
|
|
14
|
+
return inner.convert_to_adapter_tensor(x)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def convert_output(out):
|
|
18
|
+
if isinstance(out, ms.Tensor):
|
|
19
|
+
out = convert_to_adapter_tensor(out)
|
|
20
|
+
return out
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def get_registed_fn(ops, *type_names):
|
|
24
|
+
types = tuple(map(mstype.typing.str_to_type, type_names))
|
|
25
|
+
for sigs, fn in ops.entries:
|
|
26
|
+
if len(sigs) != len(types):
|
|
27
|
+
continue
|
|
28
|
+
if any(not mstype._issubclass_(type_, sig) for sig, type_ in zip(sigs, types)):
|
|
29
|
+
continue
|
|
30
|
+
return fn
|
|
31
|
+
raise ValueError(f"For 'MultitypeFuncGraph', cannot find fn match given types: {types}.")
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def _multitype_ops_tensor_calcu(ops, func1, func2):
|
|
35
|
+
@ops.register("Tensor")
|
|
36
|
+
def _tensor(x):
|
|
37
|
+
if isinstance(x, adapter_Tensor):
|
|
38
|
+
x = convert_to_ms_tensor(x)
|
|
39
|
+
out = func1(x)
|
|
40
|
+
out = convert_output(out)
|
|
41
|
+
else:
|
|
42
|
+
out = func2(x)
|
|
43
|
+
return out
|
|
44
|
+
|
|
45
|
+
def update_multitype_ops_tensor_with_fn(ops, func1):
|
|
46
|
+
func2 = get_registed_fn(ops, "Tensor")
|
|
47
|
+
_multitype_ops_tensor_calcu(ops, func1, func2)
|
|
48
|
+
|
|
49
|
+
def update_multitype_ops_tensor(ops):
|
|
50
|
+
func = get_registed_fn(ops, "Tensor")
|
|
51
|
+
_multitype_ops_tensor_calcu(ops, func, func)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def _multitype_ops_tensor_tensor_calcu(ops, func1, func2):
|
|
55
|
+
@ops.register("Tensor", "Tensor")
|
|
56
|
+
def _tensor_and_tensor(x, y):
|
|
57
|
+
if isinstance(x, adapter_Tensor) and isinstance(y, adapter_Tensor):
|
|
58
|
+
x = convert_to_ms_tensor(x)
|
|
59
|
+
y = convert_to_ms_tensor(y)
|
|
60
|
+
out = func1(x, y)
|
|
61
|
+
out = convert_output(out)
|
|
62
|
+
else:
|
|
63
|
+
out = func2(x, y)
|
|
64
|
+
return out
|
|
65
|
+
|
|
66
|
+
def update_multitype_ops_tensor_tensor_with_fn(ops, func1):
|
|
67
|
+
func2 = get_registed_fn(ops, "Tensor", "Tensor")
|
|
68
|
+
_multitype_ops_tensor_tensor_calcu(ops, func1, func2)
|
|
69
|
+
|
|
70
|
+
def update_multitype_ops_tensor_tensor(ops):
|
|
71
|
+
func = get_registed_fn(ops, "Tensor", "Tensor")
|
|
72
|
+
_multitype_ops_tensor_tensor_calcu(ops, func, func)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def _multitype_ops_number_tensor_calcu(ops, func1, func2):
|
|
76
|
+
@ops.register("Number", "Tensor")
|
|
77
|
+
def _number_and_tensor(x, y):
|
|
78
|
+
if isinstance(y, adapter_Tensor):
|
|
79
|
+
y = convert_to_ms_tensor(y)
|
|
80
|
+
out = func1(x, y)
|
|
81
|
+
out = convert_output(out)
|
|
82
|
+
else:
|
|
83
|
+
out = func2(x, y)
|
|
84
|
+
return out
|
|
85
|
+
|
|
86
|
+
def update_multitype_ops_number_tensor_with_fn(ops, func1):
|
|
87
|
+
func2 = get_registed_fn(ops, "Number", "Tensor")
|
|
88
|
+
_multitype_ops_number_tensor_calcu(ops, func1, func2)
|
|
89
|
+
|
|
90
|
+
def update_multitype_ops_number_tensor(ops):
|
|
91
|
+
func = get_registed_fn(ops, "Number", "Tensor")
|
|
92
|
+
_multitype_ops_number_tensor_calcu(ops, func, func)
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def _multitype_ops_tensor_number_calcu(ops, func1, func2):
|
|
96
|
+
@ops.register("Tensor", "Number")
|
|
97
|
+
def _tensor_and_number(x, y):
|
|
98
|
+
if isinstance(x, adapter_Tensor):
|
|
99
|
+
x = convert_to_ms_tensor(x)
|
|
100
|
+
out = func1(x, y)
|
|
101
|
+
out = convert_output(out)
|
|
102
|
+
else:
|
|
103
|
+
out = func2(x, y)
|
|
104
|
+
return out
|
|
105
|
+
|
|
106
|
+
def update_multitype_ops_tensor_number_with_fn(ops, func1):
|
|
107
|
+
func2 = get_registed_fn(ops, "Tensor", "Number")
|
|
108
|
+
_multitype_ops_tensor_number_calcu(ops, func1, func2)
|
|
109
|
+
|
|
110
|
+
def update_multitype_ops_tensor_number(ops):
|
|
111
|
+
func = get_registed_fn(ops, "Tensor", "Number")
|
|
112
|
+
_multitype_ops_tensor_number_calcu(ops, func, func)
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def _multitype_ops_tuple_tensor_calcu(ops, func1, func2):
|
|
116
|
+
@ops.register("Tuple", "Tensor")
|
|
117
|
+
def _tuple_and_tensor(x, y):
|
|
118
|
+
if isinstance(y, adapter_Tensor):
|
|
119
|
+
y = convert_to_ms_tensor(y)
|
|
120
|
+
out = func1(x, y)
|
|
121
|
+
out = convert_output(out)
|
|
122
|
+
else:
|
|
123
|
+
out = func2(x, y)
|
|
124
|
+
return out
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def update_multitype_ops_tuple_tensor_with_fn(ops, func1):
|
|
128
|
+
func2 = get_registed_fn(ops, "Tuple", "Tensor")
|
|
129
|
+
_multitype_ops_tuple_tensor_calcu(ops, func1, func2)
|
|
130
|
+
|
|
131
|
+
def update_multitype_ops_tuple_tensor(ops):
|
|
132
|
+
func = get_registed_fn(ops, "Tuple", "Tensor")
|
|
133
|
+
_multitype_ops_tuple_tensor_calcu(ops, func, func)
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def _multitype_ops_tensor_tuple_calcu(ops, func1, func2):
|
|
137
|
+
@ops.register("Tensor", "Tuple")
|
|
138
|
+
def _tensor_and_tuple(x, y):
|
|
139
|
+
if isinstance(x, adapter_Tensor):
|
|
140
|
+
x = convert_to_ms_tensor(x)
|
|
141
|
+
out = func1(x, y)
|
|
142
|
+
out = convert_output(out)
|
|
143
|
+
else:
|
|
144
|
+
out = func2(x, y)
|
|
145
|
+
return out
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def update_multitype_ops_tensor_tuple_with_fn(ops, func1):
|
|
149
|
+
func2 = get_registed_fn(ops, "Tensor", "Tuple")
|
|
150
|
+
_multitype_ops_tensor_tuple_calcu(ops, func1, func2)
|
|
151
|
+
|
|
152
|
+
def update_multitype_ops_tensor_tuple(ops):
|
|
153
|
+
func = get_registed_fn(ops, "Tensor", "Tuple")
|
|
154
|
+
_multitype_ops_tensor_tuple_calcu(ops, func, func)
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def _multitype_ops_list_tensor_calcu(ops, func1, func2):
|
|
158
|
+
@ops.register("List", "Tensor")
|
|
159
|
+
def _list_and_tensor(x, y):
|
|
160
|
+
if isinstance(y, adapter_Tensor):
|
|
161
|
+
y = convert_to_ms_tensor(y)
|
|
162
|
+
out = func1(x, y)
|
|
163
|
+
out = convert_output(out)
|
|
164
|
+
else:
|
|
165
|
+
out = func2(x, y)
|
|
166
|
+
return out
|
|
167
|
+
|
|
168
|
+
def update_multitype_ops_list_tensor_with_fn(ops, func1):
|
|
169
|
+
func2 = get_registed_fn(ops, "List", "Tensor")
|
|
170
|
+
_multitype_ops_list_tensor_calcu(ops, func1, func2)
|
|
171
|
+
|
|
172
|
+
def update_multitype_ops_list_tensor(ops):
|
|
173
|
+
func = get_registed_fn(ops, "List", "Tensor")
|
|
174
|
+
_multitype_ops_list_tensor_calcu(ops, func, func)
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
def _multitype_ops_tensor_list_calcu(ops, func1, func2):
|
|
178
|
+
@ops.register("Tensor", "List")
|
|
179
|
+
def _tensor_and_list(x, y):
|
|
180
|
+
if isinstance(x, adapter_Tensor):
|
|
181
|
+
x = convert_to_ms_tensor(x)
|
|
182
|
+
out = func1(x, y)
|
|
183
|
+
out = convert_output(out)
|
|
184
|
+
else:
|
|
185
|
+
out = func2(x, y)
|
|
186
|
+
return out
|
|
187
|
+
|
|
188
|
+
def update_multitype_ops_tensor_list_with_fn(ops, func1):
|
|
189
|
+
func2 = get_registed_fn(ops, "Tensor", "List")
|
|
190
|
+
_multitype_ops_tensor_list_calcu(ops, func1, func2)
|
|
191
|
+
|
|
192
|
+
def update_multitype_ops_tensor_list(ops):
|
|
193
|
+
func = get_registed_fn(ops, "Tensor", "List")
|
|
194
|
+
_multitype_ops_tensor_list_calcu(ops, func, func)
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
def _multitype_ops_tensor_none_calcu(ops, func1, func2):
|
|
198
|
+
@ops.register("Tensor", "None")
|
|
199
|
+
def _tensor_and_none(x, y):
|
|
200
|
+
if isinstance(x, adapter_Tensor):
|
|
201
|
+
x = convert_to_ms_tensor(x)
|
|
202
|
+
out = func1(x, y)
|
|
203
|
+
out = convert_output(out)
|
|
204
|
+
else:
|
|
205
|
+
out = func2(x, y)
|
|
206
|
+
return out
|
|
207
|
+
|
|
208
|
+
def update_multitype_ops_tensor_none_with_fn(ops, func1):
|
|
209
|
+
func2 = get_registed_fn(ops, "Tensor", "None")
|
|
210
|
+
_multitype_ops_tensor_none_calcu(ops, func1, func2)
|
|
211
|
+
|
|
212
|
+
def update_multitype_ops_tensor_none(ops):
|
|
213
|
+
func = get_registed_fn(ops, "Tensor", "None")
|
|
214
|
+
_multitype_ops_tensor_none_calcu(ops, func, func)
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
def _multitype_ops_tensor_slice_calcu(ops, func1, func2):
|
|
218
|
+
@ops.register("Tensor", "Slice")
|
|
219
|
+
def _tensor_and_slice(x, y):
|
|
220
|
+
if isinstance(x, adapter_Tensor):
|
|
221
|
+
x = convert_to_ms_tensor(x)
|
|
222
|
+
out = func1(x, y)
|
|
223
|
+
out = convert_output(out)
|
|
224
|
+
else:
|
|
225
|
+
out = func2(x, y)
|
|
226
|
+
return out
|
|
227
|
+
|
|
228
|
+
def update_multitype_ops_tensor_slice_with_fn(ops, func1):
|
|
229
|
+
func2 = get_registed_fn(ops, "Tensor", "Slice")
|
|
230
|
+
_multitype_ops_tensor_slice_calcu(ops, func1, func2)
|
|
231
|
+
|
|
232
|
+
def update_multitype_ops_tensor_slice(ops):
|
|
233
|
+
func = get_registed_fn(ops, "Tensor", "Slice")
|
|
234
|
+
_multitype_ops_tensor_slice_calcu(ops, func, func)
|
|
235
|
+
|
|
236
|
+
def update_multitype_ops_setitem_tensor(ops):
|
|
237
|
+
def register_for_setitem(sigs, fn):
|
|
238
|
+
@ops.register(*sigs)
|
|
239
|
+
def _tensor_setitem(data, index, value):
|
|
240
|
+
if isinstance(data, adapter_Tensor):
|
|
241
|
+
data = convert_to_ms_tensor(data)
|
|
242
|
+
out = fn(data, index, value)
|
|
243
|
+
out = convert_to_adapter_tensor(out)
|
|
244
|
+
else:
|
|
245
|
+
out = fn(data, index, value)
|
|
246
|
+
return out
|
|
247
|
+
|
|
248
|
+
entries = ops.entries.copy()
|
|
249
|
+
for sigs, fn in entries:
|
|
250
|
+
if mstype._issubclass_(sigs[0], mstype.tensor):
|
|
251
|
+
register_for_setitem(sigs, fn)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
string_classes = (str, bytes)
|