feat: support configurable constant-fold exclusions - #4450
Conversation
d688a7c to
7c18031
Compare
|
|
||
| @register_constant_fold_exclusion_rule(TEST_RULE_ID) | ||
| def custom_rule(node): | ||
| return (node,) if node.target is custom_target else () |
There was a problem hiding this comment.
Is it a must for users to register rules?
From the perspective of users, is there any principle for them to say in which scenarios they need to register rules? Can we predefine some rules?
There was a problem hiding this comment.
In this PR, there are no rule yet. #4452 will introduce the first rule.
Usually, users do not need to register rules. I expect that in most cases, the rules are pre-registered.
|
Heads-up on a packaging gap from this PR — the new subpackage is not in
That matters because the import happens at So it works from a source checkout, where the directory is present on disk, and fails only in an installed wheel: which is why it would not have shown up in PR CI. Fix is one line in each list, alongside the existing # dynamo_packages, after line 607
"torch_tensorrt.dynamo.lowering.passes",
+ "torch_tensorrt.dynamo.lowering.constant_fold_exclusions", # dynamo_package_dir, after line 645
"torch_tensorrt.dynamo.lowering.passes": "py/torch_tensorrt/dynamo/lowering/passes",
+ "torch_tensorrt.dynamo.lowering.constant_fold_exclusions": "py/torch_tensorrt/dynamo/lowering/constant_fold_exclusions",I checked every package on disk against both lists and this is the only one missing, so it looks like a one-off rather than a broader pattern. Leaving this to you rather than sending a drive-by patch, since you mentioned a follow-up PR that builds on this one, and you would know whether the intent is for this subpackage to ship or for the import to be restructured instead. Happy to put up the two-line PR if that is easier — just say so. |
|
Opened #4547 with the two-line fix, since this is now failing 331 jobs on Happy to close it if you would rather restructure the import so the subpackage stays internal, which is the other valid shape here. Just did not want to leave main red while that gets decided. |
Description
This PR introduces a new lowering pass
mark_constant_fold_exclusionsjust before theconstant_foldpass. The new pass is used to mark specific nodes so that they will not be constant folded in the next pass.The feature uses a rule based, configurable approach. There are pre-defined rules, and by default all rules are applied. User can use a
disabled_constant_fold_exclusionssetting to disable one or more rules by specifying the rule name.Currently, this PR should not affect the behavior because the rule list is empty. I will work on add a new rule related to attention in the next PR, which depends on the current PR.
Type of change
Please delete options that are not relevant and/or add your own.
Checklist: