Skip to content

FoldConstantsPass: Why are always_fold_ops restricted to unique consumers? #2466

@iksnagreb

Description

@iksnagreb

I do not fully understand the following: Why is always_fold_ops, which I understand as simply overriding the size limit, restricted to operators which are the single unique consumer of an input? Maybe I have missed this, but I do not see a similar restriction for the usual path where the input is below the size limit? Is it to prevent the model size from increasing by implicitly duplicating large tensors via this override?

if (node.domain, node.op_type) in self.always_fold_ops and all(
len(input.consumers()) == 1 for input in node.inputs if input is not None
):
# If the op is in always_fold_ops and all inputs are used only by this node,
# we can still fold it even if the input size exceeds the limit.
logger.debug(
"Folding large constant for node %s because it is in the always_fold_ops list",
node,
)

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions