Skip to content

registry

registry ¤

LayerOptPattern = type[LayerOptPatternDefn] module-attribute ¤

ParameterOptMatch = GraphOptMatch[TorchParameterNode] module-attribute ¤

ParameterOptPattern = type[ParameterOptPatternDefn] module-attribute ¤

ParameterOptPatternDefn = GraphOptPatternDefn[TorchParameterNode] module-attribute ¤

LayerOptApplyFunc ¤

Bases: Protocol

Source code in cirkit/backend/torch/optimization/registry.py
65
66
67
class LayerOptApplyFunc(Protocol):
    def __call__(self, compiler: "TorchCompiler", match: LayerOptMatch) -> tuple[TorchLayer, ...]:
        ...

__call__(compiler, match) ¤

Source code in cirkit/backend/torch/optimization/registry.py
66
67
def __call__(self, compiler: "TorchCompiler", match: LayerOptMatch) -> tuple[TorchLayer, ...]:
    ...

LayerOptMatch ¤

Bases: GraphOptMatch[TorchLayer]

Source code in cirkit/backend/torch/optimization/registry.py
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
class LayerOptMatch(GraphOptMatch[TorchLayer]):
    def __init__(
        self,
        pattern: LayerOptPattern,
        entries: list[TorchLayer],
        pentries: list[dict[str, list[ParameterOptMatch]]],
    ):
        super().__init__(pattern, entries)
        self._pentries = pentries

    @property
    def pentries(self) -> list[dict[str, list[ParameterOptMatch]]]:
        return self._pentries

    @cached_property
    def size(self) -> int:
        size = super().size
        for pentry in self._pentries:
            for pmatches in pentry.values():
                size += sum(match.size for match in pmatches)
        return size

_pentries = pentries instance-attribute ¤

pentries property ¤

size cached property ¤

__init__(pattern, entries, pentries) ¤

Source code in cirkit/backend/torch/optimization/registry.py
43
44
45
46
47
48
49
50
def __init__(
    self,
    pattern: LayerOptPattern,
    entries: list[TorchLayer],
    pentries: list[dict[str, list[ParameterOptMatch]]],
):
    super().__init__(pattern, entries)
    self._pentries = pentries

LayerOptPatternDefn ¤

Bases: GraphOptPatternDefn[TorchLayer]

Source code in cirkit/backend/torch/optimization/registry.py
25
26
27
28
29
30
31
32
33
34
35
36
class LayerOptPatternDefn(GraphOptPatternDefn[TorchLayer]):
    @classmethod
    def entries(cls) -> list[type[TorchLayer]]:
        ...

    @classmethod
    def ppatterns(cls) -> list[dict[str, ParameterOptPattern]]:
        ...

    @classmethod
    def cpatterns(cls) -> list[dict[str, Any]]:
        ...

cpatterns() classmethod ¤

Source code in cirkit/backend/torch/optimization/registry.py
34
35
36
@classmethod
def cpatterns(cls) -> list[dict[str, Any]]:
    ...

entries() classmethod ¤

Source code in cirkit/backend/torch/optimization/registry.py
26
27
28
@classmethod
def entries(cls) -> list[type[TorchLayer]]:
    ...

ppatterns() classmethod ¤

Source code in cirkit/backend/torch/optimization/registry.py
30
31
32
@classmethod
def ppatterns(cls) -> list[dict[str, ParameterOptPattern]]:
    ...

LayerOptRegistry ¤

Bases: CompilerRegistry[LayerOptPattern, LayerOptApplyFunc]

Source code in cirkit/backend/torch/optimization/registry.py
79
80
81
82
83
84
85
class LayerOptRegistry(CompilerRegistry[LayerOptPattern, LayerOptApplyFunc]):
    @classmethod
    def _validate_rule_function(cls, func: LayerOptApplyFunc) -> bool:
        ann = func.__annotations__.copy()
        del ann["return"]
        args = tuple(ann.keys())
        return ann[args[-1]] == LayerOptMatch

_validate_rule_function(func) classmethod ¤

Source code in cirkit/backend/torch/optimization/registry.py
80
81
82
83
84
85
@classmethod
def _validate_rule_function(cls, func: LayerOptApplyFunc) -> bool:
    ann = func.__annotations__.copy()
    del ann["return"]
    args = tuple(ann.keys())
    return ann[args[-1]] == LayerOptMatch

ParameterOptApplyFunc ¤

Bases: Protocol

Source code in cirkit/backend/torch/optimization/registry.py
18
19
20
21
22
class ParameterOptApplyFunc(Protocol):
    def __call__(
        self, compiler: "TorchCompiler", match: ParameterOptMatch
    ) -> tuple[TorchParameterNode, ...]:
        ...

__call__(compiler, match) ¤

Source code in cirkit/backend/torch/optimization/registry.py
19
20
21
22
def __call__(
    self, compiler: "TorchCompiler", match: ParameterOptMatch
) -> tuple[TorchParameterNode, ...]:
    ...

ParameterOptRegistry ¤

Bases: CompilerRegistry[ParameterOptPattern, ParameterOptApplyFunc]

Source code in cirkit/backend/torch/optimization/registry.py
70
71
72
73
74
75
76
class ParameterOptRegistry(CompilerRegistry[ParameterOptPattern, ParameterOptApplyFunc]):
    @classmethod
    def _validate_rule_function(cls, func: ParameterOptApplyFunc) -> bool:
        ann = func.__annotations__.copy()
        del ann["return"]
        args = tuple(ann.keys())
        return ann[args[-1]] == ParameterOptMatch

_validate_rule_function(func) classmethod ¤

Source code in cirkit/backend/torch/optimization/registry.py
71
72
73
74
75
76
@classmethod
def _validate_rule_function(cls, func: ParameterOptApplyFunc) -> bool:
    ann = func.__annotations__.copy()
    del ann["return"]
    args = tuple(ann.keys())
    return ann[args[-1]] == ParameterOptMatch