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

Function _restore_delegates

exir/_serialize/_program.py:595–624  ·  view source on GitHub ↗

Find and replace the Program's references to these segments, inlining the data. Args: program: The Program holding non-inlined delegates. Modified in-place. segments: List of bytes containing the delegate data. Not modified. Returns: The Program with delegates restored.

(program: Program, segments: List[bytes])

Source from the content-addressed store, hash-verified

593
594
595def _restore_delegates(program: Program, segments: List[bytes]) -> Program:
596 """Find and replace the Program's references to these segments, inlining
597 the data.
598
599 Args:
600 program: The Program holding non-inlined delegates. Modified in-place.
601 segments: List of bytes containing the delegate data. Not modified.
602
603 Returns: The Program with delegates restored.
604 """
605 for plan_index, plan in enumerate(program.execution_plan):
606 for delegate_index, delegate in enumerate(plan.delegates):
607 if delegate.processed.location == DataLocation.INLINE:
608 continue
609 assert delegate.processed.location == DataLocation.SEGMENT
610 index = delegate.processed.index
611 if index >= len(segments):
612 raise ValueError(
613 f"Plan {plan_index} delegate {delegate_index} "
614 + f"segment index {index} >= num segments {len(segments)}"
615 )
616
617 data_index: int = len(program.backend_delegate_data)
618 program.backend_delegate_data.append(
619 BackendDelegateInlineData(data=segments[index])
620 )
621 delegate.processed = BackendDelegateDataReference(
622 location=DataLocation.INLINE, index=data_index
623 )
624 return program
625
626
627def _restore_constant_segment(

Callers 1

_restore_segmentsFunction · 0.85

Calls 3

appendMethod · 0.45

Tested by

no test coverage detected