@@ -109,11 +109,10 @@ def inputs_ln(self):
109109 return torch .rand ((2 , 3 , 4 ))
110110
111111 def test_forward (self , inputs , encoder ):
112- output = encoder (inputs , return_hidden_states = True , return_attn_weights = True )
112+ output = encoder (inputs , return_hidden_states = True )
113113
114114 actual_last_hidden_state = output .last_hidden_state
115115 actual_hidden_states = torch .sum (torch .stack (output .hidden_states ), dim = 0 )
116- actual_attentions = torch .sum (torch .stack (output .attentions ), dim = 0 )
117116
118117 expected_last_hidden_state = torch .Tensor (
119118 [
@@ -127,42 +126,13 @@ def test_forward(self, inputs, encoder):
127126 [[5.1976 , 1.9218 ], [3.8499 , 2.2402 ], [3.1757 , - 0.1730 ]],
128127 ]
129128 )
130- expected_attentions = torch .Tensor (
131- [
132- [
133- [
134- [0.8520 , 0.5740 , 0.5740 ],
135- [0.6232 , 0.6884 , 0.6884 ],
136- [0.6232 , 0.6884 , 0.6884 ],
137- ],
138- [
139- [0.5859 , 0.7071 , 0.7071 ],
140- [0.6515 , 0.6742 , 0.6742 ],
141- [0.6515 , 0.6742 , 0.6742 ],
142- ],
143- ],
144- [
145- [
146- [0.7392 , 0.5216 , 0.7392 ],
147- [0.6434 , 0.7132 , 0.6434 ],
148- [0.7392 , 0.5216 , 0.7392 ],
149- ],
150- [
151- [0.6207 , 0.7586 , 0.6207 ],
152- [0.6589 , 0.6822 , 0.6589 ],
153- [0.6207 , 0.7586 , 0.6207 ],
154- ],
155- ],
156- ]
157- )
158129
159130 assert_expected (
160131 actual_last_hidden_state , expected_last_hidden_state , rtol = 0.0 , atol = 1e-4
161132 )
162133 assert_expected (
163134 actual_hidden_states , expected_hidden_states , rtol = 0.0 , atol = 1e-4
164135 )
165- assert_expected (actual_attentions , expected_attentions , rtol = 0.0 , atol = 1e-4 )
166136
167137 # set flags to false
168138 output = encoder (inputs )
@@ -172,13 +142,10 @@ def test_forward(self, inputs, encoder):
172142 )
173143
174144 def test_forward_ln (self , inputs_ln , encoder_ln ):
175- output = encoder_ln (
176- inputs_ln , return_hidden_states = True , return_attn_weights = True
177- )
145+ output = encoder_ln (inputs_ln , return_hidden_states = True )
178146
179147 actual_last_hidden_state = output .last_hidden_state
180148 actual_hidden_states = torch .sum (torch .stack (output .hidden_states ), dim = 0 )
181- actual_attentions = torch .sum (torch .stack (output .attentions ), dim = 0 )
182149
183150 expected_last_hidden_state = torch .Tensor (
184151 [
@@ -208,42 +175,13 @@ def test_forward_ln(self, inputs_ln, encoder_ln):
208175 ],
209176 ]
210177 )
211- expected_attentions = torch .Tensor (
212- [
213- [
214- [
215- [0.6653 , 0.6376 , 0.6971 ],
216- [0.7078 , 0.5621 , 0.7302 ],
217- [0.6506 , 0.6943 , 0.6551 ],
218- ],
219- [
220- [0.6333 , 0.7897 , 0.5770 ],
221- [0.7207 , 0.7019 , 0.5774 ],
222- [0.7285 , 0.7195 , 0.5520 ],
223- ],
224- ],
225- [
226- [
227- [0.6919 , 0.7021 , 0.6060 ],
228- [0.6274 , 0.7462 , 0.6264 ],
229- [0.7025 , 0.7090 , 0.5885 ],
230- ],
231- [
232- [0.5826 , 0.6227 , 0.7947 ],
233- [0.6855 , 0.6174 , 0.6971 ],
234- [0.7317 , 0.6057 , 0.6625 ],
235- ],
236- ],
237- ]
238- )
239178
240179 assert_expected (
241180 actual_last_hidden_state , expected_last_hidden_state , rtol = 0.0 , atol = 1e-4
242181 )
243182 assert_expected (
244183 actual_hidden_states , expected_hidden_states , rtol = 0.0 , atol = 1e-4
245184 )
246- assert_expected (actual_attentions , expected_attentions , rtol = 0.0 , atol = 1e-4 )
247185
248186 # set flags to false
249187 output = encoder_ln (inputs_ln )
0 commit comments