@@ -48,6 +48,8 @@ class NnxTestConf(BaseModel):
4848 has_norm_quant : bool
4949 has_bias : bool
5050 has_relu : bool
51+ synthetic_weights : bool
52+ synthetic_inputs : bool
5153
5254 @model_validator (mode = "after" ) # type: ignore
5355 def check_valid_depthwise_channels (self ) -> NnxTestConf :
@@ -116,6 +118,8 @@ def __init__(
116118 scale : Optional [torch .Tensor ] = None ,
117119 bias : Optional [torch .Tensor ] = None ,
118120 global_shift : Optional [torch .Tensor ] = torch .Tensor ([0 ]),
121+ synthetic_weights : Optional [bool ] = False ,
122+ synthetic_inputs : Optional [bool ] = False ,
119123 ) -> None :
120124 self .conf = conf
121125 self .input = input
@@ -124,6 +128,8 @@ def __init__(
124128 self .scale = scale
125129 self .bias = bias
126130 self .global_shift = global_shift
131+ self .synthetic_weights = synthetic_weights
132+ self .synthetic_inputs = synthetic_inputs
127133
128134 def is_valid (self ) -> bool :
129135 return all (
@@ -207,7 +213,11 @@ def _calculate_global_shift(
207213 """Calculate global shift so that the output values are in the range of out_type"""
208214 s = tensor .type (torch .float64 ).std ()
209215 target_s = 2 ** (out_type ._bits - 1 )
210- return torch .ceil (torch .log2 (s / target_s )).type (torch .int32 )
216+ shift = torch .ceil (torch .log2 (s / target_s )).type (torch .int32 )
217+ if shift < 1 :
218+ return torch .zeros ((1 ,)).type (torch .int32 )
219+ else :
220+ return shift
211221
212222 @staticmethod
213223 def _random_data (_type : IntegerType , shape : Tuple , extremes : Tuple = None ):
@@ -243,20 +253,30 @@ def from_conf(
243253 bias_shape = (1 , conf .out_channel , 1 , 1 )
244254
245255 if input is None :
246- input = NnxTestGenerator ._random_data (
247- _type = conf .in_type ,
248- shape = input_shape ,
249- )
256+ if conf .synthetic_inputs :
257+ inputs = torch .zeros ((1 , conf .in_channel , conf .in_height , conf .in_width ), dtype = torch .int64 )
258+ for i in range (conf .in_channel ):
259+ inputs [:, i ,0 ,0 ] = i
260+ else :
261+ input = NnxTestGenerator ._random_data (
262+ _type = conf .in_type ,
263+ shape = input_shape ,
264+ )
250265
251266 if weight is None :
252- weight_mean = NnxTestGenerator ._DEFAULT_WEIGHT_MEAN
253- weight_std = NnxTestGenerator ._DEFAULT_WEIGHT_STDEV * (1 << (conf .weight_type ._bits - 1 )- 1 )
254- weight = NnxTestGenerator ._random_data_normal (
255- mean = weight_mean ,
256- std = weight_std ,
257- _type = conf .weight_type ,
258- shape = weight_shape ,
259- )
267+ if conf .synthetic_weights :
268+ weight = torch .zeros ((conf .out_channel , 1 if conf .depthwise else conf .in_channel , conf .kernel_shape .height , conf .kernel_shape .width ), dtype = torch .int64 )
269+ for i in range (0 , min (weight .shape [0 ], weight .shape [1 ])):
270+ weight [i ,i ,0 ,0 ] = 1
271+ else :
272+ weight_mean = NnxTestGenerator ._DEFAULT_WEIGHT_MEAN
273+ weight_std = NnxTestGenerator ._DEFAULT_WEIGHT_STDEV * (1 << (conf .weight_type ._bits - 1 )- 1 )
274+ weight = NnxTestGenerator ._random_data_normal (
275+ mean = weight_mean ,
276+ std = weight_std ,
277+ _type = conf .weight_type ,
278+ shape = weight_shape ,
279+ )
260280
261281 if conf .has_norm_quant :
262282 if scale is None :
@@ -306,6 +326,8 @@ def from_conf(
306326 scale = scale ,
307327 bias = bias ,
308328 global_shift = global_shift ,
329+ synthetic_inputs = conf .synthetic_inputs ,
330+ synthetic_weights = conf .synthetic_weights ,
309331 )
310332
311333 @staticmethod
@@ -361,7 +383,10 @@ def generate(self, test_name: str, test: NnxTest):
361383 weight_type = test .conf .weight_type
362384 weight_bits = weight_type ._bits
363385 assert weight_bits > 1 and weight_bits <= 8
364- weight_offset = - (2 ** (weight_bits - 1 ))
386+ if test .synthetic_weights :
387+ weight_offset = 0
388+ else :
389+ weight_offset = - (2 ** (weight_bits - 1 ))
365390 weight_out_ch , weight_in_ch , weight_ks_h , weight_ks_w = test .weight .shape
366391 weight_data : np .ndarray = test .weight .numpy () - weight_offset
367392 weight_init = self .weightEncode (
0 commit comments