@@ -708,6 +708,35 @@ def test_dtype_arg(self):
708708 loss = h_obj (self .y_true , self .y_pred )
709709 self .assertDType (loss , "bfloat16" )
710710
711+ def test_huber_memory_usage_debug_05 (self ):
712+ import tensorflow as tf , numpy as np , keras
713+
714+ print ("\n [Huber GPU Memory Debug: delta=0.5]" )
715+ gpus = tf .config .experimental .list_physical_devices ('GPU' )
716+ if not gpus :
717+ print ("No GPU found. Skipping test." )
718+ return
719+ try :
720+ for gpu in gpus :
721+ tf .config .experimental .set_memory_growth (gpu , True )
722+ except RuntimeError as e :
723+ print (f"[Info] GPU memory growth already set or GPU initialized: { e } " )
724+
725+ x = np .random .rand (1000 , 1 )
726+ y = ((3 * x ) + 2 ) + np .random .randn (1000 , 1 )
727+ huber_loss = keras .losses .Huber (delta = 0.5 )
728+ loss = huber_loss (y , x )
729+ print (f"Huber loss: { loss .numpy ():.6f} " )
730+
731+ memory = sum (tf .config .experimental .get_memory_info (f'GPU:{ i } ' )['current' ] for i in range (len (gpus )))
732+ print (f"GPU memory usage: { memory } bytes" )
733+
734+ # sanity check for stable GPU usage (adjust threshold as needed)
735+ assert memory > 0 , (
736+ f"GPU memory not allocated or usage is zero. "
737+ f"Current usage: { memory } bytes"
738+ )
739+
711740
712741class LogCoshTest (testing .TestCase ):
713742 def setup (self ):
0 commit comments