@@ -123,3 +123,41 @@ def get_shape_with_dynamic_shape(
123123 select_layer = ctx .net .add_select (condition_val , input_shape , scale_res )
124124 set_layer_name (select_layer , target , f"{ name } _select" )
125125 return select_layer .get_output (0 )
126+
127+
128+ def to_trt_shape_tensor (
129+ ctx : ConversionContext , target : Target , name : str , shape_list : List [int | TRTTensor ]
130+ ) -> TRTTensor :
131+ """
132+ Convert a mixed shape list (ints + ITensors) into a single ITensor.
133+
134+ Args:
135+ ctx: ConversionContext
136+ target: fx node target (used for naming).
137+ name (str): base name for layer naming.
138+ shape_list (list[int | ITensor]): list containing static ints and/or ITensors.
139+
140+ Returns:
141+ ITensor if shape_list contains any ITensors, else plain Python list of ints.
142+ """
143+ trt_tensors = []
144+
145+ for i , s in enumerate (shape_list ):
146+ if isinstance (s , int ):
147+ const = ctx .net .add_constant ((1 ,), np .array ([s ], dtype = np .int32 ))
148+ set_layer_name (const , target , f"{ name } _dim{ i } _const" )
149+ trt_tensors .append (const .get_output (0 ))
150+ else :
151+ # Assume it's already an ITensor
152+ trt_tensors .append (s )
153+
154+ if trt_tensors :
155+ if any (not isinstance (s , int ) for s in shape_list ):
156+ # Concatenate everything into a single ITensor
157+ concat_layer = ctx .net .add_concatenation (trt_tensors )
158+ concat_layer .axis = 0
159+ set_layer_name (concat_layer , target , f"{ name } _shape_concat" )
160+ return concat_layer .get_output (0 )
161+
162+ # If no ITensor found, return plain list of ints
163+ return shape_list
0 commit comments