Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix bugs when constant_values are list #3873

Open
wants to merge 1 commit into
base: release/10.0
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions tools/onnx-graphsurgeon/onnx_graphsurgeon/ir/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -1282,15 +1282,20 @@ def should_eval_foldable(tensor):
# No need to fold tensors that are already constant.
continue

if size_threshold is not None and values.nbytes > size_threshold:
if isinstance(values, list):
nbytes = sum([v.nbytes for v in values])
else:
nbytes = values.nbytes

if size_threshold is not None and nbytes > size_threshold:
G_LOGGER.debug(
"Will not fold: '{:}' since its size in bytes ({:}) exceeds the size threshold ({:})".format(
name, values.nbytes, size_threshold
name, nbytes, size_threshold
)
)
continue
elif size_threshold is None and values.nbytes > (1 << 20):
large_tensors[name] = values.nbytes
elif size_threshold is None and nbytes > (1 << 20):
large_tensors[name] = nbytes

tensor.to_constant(values)
tensor.inputs.clear() # Constants do not need inputs
Expand Down