@@ -142,36 +142,39 @@ def forward(self, representations, batch):
142142 single_repr_init = single_repr
143143 single_repr = self .single_repr_dim (single_repr )
144144
145- # prepare float32 precision for equivariance
146- original_dtype = single_repr .dtype
147- single_repr , pairwise_repr = map (lambda t : t .float (), (single_repr , pairwise_repr ))
145+ # initial frames
146+ if 'frames' in representations and exists (representations ['frames' ]):
147+ quaternions , translations = representations ['frames' ]
148+ else :
149+ quaternions = torch .tensor ([1. , 0. , 0. , 0. ], device = device )
150+ quaternions = torch .tile (quaternions , b + (n , 1 ))
151+ translations = torch .zeros (b + (n , 3 ), device = device )
148152
149153 outputs = []
150154
151155 # iterative refinement with equivariant transformer in high precision
152- with commons . torch_default_dtype ( torch . float32 ):
153- # initial frames
154- if 'frames' in representations and exists ( representations [ 'frames' ]):
155- quaternions , translations = representations [ 'frames' ]
156- else :
157- quaternions = torch . tensor ([ 1. , 0. , 0. , 0. ], device = device )
158- quaternions = torch . tile (quaternions , b + ( n , 1 ))
159- translations = torch . zeros ( b + ( n , 3 ), device = device )
156+ with accelerator . autocast ( enabled = False ):
157+ # prepare float32 precision for equivariance
158+ single_repr , pairwise_repr = functional . to (
159+ ( single_repr , pairwise_repr ), dtype = torch . float
160+ )
161+ quaternions , translations = functional . to (
162+ (quaternions , translations ), dtype = torch . float
163+ )
160164 rotations = functional .quaternion_to_matrix (quaternions ).detach ()
161165
162166 # go through the layers and apply invariant point attention and
163167 # feedforward
164168 for i in range (self .structure_module_depth ):
165169 is_last = i == (self .structure_module_depth - 1 )
166170
167- with accelerator .autocast (enabled = False ):
168- single_repr = self .ipa_block (
169- single_repr .float (),
170- mask = batch ['mask' ].bool (),
171- pairwise_repr = pairwise_repr .float (),
172- rotations = rotations .float (),
173- translations = translations .float ()
174- )
171+ single_repr = self .ipa_block (
172+ single_repr ,
173+ mask = batch ['mask' ].bool (),
174+ pairwise_repr = pairwise_repr ,
175+ rotations = rotations ,
176+ translations = translations
177+ )
175178
176179 # update quaternion and translation
177180 quaternion_update , translation_update = self .to_affine_update (single_repr
@@ -197,7 +200,6 @@ def forward(self, representations, batch):
197200 functional .l2_norm (angles )
198201 )
199202 coords = functional .rigids_to_positions (frames , batch ['seq' ])
200- coords .type (original_dtype )
201203 outputs .append (
202204 dict (
203205 frames = functional .rigids_scale (
@@ -212,4 +214,5 @@ def forward(self, representations, batch):
212214
213215
214216def multi_chain_permutation_alignment (value , batch ):
215- return functional .multi_chain_permutation_alignment (value , batch )
217+ with accelerator .autocast (enabled = False ):
218+ return functional .multi_chain_permutation_alignment (value , batch )
0 commit comments