Feat (utils): replace weights with quantized ones - #1505
Merged
Conversation
pablomlago
requested changes
May 13, 2026
| @staticmethod | ||
| def _reset_quantizer(proxy) -> None: | ||
| """Switch a weight quant proxy from LearnedRound back to standard Round.""" | ||
| reinit_on_state_dict = config.REINIT_ON_STATE_DICT_LOAD |
Collaborator
There was a problem hiding this comment.
This pattern of overriding values in config and then restoring to the original values appears multiple times. Can we extract this common functionality? E.g.:
from contextlib import contextmanager
@contextmanager
def override_config(**overrides):
old = {}
try:
for k, v in overrides.items():
old[k] = getattr(config, k)
setattr(config, k, v)
yield
finally:
for k, v in old.items():
setattr(config, k, v)
and then use it like:
with override_config(
REINIT_ON_STATE_DICT_LOAD=False,
IGNORE_MISSING_KEYS=True,
):
Collaborator
Author
There was a problem hiding this comment.
I'm going to open this as an issue and do it specifically in its own PR
pablomlago
reviewed
Jun 10, 2026
pablomlago
approved these changes
Jun 10, 2026
pablomlago
left a comment
Collaborator
There was a problem hiding this comment.
LGTM, feel free to ignore the following change.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reason for this PR
In certain instances, like learned round, the weight tensors has extra parameters attached to it that could make export somewhat complicated.
Changes Made in this PR
We perform a destructive replacement of the original weight tensor with its quantized counterparts. This allows for easier exports in many scenarios.
There is an optional flag to keeep track of the original weights.
After merging, we reset the quantizers, including setting rounding mode to round, which is what is most commonly supported during export process.
What is missing:
Testing Summary
New tests added.