MCPcopy Create free account
hub / github.com/apache/tvm / PatternContext

Class PatternContext

python/tvm/relax/dpl/context.py:27–79  ·  view source on GitHub ↗

A context object for doing graph (topogical) pattern matching.

Source from the content-addressed store, hash-verified

25
26
27class PatternContext(tvm.runtime.Object):
28 """A context object for doing graph (topogical) pattern matching."""
29
30 def __init__(self, incremental=False):
31 """
32 Initialize the PatternContext
33
34 Parameters
35 ----------
36 incremental : bool, optional
37 perform incremental matching based on the recent context, by default False
38 """
39 self.__init_handle_by_constructor__(ffi.PatternContext, incremental) # type: ignore
40
41 def __enter__(self):
42 """Enter the context"""
43 ffi.enter_context(self) # type: ignore
44 return self
45
46 def __exit__(self, exc_type, exc_value, traceback):
47 """Exit the context"""
48 ffi.exit_context(self) # type: ignore
49
50 @staticmethod
51 def current() -> "PatternContext":
52 """
53 Get the current context
54
55 Returns
56 -------
57 PatternContext
58 The current context
59 """
60 return ffi.current_context() # type: ignore
61
62 def match_dfb(
63 self,
64 dfb: DataflowBlock,
65 ) -> dict[DFPattern, Var]:
66 """
67 Match a DataflowBlock via a graph of DFPattern and corresponding constraints
68
69 Parameters
70 ----------
71 dfb : DataflowBlock
72 The DataflowBlock to match
73
74 Returns
75 -------
76 Dict[DFPattern, Var]
77 The mapping from DFPattern to matched expression
78 """
79 return ffi.match_dfb(self, dfb) # type: ignore

Callers 15

test_simple_used_byFunction · 0.85
test_simple_oubFunction · 0.85
test_diamondFunction · 0.85
test_diamond_counter_oubFunction · 0.85
test_nested_contextFunction · 0.85
test_two_cbrFunction · 0.85
test_two_matmulFunction · 0.85
test_concat_mm_splitFunction · 0.85
test_self_attentionFunction · 0.85

Calls

no outgoing calls

Tested by 15

test_simple_used_byFunction · 0.68
test_simple_oubFunction · 0.68
test_diamondFunction · 0.68
test_diamond_counter_oubFunction · 0.68
test_nested_contextFunction · 0.68
test_two_cbrFunction · 0.68
test_two_matmulFunction · 0.68
test_concat_mm_splitFunction · 0.68
test_self_attentionFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…