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

Function bind_assign_value

python/tvm/relax/script/parser/parser.py:43–102  ·  view source on GitHub ↗
(
    self: Parser,
    node: doc.expr,
    var_name: str,
    value: Any,
    anno_sinfo: StructInfo | None = None,
)

Source from the content-addressed store, hash-verified

41
42
43def bind_assign_value(
44 self: Parser,
45 node: doc.expr,
46 var_name: str,
47 value: Any,
48 anno_sinfo: StructInfo | None = None,
49) -> Any:
50 var_table = self.var_table.get()
51
52 if isinstance(value, tirx.Var):
53 if value.name and var_name != value.name:
54 self.report_error(
55 node,
56 "Cannot define TIR variables with different names. The LHS of binding should "
57 "has the same name provided in RHS.",
58 )
59 if var_name in var_table:
60 prev_value = var_table[var_name]
61 if not isinstance(prev_value, tirx.Var):
62 self.report_error(
63 node,
64 "Cannot redefine a non-TIR-variable object to a TIR variable. Please "
65 "define the TIR variable with another name.",
66 )
67 if prev_value.dtype != value.dtype:
68 self.report_error(
69 node,
70 "Expected the same dtype for TIR vars "
71 f"but got {value.dtype} vs {prev_value.dtype}",
72 )
73 if not isinstance(value, type(prev_value)):
74 self.report_error(
75 node,
76 f"Expected the same IR type for TIR vars "
77 f"but existing value {type(value)} is mismatched "
78 f"to previous {type(prev_value)}",
79 )
80 value = prev_value
81 IRBuilder.name(var_name, value)
82 return value
83
84 if isinstance(value, tuple):
85 value = convert_to_expr(value)
86 if isinstance(value, numbers.Number):
87 value = R.const(value)
88
89 if isinstance(value, relax.Expr):
90 var = R.emit(value, anno_sinfo)
91 elif isinstance(value, MatchCastPair):
92 if anno_sinfo is not None and not tvm_ffi.structural_equal(anno_sinfo, value.struct_info):
93 self.report_error(
94 node, "Cannot specify inconsistent annotation for a match cast pair. "
95 )
96 var = R.emit_match_cast(value.value, value.struct_info)
97 else:
98 return value
99 # raise TypeError(f"Unsupported type {type(value)} in assignment")
100

Callers

nothing calls this directly

Calls 5

convert_to_exprFunction · 0.90
report_errorMethod · 0.80
getMethod · 0.45
nameMethod · 0.45
emitMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…