Skip to content

Commit

Permalink
refactor: use get_submodule in set_module_by_name
Browse files Browse the repository at this point in the history
  • Loading branch information
hayun0909 authored and dacorvo committed Apr 16, 2024
1 parent 910719e commit 0eaad66
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions quanto/quantize.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,9 @@ def set_module_by_name(parent_module, name, child_module):
if len(module_names) == 1:
setattr(parent_module, name, child_module)
else:
next_module = parent_module
for idx in range(len(module_names) - 1):
next_module_name = module_names[idx]
if next_module_name.isnumeric():
next_module = next_module[int(next_module_name)]
else:
next_module = getattr(next_module, next_module_name)
setattr(next_module, module_names[-1], child_module)
parent_module_name = name[: name.rindex(".")]
parent_module = parent_module.get_submodule(parent_module_name)
setattr(parent_module, module_names[-1], child_module)


def quantize(model, modules=None, **kwargs):
Expand Down

0 comments on commit 0eaad66

Please sign in to comment.