Skip to content

Commit 40193dc

Browse files
authored
fix: expand dim for scalar numpy when freezing tensors to IConstantLayers (#3251)
1 parent aa37194 commit 40193dc

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

py/torch_tensorrt/dynamo/conversion/converter_utils.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,13 @@ def convert_with_type_enforcement(
505505
_LOGGER.debug(
506506
f"Freezing tensor {name}_constant_{index} to TRT IConstantLayer"
507507
)
508+
# If the candidate is a scalar Numpy array, handle it accordingly
509+
if isinstance(candidate, np.ndarray) and candidate.shape == ():
510+
_LOGGER.debug(
511+
f"Scalar numpy detected at {name}_constant_{index}, adding rank (1,)"
512+
)
513+
# Convert the scalar to a 1D array (with a single element)
514+
candidate = np.expand_dims(candidate, axis=0)
508515
new_value = get_trt_tensor(
509516
ctx, candidate, name + f"_constant_{index}"
510517
)

0 commit comments

Comments
 (0)