Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed to dump the ignored_scope in quantization more gracefully #2578

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
reformatted how keys with empty value are removed
  • Loading branch information
Viditagarwal7479 committed Mar 21, 2024
commit 00a5e3ee7d6d54b73d6f6f52d0257c8822672803
24 changes: 11 additions & 13 deletions nncf/openvino/rt_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,27 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import Dict, List, Optional
from typing import Dict, List, Optional, Any

import openvino.runtime as ov

from nncf.common.logging import nncf_logger
from nncf.scopes import IgnoredScope
from dataclasses import asdict


def handle_ignored_scope(value: IgnoredScope) -> IgnoredScope:
def exclude_empty_fields(value: Dict[str, Any]) -> Dict[str, Any]:
"""
Dump Ignored Scope parameters more gracefully.
https://github.com/openvinotoolkit/nncf/issues/2564
Remove keys where value is empty and key is `validate`

:param value: IgnoredScope instance, based on the quantization parameters
"""
new_value = IgnoredScope(**(value.__dict__))
new_value.__dict__.pop("validate")
keys = list(new_value.__dict__.keys())
value.pop("validate")
keys = list(value.keys())
for key in keys:
if not new_value.__dict__[key]:
new_value.__dict__.pop(key)
return new_value
if not value[key]:
value.pop(key)
return value


def dump_parameters(
Expand All @@ -50,9 +48,9 @@ def dump_parameters(
for key, value in parameters.items():
# Special condition for composed fields like IgnoredScope
if isinstance(value, IgnoredScope):
value = handle_ignored_scope(value)
if bool(value.__dict__):
dump_parameters(model, value.__dict__, algo_name, [key])
value = exclude_empty_fields(asdict(value))
if bool(value):
dump_parameters(model, value, algo_name, [key])
continue
else:
# The default value in case empty ignored_scope parameter passed
Expand Down
Loading