@@ -334,33 +334,33 @@ def test_to_tosa_INT_not_delegated(test_data: Tuple):
334334 pipeline .run ()
335335
336336
337- _TO_COPY_QUANTIZED_IDENTITY_CAST_DATA = {
338- "int8_cast_add " : lambda : (
337+ _TO_COPY_QUANTIZED_INT_TO_FLOAT_CAST_DATA = {
338+ "int8_to_fp32_add " : lambda : (
339339 (torch .randn (1 , 3 , 4 , 4 ) * 10 ).to (dtype = torch .int8 ),
340340 torch .randn (1 , 3 , 4 , 4 ),
341341 torch .float32 ,
342342 ),
343- "int16_cast_add " : lambda : (
343+ "int16_to_fp32_add " : lambda : (
344344 (torch .randn (1 , 3 , 4 , 4 ) * 10 ).to (dtype = torch .int16 ),
345345 torch .randn (1 , 3 , 4 , 4 ),
346346 torch .float32 ,
347347 ),
348- "int32_cast_add " : lambda : (
348+ "int32_to_fp32_add " : lambda : (
349349 (torch .randn (1 , 3 , 4 , 4 ) * 10 ).to (dtype = torch .int32 ),
350350 torch .randn (1 , 3 , 4 , 4 ),
351351 torch .float32 ,
352352 ),
353353}
354354
355355
356- _TO_COPY_QUANTIZED_IDENTITY_CAST_CAT_DATA = {
357- "int8_cast_cat " : lambda : (
356+ _TO_COPY_QUANTIZED_INT_TO_FLOAT_CAST_CAT_DATA = {
357+ "int8_to_fp32_cat " : lambda : (
358358 (torch .randn (1 , 2 , 4 , 4 ) * 10 ).to (dtype = torch .int8 ),
359359 torch .randn (1 , 2 , 4 , 1 ),
360360 torch .float32 ,
361361 3 ,
362362 ),
363- "int16_cast_cat " : lambda : (
363+ "int16_to_fp32_cat " : lambda : (
364364 (torch .randn (1 , 2 , 4 , 4 ) * 10 ).to (dtype = torch .int16 ),
365365 torch .randn (1 , 2 , 4 , 1 ),
366366 torch .float32 ,
@@ -369,8 +369,8 @@ def test_to_tosa_INT_not_delegated(test_data: Tuple):
369369}
370370
371371
372- @common .parametrize ("test_data" , _TO_COPY_QUANTIZED_IDENTITY_CAST_DATA )
373- def test_to_tosa_INT_quantized_identity_cast_add (test_data : Tuple ):
372+ @common .parametrize ("test_data" , _TO_COPY_QUANTIZED_INT_TO_FLOAT_CAST_DATA )
373+ def test_to_tosa_INT_quantized_int_to_float_cast_add (test_data : Tuple ):
374374 x , y , new_dtype = test_data ()
375375 pipeline = TosaPipelineINT [input_t2 ](
376376 CastAddTensor (new_dtype ),
@@ -388,8 +388,8 @@ def test_to_tosa_INT_quantized_identity_cast_add(test_data: Tuple):
388388 pipeline .run ()
389389
390390
391- @common .parametrize ("test_data" , _TO_COPY_QUANTIZED_IDENTITY_CAST_CAT_DATA )
392- def test_to_tosa_INT_quantized_identity_cast_cat (test_data : Tuple ):
391+ @common .parametrize ("test_data" , _TO_COPY_QUANTIZED_INT_TO_FLOAT_CAST_CAT_DATA )
392+ def test_to_tosa_INT_quantized_int_to_float_cast_cat (test_data : Tuple ):
393393 x , y , new_dtype , dim = test_data ()
394394 pipeline = TosaPipelineINT [input_t2 ](
395395 CastCatTensor (new_dtype , dim ),
@@ -400,8 +400,8 @@ def test_to_tosa_INT_quantized_identity_cast_cat(test_data: Tuple):
400400 pipeline .run ()
401401
402402
403- @common .parametrize ("test_data" , _TO_COPY_QUANTIZED_IDENTITY_CAST_DATA )
404- def test_to_tosa_INT_quantized_identity_cast_to_unquantized_add_delegated (
403+ @common .parametrize ("test_data" , _TO_COPY_QUANTIZED_INT_TO_FLOAT_CAST_DATA )
404+ def test_to_tosa_INT_quantized_int_to_float_cast_to_unquantized_add_delegated (
405405 test_data : Tuple ,
406406):
407407 x , y , new_dtype = test_data ()
@@ -423,6 +423,46 @@ def test_to_tosa_INT_quantized_identity_cast_to_unquantized_add_delegated(
423423 pipeline .run ()
424424
425425
426+ _TO_COPY_INT_TO_INT_CAST_DATA = {
427+ "int8_to_int16" : lambda : (
428+ torch .randint (- 127 , 128 , (1 , 2 , 3 , 4 ), dtype = torch .int8 ),
429+ torch .int16 ,
430+ ),
431+ "int8_to_int32" : lambda : (
432+ torch .randint (- 127 , 128 , (1 , 2 , 3 , 4 ), dtype = torch .int8 ),
433+ torch .int32 ,
434+ ),
435+ "int16_to_int8" : lambda : (
436+ torch .randint (- 127 , 128 , (1 , 2 , 3 , 4 ), dtype = torch .int16 ),
437+ torch .int8 ,
438+ ),
439+ "int16_to_int32" : lambda : (
440+ torch .randint (- 127 , 128 , (1 , 2 , 3 , 4 ), dtype = torch .int16 ),
441+ torch .int32 ,
442+ ),
443+ "int32_to_int8" : lambda : (
444+ torch .randint (- 127 , 128 , (1 , 2 , 3 , 4 ), dtype = torch .int32 ),
445+ torch .int8 ,
446+ ),
447+ "int32_to_int16" : lambda : (
448+ torch .randint (- 127 , 128 , (1 , 2 , 3 , 4 ), dtype = torch .int32 ),
449+ torch .int16 ,
450+ ),
451+ }
452+
453+
454+ @common .parametrize ("test_data" , _TO_COPY_INT_TO_INT_CAST_DATA )
455+ def test_to_tosa_INT_int_to_int_cast (test_data : Tuple ):
456+ test_tensor , new_dtype = test_data ()
457+ pipeline = TosaPipelineINT [input_t1 ](
458+ Cast (new_dtype ),
459+ (test_tensor ,),
460+ aten_op = [],
461+ exir_op = [],
462+ )
463+ pipeline .run ()
464+
465+
426466@common .parametrize ("test_data" , _TO_COPY_TEST_DATA_INT )
427467@common .SkipIfNoModelConverter
428468def test_to_vgf_quant (test_data : Tuple ):
@@ -462,6 +502,25 @@ def test_to_vgf_quant(test_data: Tuple):
462502 "rand_fp16_fp16" : "FP16 is not supported" ,
463503}
464504
505+ _TO_COPY_FLOAT_IDENTITY_CAST_DATA = {
506+ "fp32_to_fp32" : lambda : (
507+ torch .rand ((1 , 2 , 3 , 4 ), dtype = torch .float32 ),
508+ torch .float32 ,
509+ ),
510+ }
511+
512+
513+ @common .parametrize ("test_data" , _TO_COPY_FLOAT_IDENTITY_CAST_DATA )
514+ def test_to_tosa_INT_float_to_same_dtype_cast (test_data : Tuple ):
515+ test_tensor , new_dtype = test_data ()
516+ pipeline = TosaPipelineINT [input_t1 ](
517+ CastAdd (new_dtype ),
518+ (test_tensor ,),
519+ aten_op = [],
520+ exir_op = [],
521+ )
522+ pipeline .run ()
523+
465524
466525@common .parametrize (
467526 "test_data" , _TO_COPY_TEST_DATA_REDUNDANT_CAST , xfails = redundant_xfails_FP
@@ -504,6 +563,36 @@ def test_to_tosa_INT_not_delegated_REDUNDANT_CAST(test_data: Tuple):
504563 pipeline .run ()
505564
506565
566+ _TO_COPY_UNSUPPORTED_QUANTIZED_CAST_DATA = {
567+ "fp32_to_fp16" : lambda : (
568+ torch .rand ((1 , 2 , 3 , 4 ), dtype = torch .float32 ),
569+ torch .float16 ,
570+ ),
571+ "fp32_to_int32" : lambda : (
572+ torch .rand ((1 , 2 , 3 , 4 ), dtype = torch .float32 ),
573+ torch .int32 ,
574+ ),
575+ "bool_to_fp32" : lambda : (
576+ torch .randint (0 , 2 , (1 , 2 , 3 , 4 ), dtype = torch .bool ),
577+ torch .float32 ,
578+ ),
579+ }
580+
581+
582+ @common .parametrize ("test_data" , _TO_COPY_UNSUPPORTED_QUANTIZED_CAST_DATA )
583+ def test_to_tosa_INT_unsupported_cast_not_delegated (test_data : Tuple ):
584+ test_tensor , new_dtype = test_data ()
585+ pipeline = OpNotSupportedPipeline [input_t1 ](
586+ Cast (new_dtype ),
587+ (test_tensor ,),
588+ {
589+ "executorch_exir_dialects_edge__ops_dim_order_ops__to_dim_order_copy_default" : 1
590+ },
591+ quantize = True ,
592+ )
593+ pipeline .run ()
594+
595+
507596_TO_COPY_DATA_INT_U55_REJECT = {
508597 "rand_bool_int8" : lambda : (
509598 torch .randint (0 , 2 , (1 , 2 , 3 , 4 ), dtype = torch .bool ),
0 commit comments