File tree Expand file tree Collapse file tree
tensor2tensor/mesh_tensorflow/research Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -475,6 +475,10 @@ def _top_2_gating(
475475 inputs , experts_dim , use_bias = False ,
476476 expert_dims = outer_expert_dims ), experts_dim )
477477
478+ # The internals of this function run in float32.
479+ # bfloat16 seems to reduce quality.
480+ raw_gates = mtf .to_float (raw_gates )
481+
478482 expert_capacity_f = float (expert_capacity_dim .size )
479483
480484 # FIND TOP 2 EXPERTS PER POSITON
@@ -591,6 +595,9 @@ def _top_2_gating(
591595 * mtf .one_hot (index_2 , experts_dim )
592596 * mtf .one_hot (mtf .to_int32 (position_in_expert_2 ), expert_capacity_dim ))
593597
598+ combine_tensor = mtf .cast (combine_tensor , inputs .dtype )
599+ loss = mtf .cast (loss , inputs .dtype )
600+
594601 dispatch_tensor = mtf .cast (
595602 mtf .cast (combine_tensor , tf .bool ), combine_tensor .dtype )
596603
You can’t perform that action at this time.
0 commit comments