@@ -528,6 +528,7 @@ def fn(a):
528528
529529
530530def test_div_exact ():
531+ # Test that division with integer inputs and requires_grad tensor output works correctly
531532 def fn (a , b , c ):
532533 indices = torch .div (a , b , rounding_mode = "trunc" )
533534 # this would throw an error if indices are not ints
@@ -536,9 +537,13 @@ def fn(a, b, c):
536537 jfn = thunder .jit (fn )
537538 a = torch .randint (1 , 5 , (5 ,))
538539 b = torch .ones (5 , dtype = torch .int32 )
539- c = torch .randn (5 , 5 )
540- assert_close (fn (a , b , c ), jfn (a , b , c ))
540+ c = torch .randn (5 , 5 , requires_grad = True )
541+ result_eager = fn (a , b , c )
542+ result_jit = jfn (a , b , c )
543+ assert_close (result_eager , result_jit )
544+ # Ensure the division primitive is used (no div_exact)
541545 trc = thunder .last_traces (jfn )[- 1 ]
542546 for bsym in trc .bound_symbols :
543547 if bsym .sym .id == "div" :
544- assert "div_exact" in [ssym .sym .name for ssym in bsym .subsymbols [0 ].subsymbols ]
548+ # Verify that prims.div is used, not a separate div_exact primitive
549+ assert "div" in [ssym .sym .name for ssym in bsym .subsymbols [0 ].subsymbols ]
0 commit comments