@@ -83,13 +83,13 @@ def _get_slice_adjustment(
8383 if exact_values is not None :
8484 adjustments = {max (value - pad , 0 ) for value in exact_values }
8585 if len (adjustments ) == 1 :
86- adjustment = next (iter (adjustments ))
87- return adjustment if adjustment > 0 else None
86+ exact_adjustment = next (iter (adjustments ))
87+ return exact_adjustment if exact_adjustment > 0 else None
8888
8989 if pad >= stride - 1 :
9090 return None
9191
92- adjustment : SymIntLike | None = None # type: ignore[no-redef]
92+ adjustment : SymIntLike | None = None
9393 for threshold in range (pad + 1 , stride ):
9494 term = (remainder + stride - threshold ) // stride
9595 adjustment = term if adjustment is None else adjustment + term
@@ -272,10 +272,29 @@ def call(self, graph_module: torch.fx.GraphModule) -> PassResult:
272272
273273 parent_node = node .args [0 ]
274274 with graph_module .graph .inserting_before (node ):
275+ # ``Graph.create_node`` rejects raw SymInts in
276+ # call_function args. Aggregate every slice arg across
277+ # all entries and lift via a single ``materialize_symints``
278+ # call -- the helper walks the graph once for producer
279+ # discovery, so a single call amortises that cost and lets
280+ # symints with shared sub-expressions get hash-consed into
281+ # one subgraph. Plain ints pass through unchanged.
282+ flat = [a for args in slice_args for a in args ]
283+ materialized = iter (graph .materialize_symints (flat ))
284+ # Pop exactly len(args) values from the materialized iterator
285+ # and pack them back into a tuple -- regroups the flat list
286+ # of lifted values into the original (dim, start, end) shape.
287+ lifted_slice_args = [
288+ tuple (next (materialized ) for _ in args ) for args in slice_args
289+ ]
290+
275291 last_node = cast (torch .fx .Node , parent_node )
276- for args in slice_args :
292+ for args in lifted_slice_args :
277293 slice_node = create_node (
278- graph , slice_op , (last_node ,) + args , from_node = node
294+ graph ,
295+ slice_op ,
296+ (last_node ,) + args ,
297+ from_node = node ,
279298 )
280299 last_node = slice_node
281300 node .replace_input_with (cast (torch .fx .Node , parent_node ), last_node )
0 commit comments