@@ -243,8 +243,8 @@ def _generic_walker_step(cls, processor: Callable, inputs, ds):
243243 return cls ._generic_walker_step (processor , flat , ds )
244244
245245 class ChangeDimensionProcessor :
246- def __init__ (self ):
247- self .mapping = {}
246+ def __init__ (self , desired_values ):
247+ self .mapping = desired_values or {}
248248
249249 def _build_new_shape (
250250 self , shape : Tuple [int , ...], ds : Dict [int , Any ]
@@ -310,7 +310,7 @@ def __call__(self, inputs, ds):
310310 new_shape = self ._build_new_shape (inputs .shape , ds )
311311 return self ._build_new_tensor (inputs , new_shape )
312312
313- def change_dynamic_dimensions (self ):
313+ def change_dynamic_dimensions (self , desired_values : Optional [ Dict [ str , int ]] = None ):
314314 """
315315 A model exported with dynamic shapes is not necessarily dynamic
316316 just because the user specified dynamic shapes. The algorithm
@@ -320,6 +320,9 @@ def change_dynamic_dimensions(self):
320320 for the dimension than the first ones, assuming they were used to export
321321 the model.
322322
323+ :param desired_values: to fixed named dimension to have the desired value
324+ :return: new inputs
325+
323326 Example:
324327
325328 .. runpython::
@@ -340,7 +343,7 @@ def change_dynamic_dimensions(self):
340343 print("before:", string_type(kwargs, with_shape=True))
341344 print("-after:", string_type(new_kwargs, with_shape=True))
342345 """
343- return self ._generic_walker (self .ChangeDimensionProcessor ())
346+ return self ._generic_walker (self .ChangeDimensionProcessor (desired_values ))
344347
345348
346349class ModelInputs :
0 commit comments