Skip to content

Conversation

@cortexlfj
Copy link
Contributor

[mrt ir]: opclass and WithParameters

from . import symbol

#from mrt.mir.mhsymbol import MultiHeadSymbol, Graph
class MultiHeadSymbol(dict):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MultiHeadSymbol should inherit from Symbol class, and the Graph is exactly MultiHeadSymbol.

Comment on lines 52 to 72
@property
def args(self):
return self.graph.args
@property
def op_name(self):
return self.graph.op_name
@property
def name(self):
return self.graph.name
@property
def shape(self):
return self.graph.shape
@property
def dtype(self):
return self.graph.dtype
@property
def attrs(self):
return self.graph.attrs
@property
def extra_attrs(self):
return self.graph.extra_attrs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add return type hint

class SymbolBridge: # SymbolManipulator / Pass
graph: Symbol

def __init__(self, symbol: Symbol):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dataclass will create __init__ function automatically, which may lead to conflict and unknown bugs.

don't use dataclass for SymbolBridge and subclass.

args = data['args'] or []
attrs = data['attrs'] or {}
try:
out = cls(*args, name=data['name'], op_name=data['op_name'], extra_attrs=data['extra_attrs'], **attrs)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

subclass like Conv2D don't have op_name parameter, may lead to error.

Since we should have uniform construct API, make subclass like Conv2D to add a op_name parameter, and that sounds more reasonable. But subclass has intrinsic property for op_name, so use assert to check op_name is None or correct name, like:

def __init__(..., op_name=None, ...):
    assert op_name is None or op_name == opns.CONV2D

_format_printer(oattrs))


@dataclass
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since symbol is not the dataclass, the below serialization function: dump_json and load_json may not work. Check these serial functions carefully.


rs_bit = X.from_const_data(X.precision - anno_bit)
X = op.right_shift(X, rs_bit).like(self)
X_op = infer_single(opclass.right_shift(X.graph, rs_bit)).like(self.graph)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since all transformers have been moved to SymbolBridge, the like method in Symbol should also move to transformer. Note that like method is used to create a similar symbol bridge for new symbol, which is identical to from_symbol in SymbolBridge.

@wlt-cortex
Copy link
Member

Does this PR passed for ResNet model? If passed, copy the last inference results below. @cortexlfj

@cortexlfj
Copy link
Contributor Author

cortexlfj commented Dec 1, 2025

Does this PR passed for ResNet model? If passed, copy the last inference results below. @cortexlfj

With 16 calibrate repeats, and 200 eval round:
Iteration: 199 | init: Top1/5: 79.50%,96.00% | sim: Top1/5: 79.50%,96.00% | sim-int-quant: Top1/5: 81.00%,96.50% | sim-int-data: Top1/5: 82.50%,95.50% |

@cortexlfj cortexlfj closed this Dec 1, 2025
@cortexlfj cortexlfj reopened this Dec 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants