MCPcopy Create free account
hub / github.com/pytorch/executorch / call_scan

Method call_scan

exir/pass_base.py:584–616  ·  view source on GitHub ↗
(
        self,
        combine_fn: torch.fx.GraphModule,
        init: List[ProxyValue],
        xs: List[Argument],
        additional_inputs: List[ProxyValue],
        meta: NodeMetadata,
    )

Source from the content-addressed store, hash-verified

582 )
583
584 def call_scan(
585 self,
586 combine_fn: torch.fx.GraphModule,
587 init: List[ProxyValue],
588 xs: List[Argument],
589 additional_inputs: List[ProxyValue],
590 meta: NodeMetadata,
591 ) -> ProxyValue:
592 # Get the expected x element shapes from the combine_fn's placeholders
593 # The combine_fn expects: (carry..., x_element..., additional_inputs...)
594 combine_fn_placeholders = [
595 n for n in combine_fn.graph.nodes if n.op == "placeholder"
596 ]
597 num_init = len(init)
598 # The x_element placeholders are at indices [num_init : num_init + num_xs]
599 xs_element_data = []
600 for i in range(0, len(xs)):
601 ph = combine_fn_placeholders[num_init + i]
602 # Use the placeholder's val which has the correct shape
603 xs_element_data.append(ph.meta["val"])
604
605 combine_fn_result = self.call_submodule(
606 combine_fn, (*init, *xs_element_data, *additional_inputs)
607 )
608 assert combine_fn_result is not None
609
610 return self._fx(
611 "call_function",
612 torch.ops.higher_order.scan,
613 (combine_fn_result.graph_module, init, xs, additional_inputs),
614 {},
615 meta,
616 )
617
618 def call_getitem(
619 self, value: ProxyValue, key: int, meta: NodeMetadata

Callers 1

call_functionMethod · 0.80

Calls 3

call_submoduleMethod · 0.95
_fxMethod · 0.95
appendMethod · 0.45

Tested by

no test coverage detected