Skip to content

Commit

Permalink
Fix incompatible types in assignment
Browse files Browse the repository at this point in the history
Fix:

ms_mo/quant/quantizers.py:3933: error: Incompatible types in assignment (expression has type "int | float", variable has type "Tensor")  [assignment]
fms_mo/quant/quantizers.py:3945: error: Incompatible types in assignment (expression has type "float", variable has type "Tensor | None")  [assignment]
fms_mo/quant/quantizers.py:3947: error: Incompatible types in assignment (expression has type "Any | int", variable has type "Tensor | None")  [assignment]
fms_mo/quant/quantizers.py:4190: error: Incompatible types in assignment (expression has type "Parameter", variable has type "None")  [assignment]
fms_mo/quant/quantizers.py:4196: error: Incompatible types in assignment (expression has type "Size", variable has type "list[Any]")  [assignment]
fms_mo/modules/linear.py:1341: error: Incompatible types in assignment (expression has type "tuple[int, int]", variable has type "tuple[int, int, int]")  [assignment]
fms_mo/utils/torchscript_utils.py:58: error: Incompatible types in assignment (expression has type "list[str] | None", variable has type "list[str]")  [assignment]
fms_mo/utils/qconfig_utils.py:167: error: Incompatible types in assignment (expression has type "int", target has type "dict[type, dict[str, type]]")  [assignment]
fms_mo/utils/qconfig_utils.py:168: error: Incompatible types in assignment (expression has type "int", target has type "dict[type, dict[str, type]]")  [assignment]
fms_mo/utils/qconfig_utils.py:169: error: Incompatible types in assignment (expression has type "str", target has type "dict[type, dict[str, type]]")  [assignment]
fms_mo/utils/qconfig_utils.py:170: error: Incompatible types in assignment (expression has type "str", target has type "dict[type, dict[str, type]]")  [assignment]
fms_mo/utils/qconfig_utils.py:171: error: Incompatible types in assignment (expression has type "None", target has type "dict[type, dict[str, type]]")  [assignment]
fms_mo/utils/qconfig_utils.py:172: error: Incompatible types in assignment (expression has type "None", target has type "dict[type, dict[str, type]]")  [assignment]
fms_mo/utils/qconfig_utils.py:173: error: Incompatible types in assignment (expression has type "int", target has type "dict[type, dict[str, type]]")  [assignment]
fms_mo/utils/qconfig_utils.py:174: error: Incompatible types in assignment (expression has type "int", target has type "dict[type, dict[str, type]]")  [assignment]
fms_mo/utils/qconfig_utils.py:175: error: Incompatible types in assignment (expression has type "str", target has type "dict[type, dict[str, type]]")  [assignment]
fms_mo/utils/qconfig_utils.py:176: error: Incompatible types in assignment (expression has type "str", target has type "dict[type, dict[str, type]]")  [assignment]
fms_mo/utils/qconfig_utils.py:178: error: Incompatible types in assignment (expression has type "str", target has type "dict[type, dict[str, type]]")  [assignment]
fms_mo/utils/qconfig_utils.py:179: error: Incompatible types in assignment (expression has type "str", target has type "dict[type, dict[str, type]]")  [assignment]
fms_mo/utils/qconfig_utils.py:180: error: Incompatible types in assignment (expression has type "tuple[float, float]", target has type "dict[type, dict[str, type]]")  [assignment]
fms_mo/utils/qconfig_utils.py:183: error: Incompatible types in assignment (expression has type "list[Never]", target has type "dict[type, dict[str, type]]")  [assignment]
fms_mo/utils/qconfig_utils.py:184: error: Incompatible types in assignment (expression has type "list[Never]", target has type "dict[type, dict[str, type]]")  [assignment]
fms_mo/utils/qconfig_utils.py:188: error: Incompatible types in assignment (expression has type "None", target has type "dict[type, dict[str, type]]")  [assignment]
fms_mo/utils/qconfig_utils.py:189: error: Incompatible types in assignment (expression has type "None", target has type "dict[type, dict[str, type]]")  [assignment]
fms_mo/utils/qconfig_utils.py:190: error: Incompatible types in assignment (expression has type "None", target has type "dict[type, dict[str, type]]")  [assignment]
fms_mo/utils/qconfig_utils.py:191: error: Incompatible types in assignment (expression has type "str", target has type "dict[type, dict[str, type]]")  [assignment]
fms_mo/utils/qconfig_utils.py:192: error: Incompatible types in assignment (expression has type "str", target has type "dict[type, dict[str, type]]")  [assignment]
fms_mo/utils/qconfig_utils.py:193: error: Incompatible types in assignment (expression has type "str", target has type "dict[type, dict[str, type]]")  [assignment]
fms_mo/utils/qconfig_utils.py:194: error: Incompatible types in assignment (expression has type "str", target has type "dict[type, dict[str, type]]")  [assignment]
fms_mo/utils/qconfig_utils.py:195: error: Incompatible types in assignment (expression has type "str", target has type "dict[type, dict[str, type]]")  [assignment]
fms_mo/utils/qconfig_utils.py:196: error: Incompatible types in assignment (expression has type "str", target has type "dict[type, dict[str, type]]")  [assignment]
fms_mo/utils/qconfig_utils.py:197: error: Incompatible types in assignment (expression has type "bool", target has type "dict[type, dict[str, type]]")  [assignment]
fms_mo/utils/qconfig_utils.py:199: error: Incompatible types in assignment (expression has type "None", target has type "dict[type, dict[str, type]]")  [assignment]
fms_mo/utils/qconfig_utils.py:203: error: Incompatible types in assignment (expression has type "None", target has type "dict[type, dict[str, type]]")  [assignment]
fms_mo/utils/qconfig_utils.py:204: error: Incompatible types in assignment (expression has type "None", target has type "dict[type, dict[str, type]]")  [assignment]
fms_mo/utils/qconfig_utils.py:205: error: Incompatible types in assignment (expression has type "None", target has type "dict[type, dict[str, type]]")  [assignment]
fms_mo/utils/qconfig_utils.py:206: error: Incompatible types in assignment (expression has type "None", target has type "dict[type, dict[str, type]]")  [assignment]
fms_mo/utils/qconfig_utils.py:207: error: Incompatible types in assignment (expression has type "None", target has type "dict[type, dict[str, type]]")  [assignment]
fms_mo/utils/qconfig_utils.py:208: error: Incompatible types in assignment (expression has type "str", target has type "dict[type, dict[str, type]]")  [assignment]
fms_mo/utils/qconfig_utils.py:210: error: Incompatible types in assignment (expression has type "bool", target has type "dict[type, dict[str, type]]")  [assignment]
fms_mo/utils/qconfig_utils.py:213: error: Incompatible types in assignment (expression has type "bool", target has type "dict[type, dict[str, type]]")  [assignment]
fms_mo/utils/qconfig_utils.py:214: error: Incompatible types in assignment (expression has type "bool", target has type "dict[type, dict[str, type]]")  [assignment]
fms_mo/utils/qconfig_utils.py:215: error: Incompatible types in assignment (expression has type "bool", target has type "dict[type, dict[str, type]]")  [assignment]
fms_mo/utils/qconfig_utils.py:216: error: Incompatible types in assignment (expression has type "bool", target has type "dict[type, dict[str, type]]")  [assignment]
fms_mo/utils/qconfig_utils.py:217: error: Incompatible types in assignment (expression has type "int", target has type "dict[type, dict[str, type]]")  [assignment]
fms_mo/utils/qconfig_utils.py:218: error: Incompatible types in assignment (expression has type "int", target has type "dict[type, dict[str, type]]")  [assignment]
fms_mo/utils/qconfig_utils.py:219: error: Incompatible types in assignment (expression has type "int", target has type "dict[type, dict[str, type]]")  [assignment]
fms_mo/utils/qconfig_utils.py:220: error: Incompatible types in assignment (expression has type "int", target has type "dict[type, dict[str, type]]")  [assignment]
fms_mo/utils/qconfig_utils.py:221: error: Incompatible types in assignment (expression has type "str", target has type "dict[type, dict[str, type]]")  [assignment]
fms_mo/utils/qconfig_utils.py:222: error: Incompatible types in assignment (expression has type "float", target has type "dict[type, dict[str, type]]")  [assignment]
fms_mo/utils/qconfig_utils.py:223: error: Incompatible types in assignment (expression has type "float", target has type "dict[type, dict[str, type]]")  [assignment]
fms_mo/utils/qconfig_utils.py:224: error: Incompatible types in assignment (expression has type "float", target has type "dict[type, dict[str, type]]")  [assignment]
fms_mo/utils/qconfig_utils.py:226: error: Incompatible types in assignment (expression has type "list[Never]", target has type "dict[type, dict[str, type]]")  [assignment]
fms_mo/utils/qconfig_utils.py:227: error: Incompatible types in assignment (expression has type "bool", target has type "dict[type, dict[str, type]]")  [assignment]
fms_mo/utils/qconfig_utils.py:228: error: Incompatible types in assignment (expression has type "bool", target has type "dict[type, dict[str, type]]")  [assignment]
fms_mo/utils/qconfig_utils.py:229: error: Incompatible types in assignment (expression has type "str", target has type "dict[type, dict[str, type]]")  [assignment]
fms_mo/utils/qconfig_utils.py:230: error: Incompatible types in assignment (expression has type "list[Never]", target has type "dict[type, dict[str, type]]")  [assignment]
fms_mo/utils/qconfig_utils.py:237: error: Incompatible types in assignment (expression has type "None", target has type "dict[type, dict[str, type]]")  [assignment]
fms_mo/utils/qconfig_utils.py:238: error: Incompatible types in assignment (expression has type "int", target has type "dict[type, dict[str, type]]")  [assignment]
fms_mo/utils/qconfig_utils.py:239: error: Incompatible types in assignment (expression has type "int", target has type "dict[type, dict[str, type]]")  [assignment]
fms_mo/utils/qconfig_utils.py:240: error: Incompatible types in assignment (expression has type "int", target has type "dict[type, dict[str, type]]")  [assignment]
fms_mo/utils/qconfig_utils.py:243: error: Incompatible types in assignment (expression has type "bool", target has type "dict[type, dict[str, type]]")  [assignment]
fms_mo/utils/qconfig_utils.py:244: error: Incompatible types in assignment (expression has type "bool", target has type "dict[type, dict[str, type]]")  [assignment]
fms_mo/utils/qconfig_utils.py:245: error: Incompatible types in assignment (expression has type "bool", target has type "dict[type, dict[str, type]]")  [assignment]
fms_mo/utils/qconfig_utils.py:246: error: Incompatible types in assignment (expression has type "bool", target has type "dict[type, dict[str, type]]")  [assignment]
fms_mo/utils/qconfig_utils.py:247: error: Incompatible types in assignment (expression has type "list[Never]", target has type "dict[type, dict[str, type]]")  [assignment]
fms_mo/utils/qconfig_utils.py:248: error: Incompatible types in assignment (expression has type "bool", target has type "dict[type, dict[str, type]]")  [assignment]
fms_mo/utils/qconfig_utils.py:249: error: Incompatible types in assignment (expression has type "bool", target has type "dict[type, dict[str, type]]")  [assignment]
fms_mo/utils/qconfig_utils.py:250: error: Incompatible types in assignment (expression has type "bool", target has type "dict[type, dict[str, type]]")  [assignment]
fms_mo/utils/qconfig_utils.py:251: error: Incompatible types in assignment (expression has type "bool", target has type "dict[type, dict[str, type]]")  [assignment]
fms_mo/utils/qconfig_utils.py:252: error: Incompatible types in assignment (expression has type "bool", target has type "dict[type, dict[str, type]]")  [assignment]
fms_mo/utils/qconfig_utils.py:253: error: Incompatible types in assignment (expression has type "int", target has type "dict[type, dict[str, type]]")  [assignment]
fms_mo/utils/qconfig_utils.py:257: error: Incompatible types in assignment (expression has type "float", target has type "dict[type, dict[str, type]]")  [assignment]
fms_mo/quant/ptq.py:2646: error: Incompatible types in assignment (expression has type "tuple[type[Conv2d], type[Linear]]", variable has type "tuple[type[Conv2d], type[Linear], type[DetQConv2d]]")  [assignment]

Signed-off-by: Martin Hickey <[email protected]>
  • Loading branch information
hickeyma committed Jan 23, 2025
1 parent 7f748af commit 7c0fc69
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion fms_mo/quant/ptq.py
Original file line number Diff line number Diff line change
Expand Up @@ -2643,7 +2643,7 @@ def reset_bn(module: nn.BatchNorm2d):
bn_affine = True # FrozenBN doesn't have .affine property
except:
BNofInteret = (nn.BatchNorm2d, nn.BatchNorm1d)
AbsorbLayers = (nn.Conv2d, nn.Linear)
AbsorbLayers = (nn.Conv2d, nn.Linear) # type: ignore[assignment]


def search_fold_and_remove_bn(model, mod_folded):
Expand Down
2 changes: 1 addition & 1 deletion fms_mo/quant/quantizers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4035,7 +4035,7 @@ def __init__(
self.reset_ReSig_param(multimodal)

self.beta = 2 / 3
self.Wshape: list[Any] = list()
self.Wshape: list[int] = list()
self.reshape2: list[Any] = list()

def forward(self, x):
Expand Down
4 changes: 2 additions & 2 deletions fms_mo/utils/qconfig_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

# Standard
from pathlib import Path
from typing import Any
from typing import Any, Dict
import json
import logging
import os
Expand Down Expand Up @@ -149,7 +149,7 @@ def qconfig_init(recipe: str = None, args: Any = None):
otherwise use constantLR as default
"""

qcfg = {}
qcfg: Dict[str, Any] = {}
# 1. create a dict with default values
qcfg["mapping"] = {
nn.Conv2d: {"from": nn.Conv2d, "to": QConv2d, "otherwise": QConv2d},
Expand Down
3 changes: 2 additions & 1 deletion fms_mo/utils/torchscript_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ def parse_operation(op_str: str):
operands = op_str[
last_open_parenthesis_index + 1 : last_close_parenthesis_index
].split(",")
operands = [operand.strip() for operand in operands] if operands != [""] else None
# pylint: disable=line-too-long
operands = [operand.strip() for operand in operands] if operands != [""] else None # type: ignore[assignment]
return operator, operands


Expand Down

0 comments on commit 7c0fc69

Please sign in to comment.