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

Function decompose_clip

tests/python/nightly/test_nnapi/infrastructure.py:51–72  ·  view source on GitHub ↗
(mod: tvm.IRModule)

Source from the content-addressed store, hash-verified

49
50
51def decompose_clip(mod: tvm.IRModule) -> tvm.IRModule:
52 from tvm.relax import Expr
53 from tvm.relax.dpl import DFPattern, rewrite_call
54 from tvm.relax.dpl.pattern import is_op, wildcard
55
56 input_pattern = wildcard()
57 min_pattern = wildcard()
58 max_pattern = wildcard()
59 pattern = is_op("relax.clip")(input_pattern, min_pattern, max_pattern)
60
61 def _rewriter(expr: Expr, matches: dict[DFPattern, Expr]) -> Expr: # pylint: disable=unused-argument
62 dtype = matches[input_pattern].struct_info.dtype
63 return R.minimum(
64 R.maximum(
65 matches[input_pattern],
66 R.const(np.array(matches[min_pattern].value.value).astype(dtype), dtype),
67 ),
68 R.const(np.array(matches[max_pattern].value.value).astype(dtype), dtype),
69 )
70
71 mod["main"] = rewrite_call(pattern, _rewriter, mod["main"])
72 return mod
73
74
75def _build(mod, enable_nnapi):

Callers 1

_buildFunction · 0.85

Calls 3

wildcardFunction · 0.90
is_opFunction · 0.90
rewrite_callFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…