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

Weight compression via Lora Correction Algorithm #2816

Merged

Conversation

ljaljushkin
Copy link
Contributor

@ljaljushkin ljaljushkin commented Jul 16, 2024

Changes

Lora Correction algorithm for int4/nf4 weight compression.

Reason for changes

Method for improving accuracy by migrating quantization noise to “learnable” lora adapters.

Related tickets

135863

Tests

  • docstrings, proper names
  • results for phi3 and stablelm2-1.6b on lambada, wikitext
  • job/NNCF/job/manual/job/post_training_weight_compression/144/
    image
    image
    image

image

@github-actions github-actions bot added NNCF PT Pull requests that updates NNCF PyTorch NNCF OpenVINO Pull requests that updates NNCF OpenVINO NNCF PTQ Pull requests that updates NNCF PTQ labels Jul 16, 2024
@openvino-nncf-ci openvino-nncf-ci added the API Public API-impacting changes label Jul 16, 2024
@ljaljushkin ljaljushkin force-pushed the nl/lora_correct_prod_squash branch 2 times, most recently from a355df6 to 24b1f9e Compare July 22, 2024 15:45
@github-actions github-actions bot added the documentation Improvements or additions to documentation label Jul 22, 2024
@ljaljushkin ljaljushkin marked this pull request as ready for review July 22, 2024 15:50
@ljaljushkin ljaljushkin requested a review from a team as a code owner July 22, 2024 15:50
for i in range(n_iters):
VX = Vr @ X
if not w_regularization:
sol = fns.linalg.lstsq(fns.transpose(VX), fns.transpose(dY))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

driver="gelsy" ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, corrected

if not w_regularization:
sol = fns.linalg.lstsq(fns.transpose(X), fns.transpose(dYU), driver="gelsy")
else:
Ind = fns.eye(Vr.shape[1], backend=Vr.backend, dtype=Vr.dtype)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be also worth to add some math formulas in comment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, also refactored to avoid too many transpose. please take a look at it as well

@ljaljushkin ljaljushkin force-pushed the nl/lora_correct_prod_squash branch from 470fbd8 to a3b26c7 Compare August 19, 2024 18:17
for i in range(n_gs):
offset = i * gs
denum = fns.sum(s[offset : offset + gs])
s[offset : offset + gs] = s[offset : offset + gs] / denum
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can skip first normalization

Copy link
Contributor

@alexsu52 alexsu52 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, please consider taking my comments into consideration

nncf/quantization/advanced_parameters.py Outdated Show resolved Hide resolved
nncf/quantization/quantize_model.py Outdated Show resolved Hide resolved
@ljaljushkin ljaljushkin requested a review from alexsu52 August 27, 2024 15:41
@ljaljushkin
Copy link
Contributor Author

Latest build of conformance test with lora test case:
job/NNCF/job/manual/job/post_training_weight_compression/150

@alexsu52 alexsu52 merged commit 417c2a1 into openvinotoolkit:develop Aug 28, 2024
13 checks passed
ljaljushkin added a commit to KodiaqQ/nncf that referenced this pull request Sep 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Public API-impacting changes documentation Improvements or additions to documentation NNCF OpenVINO Pull requests that updates NNCF OpenVINO NNCF PT Pull requests that updates NNCF PyTorch NNCF PTQ Pull requests that updates NNCF PTQ
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants