2626import transformer_engine .jax as te
2727import transformer_engine .jax .flax as te_flax
2828
29+ from common import is_bf16_supported
30+
2931os .environ ["CUDA_DEVICE_ORDER" ] = "PCI_BUS_ID"
3032DEVICE_DP_AXIS = "data"
3133DEVICE_TP_AXIS = "model"
@@ -554,8 +556,9 @@ def encoder_parser(args):
554556def query_gpu (q ):
555557 """Query GPU info on the system"""
556558 gpu_has_fp8 , reason = te .fp8 .is_fp8_available ()
559+ gpu_has_bf16 = is_bf16_supported ()
557560 num_gpu = len (jax .devices ())
558- q .put ([num_gpu , gpu_has_fp8 , reason ])
561+ q .put ([num_gpu , gpu_has_fp8 , gpu_has_bf16 , reason ])
559562
560563
561564def unittest_query_gpu ():
@@ -568,15 +571,15 @@ def unittest_query_gpu():
568571 q = mp .Queue ()
569572 p = mp .Process (target = query_gpu , args = (q ,))
570573 p .start ()
571- num_gpu , gpu_has_fp8 , reason = q .get ()
574+ num_gpu , gpu_has_fp8 , gpu_has_bf16 , reason = q .get ()
572575 p .join ()
573- return num_gpu , gpu_has_fp8 , reason
576+ return num_gpu , gpu_has_fp8 , gpu_has_bf16 , reason
574577
575578
576579class TestEncoder (unittest .TestCase ):
577580 """Encoder unittests"""
578581
579- num_gpu , gpu_has_fp8 , reason = unittest_query_gpu ()
582+ num_gpu , gpu_has_fp8 , gpu_has_bf16 , reason = unittest_query_gpu ()
580583
581584 def exec (self , use_fp8 ):
582585 """Run 3 epochs for testing"""
@@ -600,6 +603,7 @@ def exec(self, use_fp8):
600603
601604 return results
602605
606+ @unittest .skipIf (not gpu_has_bf16 , "Device compute capability 8.0+ is required for BF16" )
603607 def test_te_bf16 (self ):
604608 """Test Transformer Engine with BF16"""
605609 results = self .exec (False )
0 commit comments