Skip to content

Commit d737c0e

Browse files
committed
Fix has not attribute
Fix: fms_mo/quant/quantizers.py:3898: error: Item "None" of "Parameter | None" has no attribute "fill_" [union-attr] fms_mo/quant/quantizers.py:3963: error: Item "float" of "Any | float" has no attribute "round" [union-attr] fms_mo/quant/quantizers.py:5392: error: Module has no attribute "float8_e5m2G" [attr-defined] fms_mo/custom_ext_kernels/utils.py:77: error: Module has no attribute "custom_op" [attr-defined] fms_mo/custom_ext_kernels/utils.py:79: error: Module has no attribute "register_kernel" [attr-defined] fms_mo/custom_ext_kernels/utils.py:80: error: Module has no attribute "register_fake" [attr-defined] fms_mo/utils/torchscript_utils.py:182: error: Item "None" of "Node | None" has no attribute "inputs" [union-attr] fms_mo/utils/torchscript_utils.py:184: error: Item "None" of "Node | None" has no attribute "outputs" [union-attr] fms_mo/utils/torchscript_utils.py:204: error: "Node" has no attribute "name" [attr-defined] fms_mo/utils/torchscript_utils.py:204: error: "Node" has no attribute "obj" [attr-defined] fms_mo/utils/torchscript_utils.py:205: error: "Node" has no attribute "name" [attr-defined] fms_mo/utils/torchscript_utils.py:207: error: "Node" has no attribute "name" [attr-defined] fms_mo/utils/torchscript_utils.py:209: error: "Node" has no attribute "name" [attr-defined] fms_mo/utils/torchscript_utils.py:212: error: "Node" has no attribute "Op" [attr-defined] fms_mo/utils/torchscript_utils.py:214: error: "Node" has no attribute "unpackIdx" [attr-defined] fms_mo/utils/torchscript_utils.py:216: error: "Node" has no attribute "lineno" [attr-defined] fms_mo/utils/torchscript_utils.py:217: error: "Node" has no attribute "operator" [attr-defined] fms_mo/utils/torchscript_utils.py:219: error: "Node" has no attribute "parents" [attr-defined] fms_mo/utils/torchscript_utils.py:220: error: "Node" has no attribute "parents_ptr" [attr-defined] fms_mo/utils/torchscript_utils.py:221: error: "Node" has no attribute "scope" [attr-defined] fms_mo/utils/torchscript_utils.py:222: error: "Node" has no attribute "modname" [attr-defined] fms_mo/utils/torchscript_utils.py:223: error: "Node" has no attribute "children" [attr-defined] fms_mo/utils/torchscript_utils.py:224: error: "Node" has no attribute "children_ptr" [attr-defined] fms_mo/utils/torchscript_utils.py:225: error: "Node" has no attribute "TSparents" [attr-defined] fms_mo/utils/torchscript_utils.py:226: error: "Node" has no attribute "TSoutputs" [attr-defined] fms_mo/utils/torchscript_utils.py:228: error: "Node" has no attribute "name" [attr-defined] fms_mo/calib.py:485: error: Item "None" of "FrameType | None" has no attribute "f_code" [union-attr] fms_mo/quant/ptq.py:2626: error: Item "None" of "Tensor | None" has no attribute "zero_" [union-attr] fms_mo/quant/ptq.py:2627: error: Item "None" of "Tensor | None" has no attribute "fill_" [union-attr] Signed-off-by: Martin Hickey <[email protected]>
1 parent 7c0fc69 commit d737c0e

File tree

5 files changed

+41
-29
lines changed

5 files changed

+41
-29
lines changed

fms_mo/calib.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,8 @@ def qmodel_calib(
482482
return model
483483

484484
DPorDDPdevices = None
485-
if "qmodel_prep" not in sys._getframe().f_back.f_code.co_name:
485+
f_back = sys._getframe().f_back
486+
if f_back and "qmodel_prep" not in f_back.f_code.co_name:
486487
model.to(currDev)
487488
qcfg["wasDPmodel"] = qcfg.get("wasDPmodel", isinstance(model, nn.DataParallel))
488489
qcfg["wasDDPmodel"] = qcfg.get(

fms_mo/custom_ext_kernels/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@
7474
# Third Party
7575
import torch.library as lib
7676

77-
reg_op = partial(lib.custom_op, mutates_args=())
77+
reg_op = partial(lib.custom_op, mutates_args=()) # type: ignore[attr-defined]
7878
reg_op_func = lib.define # NOTE this is func, not decorator
79-
kernel_impl = lib.register_kernel
80-
reg_fake = lib.register_fake
79+
kernel_impl = lib.register_kernel # type: ignore[attr-defined]
80+
reg_fake = lib.register_fake # type: ignore[attr-defined]
8181

8282
else:
8383
raise RuntimeError("Custom Op registration only works for >PT2.1")

fms_mo/quant/ptq.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2623,8 +2623,10 @@ def reset_bn(module: nn.BatchNorm2d):
26232623
Function not currently used.
26242624
"""
26252625
if module.track_running_stats:
2626-
module.running_mean.zero_()
2627-
module.running_var.fill_(1 - module.eps)
2626+
if running_mean := module.running_mean:
2627+
running_mean.zero_()
2628+
if running_var := module.running_var:
2629+
running_var.fill_(1 - module.eps)
26282630
# we do not reset numer of tracked batches here
26292631
if module.affine:
26302632
nn.init.ones_(module.weight)

fms_mo/quant/quantizers.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3895,7 +3895,8 @@ def forward(self, x: torch.Tensor):
38953895
self.delta = torch.nn.Parameter(delta)
38963896
else:
38973897
delta, zero_point = self.init_quantization_scale(x, self.channel_wise)
3898-
self.delta.fill_(delta)
3898+
if self_data := self.delta:
3899+
self_data.fill_(delta)
38993900
self.zero_point.fill_(zero_point)
39003901
self.inited = True
39013902

@@ -3960,7 +3961,7 @@ def init_quantization_scale(self, x: torch.Tensor, channel_wise: bool = False):
39603961
if score < best_score:
39613962
best_score = score
39623963
delta = (new_max - new_min) / (2**self.n_bits - 1)
3963-
zero_point = (-new_min / delta).round()
3964+
zero_point = (-new_min / delta).round() # type: ignore[union-attr]
39643965
else:
39653966
raise NotImplementedError
39663967

@@ -5389,7 +5390,7 @@ def __init__(
53895390
if "e4m3" in q_mode:
53905391
self.float8_dtype = torch.float8_e4m3fn
53915392
elif "e5m2" in q_mode:
5392-
self.float8_dtype = torch.float8_e5m2G
5393+
self.float8_dtype = torch.float8_e5m2
53935394
else:
53945395
raise ValueError("FP8 only supports e4m3 and e5m2")
53955396
self.emulate = emulate

fms_mo/utils/torchscript_utils.py

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,14 @@ def __init__(self, node_input, dictionary_of_nodes: dict):
179179
)
180180
operator, operands = parse_operation(op_str)
181181
if "aten::_conv" in op_str:
182-
self.ch_in = list(native_torchscript_node.inputs())[0].type().sizes()
183-
# NOTE: Needed for finding shortcut convolutions later
184-
self.ch_out = list(native_torchscript_node.outputs())[0].type().sizes()
182+
if native_torchscript_node:
183+
self.ch_in = (
184+
list(native_torchscript_node.inputs())[0].type().sizes()
185+
)
186+
# NOTE: Needed for finding shortcut convolutions later
187+
self.ch_out = (
188+
list(native_torchscript_node.outputs())[0].type().sizes()
189+
)
185190
else:
186191
node_def = node_input_repr
187192
op_str, operator, operands = None, None, None
@@ -201,31 +206,34 @@ def __init__(self, node_input, dictionary_of_nodes: dict):
201206
working_str = node_input_repr[start_index:end_index]
202207
start_index = end_index + 2
203208

204-
node_instance.name, node_instance.obj = working_str.split(" : ")
205-
node_instance.name = node_instance.name.strip()
209+
# pylint: disable=line-too-long
210+
node_instance.name, node_instance.obj = working_str.split(" : ") # type: ignore[attr-defined]
211+
node_instance.name = node_instance.name.strip() # type: ignore[attr-defined]
206212
if native_torchscript_outputs:
207-
if node_instance.name not in native_torchscript_outputs:
213+
# pylint: disable=line-too-long
214+
if node_instance.name not in native_torchscript_outputs: # type: ignore[attr-defined]
215+
# pylint: disable=line-too-long
208216
logger.error(
209-
f"Node def {node_instance.name} not in nativeTSoutputs "
217+
f"Node def {node_instance.name} not in nativeTSoutputs " # type: ignore[attr-defined]
210218
f"{native_torchscript_outputs}"
211219
)
212-
node_instance.Op = op_str
220+
node_instance.Op = op_str # type: ignore[attr-defined]
213221
if node_def_in_one_line > 1:
214-
node_instance.unpackIdx = node_index
222+
node_instance.unpackIdx = node_index # type: ignore[attr-defined]
215223
if line_number:
216-
node_instance.lineno = line_number
217-
node_instance.operator = operator
224+
node_instance.lineno = line_number # type: ignore[attr-defined]
225+
node_instance.operator = operator # type: ignore[attr-defined]
218226
# This is the name of parents, not the pointer to the parent nodes
219-
node_instance.parents = operands
220-
node_instance.parents_ptr = []
221-
node_instance.scope = scope_repr
222-
node_instance.modname = module_name
223-
node_instance.children = []
224-
node_instance.children_ptr = []
225-
node_instance.TSparents = native_torchscript_parents
226-
node_instance.TSoutputs = native_torchscript_outputs
227+
node_instance.parents = operands # type: ignore[attr-defined]
228+
node_instance.parents_ptr = [] # type: ignore[attr-defined]
229+
node_instance.scope = scope_repr # type: ignore[attr-defined]
230+
node_instance.modname = module_name # type: ignore[attr-defined]
231+
node_instance.children = [] # type: ignore[attr-defined]
232+
node_instance.children_ptr = [] # type: ignore[attr-defined]
233+
node_instance.TSparents = native_torchscript_parents # type: ignore[attr-defined]
234+
node_instance.TSoutputs = native_torchscript_outputs # type: ignore[attr-defined]
227235
# graph.dictionary_of_nodes will keep a record of all the nodes
228-
dictionary_of_nodes[node_instance.name] = node_instance
236+
dictionary_of_nodes[node_instance.name] = node_instance # type: ignore[attr-defined]
229237

230238
def __repr__(self):
231239
return f"{self.name} "

0 commit comments

Comments
 (0)