Repository navigation
Skip executing large aliased constant folds that 4531 will not install. - #4597
micwill755 wants to merge 3 commits into
Conversation
a41ed2f to
20b8bcd
Compare
d844300 to
b61b68c
Compare
20b8bcd to
d48152c
Compare
b61b68c to
cacfbc5
Compare
d48152c to
6f91a46
Compare
cacfbc5 to
59fd02a
Compare
ee681ee to
fe0fb9c
Compare
59fd02a to
e35fac9
Compare
fe0fb9c to
c9aee71
Compare
e35fac9 to
f0695ce
Compare
c9aee71 to
cd041e7
Compare
f0695ce to
8ccd56d
Compare
| """ | ||
| if node.op != "call_function" or node.target not in _ALIASING_VIEW_OPS: | ||
| return False | ||
| return _source_attr_nbytes(gm, node) > _MAX_CONSTANT_FOLD_BYTES |
There was a problem hiding this comment.
The skip decision uses the size of the root get_attr, not the view's output size. So taking a small select.int of a large weight skips the fold, and conversion then fails.
#4531's install-skip uses the folded output size plus a real storage-aliasing check. This check uses _source_attr_nbytes, the size of the weight at the root. For a 4 KiB select.int of a 4 MiB weight, the op isn't folded, so it reaches impl/select.py with a raw constant: RuntimeError: slice_tensor received input tensor(...) that is not part of the TensorRT region!. slice.Tensor has the same size mismatch but compiles, because its converter handles constant inputs.
I reproduced this on this PR, and it still fails at the top of the stack. Only permute is tested.
The fix is to decide from the node's output size (node.meta["val"]), matching #4531. Or drop select.int (and anything else whose converter rejects a constant input) from _ALIASING_VIEW_OP_NAMES.
There was a problem hiding this comment.
Fixed in eebd4de. The skip now uses the view output size from node.meta["val"], and the allowlist is limited to aten.permute.default, whose converter accepts constant inputs. Small select.int and slice.Tensor outputs from large weights are therefore still folded. I added regression tests covering both the skip decision and the small-select case.
cd041e7 to
a56ecf0
Compare
8ccd56d to
6daf644
Compare
a56ecf0 to
6e5e81f
Compare
6daf644 to
90f8285
Compare
6e5e81f to
9ae4895
Compare
90f8285 to
79c54b0
Compare
There was a problem hiding this comment.
There are some changes that do not conform to Python style guidelines:
--- /home/runner/work/TensorRT/TensorRT/py/torch_tensorrt/dynamo/conversion/impl/moe.py 2026-10-06 21:35:00.255699+00:00
+++ /home/runner/work/TensorRT/TensorRT/py/torch_tensorrt/dynamo/conversion/impl/moe.py 2026-10-06 21:35:20.981758+00:00
@@ -94,11 +94,13 @@
ctx, offs, torch.int32, f"{name}_offs_i32", target, source_ir
)
offs_row = impl.shuffle.reshape(
ctx, target, source_ir, f"{name}_offs_row", offs_i32, (1, -1)
)
- passed = impl.elementwise.le(ctx, target, source_ir, f"{name}_passed", offs_row, rows)
+ passed = impl.elementwise.le(
+ ctx, target, source_ir, f"{name}_passed", offs_row, rows
+ )
group = impl.reduce.sum(
ctx,
target,
source_ir,
f"{name}_group",
--- /home/runner/work/TensorRT/TensorRT/py/torch_tensorrt/dynamo/conversion/aten_ops_converters.py 2026-10-06 21:35:00.254191+00:00
+++ /home/runner/work/TensorRT/TensorRT/py/torch_tensorrt/dynamo/conversion/aten_ops_converters.py 2026-10-06 21:35:23.368919+00:00
@@ -4640,13 +4640,11 @@
if key in kwargs and kwargs[key] is not None:
return kwargs[key]
return args_bounds_check(args, index, default)
-def histc_validator(
- node: Node, settings: Optional[CompilationSettings] = None
-) -> bool:
+def histc_validator(node: Node, settings: Optional[CompilationSettings] = None) -> bool:
bins = _arg_or_kwarg(node.args, node.kwargs, 1, "bins", 100)
lo = _arg_or_kwarg(node.args, node.kwargs, 2, "min", 0)
hi = _arg_or_kwarg(node.args, node.kwargs, 3, "max", 0)
if not all(
isinstance(v, (int, float)) and not isinstance(v, bool) for v in (bins, lo, hi)9ae4895 to
dba7b55
Compare
5b7b71b to
1565f07
Compare
fb39431 to
7c47c8b
Compare
b9d3040 to
eebd4de
Compare
7c47c8b to
e99b651
Compare
Inductor's skip_folding_node_fn never fires on our cf.run() path; honor it so large weight permutes/views are not computed, then discarded.
e99b651 to
8923268
Compare
eebd4de to
98ad60b
Compare
Summary
skip_folding_node_fnduringconstant_fold()so large aliased weight permutes/views are not executed, then thrown away.cpu().contiguous()). This skips computing them:_TorchTensorRTConstantFolder.run_nodereturns unknown without calling the op when the node is a true view of a large module tensor.aten.contiguousand other materializing ops still run. The 4531 install-time skip stays as a safety net.PR 6 of the compile-startup stack; based on #4596.
Test plan
tests/py/dynamo/lowering/test_skip_aliased_fold_execute.py(large permute skipped and not executed, small permute still folds, large contiguous still executes, materializedweight + weightstill folds)ConstantFolder.runis ~50 ms, of which the aliased permutes are ~2 ms (4531 already took the ~0.25 scpu().contiguous()copies)Stack created with GitHub Stacks CLI • Give Feedback 💬