-
Notifications
You must be signed in to change notification settings - Fork 322
/
Copy pathtest_transformer.py
73 lines (55 loc) · 1.96 KB
/
test_transformer.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
# Copyright (c) 2021 PPViT Authors. All Rights Reserved.
#
# 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.:
import unittest
import paddle
import numpy as np
from transformer import Transformer
from position_embedding import build_position_encoding
from utils import NestedTensor
class TransformerTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
paddle.set_device('cpu')
cls.tensors = paddle.randn((4, 256, 24, 33))
cls.masks = paddle.ones((4, 24, 33))
cls.query_embed = paddle.randn((100, 256))
cls.pos_embed = paddle.randn((4, 256, 24, 33))
@classmethod
def tearDown(cls):
pass
@classmethod
def tearDown(cls):
pass
@unittest.skip('skip fo debug')
def test_position_embed(self):
t = TransformerTest.tensors
m = TransformerTest.masks
tensor_list = NestedTensor(t, m)
pos_embed = build_position_encoding()
out = pos_embed(tensor_list)
self.assertEqual(out.shape, [4, 256, 24, 33])
@unittest.skip('skip fo debug')
def test_transformer(self):
t = TransformerTest.tensors
m = TransformerTest.masks
q = TransformerTest.query_embed
p = TransformerTest.pos_embed
model = Transformer()
out = model(src=t,
mask=m,
query_embed=q,
pos_embed=p)
@unittest.skip('skip fo debug')
def test_position_embed_sine(self):
pass