@@ -439,22 +439,35 @@ def test_amax_matches_original(self):
439439 (torch .randn (7 ), 0 , True ), # 1-D (fallthrough)
440440 (torch .randn (2 , 2 , 3 , 4 , 5 ), - 1 , True ), # 5-D (fallthrough)
441441 (torch .randn (2 , 3 , 4 , 5 ), (2 , 3 ), True ), # 4-D tuple (fallthrough)
442+ (torch .randn (2 , 3 , 4 , 5 ), np .int64 (- 1 ), True ), # np.int64 axis
443+ (torch .randn (2 , 3 , 4 , 5 ), np .int32 (1 ), True ), # np.int32 axis
442444 ]
443445 for x , axis , keepdims in cases :
444446 with self .subTest (
445447 shape = tuple (x .shape ), axis = axis , keepdims = keepdims
446448 ):
447- original = torch_backend_numpy .amax (
448- x , axis = axis , keepdims = keepdims
449- )
450449 patched = traceable_ops ._patched_amax (
451450 x , axis = axis , keepdims = keepdims
452451 )
453- self .assertEqual (tuple (original .shape ), tuple (patched .shape ))
454- # The reformulation is the identical reduction; values must be
455- # bit-identical, not merely close (a silent numeric drift here
456- # would corrupt attention-sink softmax stabilization).
457- self .assertTrue (torch .equal (original , patched ))
452+ # The original Keras amax cannot handle NumPy integer axes
453+ # (raises "truth value of an empty array is ambiguous"); for
454+ # those cases verify only that the patched version works and
455+ # matches torch.max directly.
456+ if isinstance (axis , np .integer ):
457+ expected = torch .max (
458+ x , dim = int (axis ), keepdim = keepdims
459+ ).values
460+ self .assertTrue (torch .equal (expected , patched ))
461+ else :
462+ original = torch_backend_numpy .amax (
463+ x , axis = axis , keepdims = keepdims
464+ )
465+ self .assertEqual (tuple (original .shape ), tuple (patched .shape ))
466+ # The reformulation is the identical reduction; values must
467+ # be bit-identical, not merely close (a silent numeric
468+ # drift here would corrupt attention-sink softmax
469+ # stabilization).
470+ self .assertTrue (torch .equal (original , patched ))
458471
459472 def test_amax_public_ops_max_4d_matches (self ):
460473 # The public keras op that GPT-OSS attention actually calls.
0 commit comments