44#
55# This source code is licensed under the BSD-style license found in the
66# LICENSE file in the root directory of this source tree.
7- from typing import Callable
87
98import pytest
109import torch
@@ -351,43 +350,43 @@ def test_mean_dim_vgf_quant(test_data):
351350 pipeline = VgfPipeline [input_t ](
352351 MeanDim (dim , keep_dim ),
353352 (test_data_val ,),
353+ [], # Quantized mean.dim may be decomposed to sum, avgpool, or both.
354354 [],
355355 symmetric_io_quantization = True ,
356356 quantize = True ,
357357 )
358358 pipeline .run ()
359359
360360
361- mean_input_t = tuple [torch .Tensor , bool ]
362-
363-
364361class MeanDefault (torch .nn .Module ):
365- def forward ( self , tensor : torch .Tensor , keepdim : bool ):
366- return tensor . mean ()
362+ torch_op = " torch.ops.aten.mean.default"
363+ exir_op = "executorch_exir_dialects_edge__ops_aten_mean_default"
367364
368- test_data_suite : dict [str , Callable [[], mean_input_t ]] = {
369- "rank_2" : lambda : (
370- torch .rand (1 , 2 ),
371- False ,
372- ),
373- "rank_2_keepdim" : lambda : (torch .rand (5 , 5 ), True ),
374- "rank_4" : lambda : (torch .rand (5 , 1 , 10 , 1 ), False ),
365+ test_data_suite = {
366+ "rank_1" : lambda : (torch .rand (7 ),),
367+ "rank_2" : lambda : (torch .rand (2 , 5 ),),
368+ "rank_3" : lambda : (torch .rand (2 , 5 , 7 ),),
369+ "rank_4" : lambda : (torch .rand (1 , 5 , 7 , 3 ),),
375370 }
376371
372+ def forward (self , x : torch .Tensor ):
373+ return torch .mean (x )
374+
377375
378376@common .parametrize ("test_data" , MeanDefault .test_data_suite )
379377def test_mean_tosa_FP (test_data ):
380- pipeline = TosaPipelineFP [mean_input_t ](
378+ pipeline = TosaPipelineFP [input_t ](
381379 MeanDefault (),
382380 test_data (),
383- [], # Might be sum, avgpool, or both
381+ MeanDefault .torch_op ,
382+ MeanDefault .exir_op ,
384383 )
385384 pipeline .run ()
386385
387386
388387@common .parametrize ("test_data" , MeanDefault .test_data_suite )
389388def test_mean_tosa_INT (test_data ):
390- pipeline = TosaPipelineINT [mean_input_t ](
389+ pipeline = TosaPipelineINT [input_t ](
391390 MeanDefault (),
392391 test_data (),
393392 [], # Might be sum, avgpool, or both
@@ -396,6 +395,33 @@ def test_mean_tosa_INT(test_data):
396395 pipeline .run ()
397396
398397
398+ @common .parametrize ("test_data" , MeanDefault .test_data_suite )
399+ @common .SkipIfNoModelConverter
400+ def test_mean_vgf_no_quant (test_data ):
401+ pipeline = VgfPipeline [input_t ](
402+ MeanDefault (),
403+ test_data (),
404+ MeanDefault .torch_op ,
405+ MeanDefault .exir_op ,
406+ quantize = False ,
407+ )
408+ pipeline .run ()
409+
410+
411+ @common .parametrize ("test_data" , MeanDefault .test_data_suite )
412+ @common .SkipIfNoModelConverter
413+ def test_mean_vgf_quant (test_data ):
414+ pipeline = VgfPipeline [input_t ](
415+ MeanDefault (),
416+ test_data (),
417+ [], # Quantized mean.default may be decomposed to sum, avgpool, or both.
418+ [],
419+ symmetric_io_quantization = True ,
420+ quantize = True ,
421+ )
422+ pipeline .run ()
423+
424+
399425a16w8_mean_test_parameters = {
400426 "rank_2_keepdim" : lambda : (torch .rand (7 , 3 ), (0 , 1 ), True ),
401427 "rank_3_keepdim" : lambda : (torch .rand (5 , 7 , 3 ), (0 , 1 , 2 ), True ),
0 commit comments