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

Method run_method

export/export.py:616–657  ·  view source on GitHub ↗

Run a specific method with the given inputs. Args: method_name: Name of the method to run, defaults to "forward" example_inputs: Optional inputs to use, defaults to the example inputs Returns: The outputs of the method execution

(
        self,
        method_name: str = "forward",
        example_inputs: Optional[Tuple[torch.Tensor, ...]] = None,
    )

Source from the content-addressed store, hash-verified

614 return self._example_inputs[method_name][0]
615
616 def run_method(
617 self,
618 method_name: str = "forward",
619 example_inputs: Optional[Tuple[torch.Tensor, ...]] = None,
620 ) -> Sequence[Any]:
621 """
622 Run a specific method with the given inputs.
623
624 Args:
625 method_name: Name of the method to run, defaults to "forward"
626 example_inputs: Optional inputs to use, defaults to the example inputs
627
628 Returns:
629 The outputs of the method execution
630
631 Raises:
632 RuntimeError: If the method cannot be loaded
633 """
634 # Lazy import to avoid forcing portable_lib dependency at module load time.
635 try:
636 from executorch.runtime import Runtime, Verification
637 except ModuleNotFoundError as e:
638 raise ModuleNotFoundError(
639 "executorch.runtime is not available. "
640 "In OSS: Please ensure executorch is properly installed via pip. "
641 "In fbcode: Please add //executorch/runtime:runtime to your dependencies."
642 ) from e
643
644 et_runtime = Runtime.get()
645 program = et_runtime.load_program(
646 self.get_pte_buffer(), verification=Verification.Minimal
647 )
648 forward = program.load_method(method_name)
649
650 if forward is None:
651 raise RuntimeError(
652 f"Failed to load method '{method_name}' from the program"
653 )
654 if example_inputs is None:
655 example_inputs = self.get_example_input(method_name)
656
657 return forward.execute(example_inputs)
658
659 def print_delegation_info(self) -> None:
660 """

Calls 6

get_pte_bufferMethod · 0.95
get_example_inputMethod · 0.95
load_programMethod · 0.80
load_methodMethod · 0.80
getMethod · 0.45
executeMethod · 0.45