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

Introduce support for NF4 data type for OV weight compression #988

Merged
merged 6 commits into from
Nov 13, 2024

Conversation

l-bat
Copy link
Contributor

@l-bat l-bat commented Nov 5, 2024

What does this PR do?

  • Added a new possible value for --weight-format CLI argument: nf4.
  • Added a couple of tests for compression with the nf4 data type.

Usage examples:

Optimum CLI:

optimum-cli export openvino -m facebook/opt-125m --task text-generation-with-past --weight-format nf4 ./tmp

Optimum Python API:

model = OVModelForCausalLM.from_pretrained(
    model_id="gpt2",
    export=True,
    quantization_config=OVWeightQuantizationConfig(bits=4, weight_format="nf4"),
)

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you make sure to update the documentation with your changes?
  • Did you write any new necessary tests?

@l-bat
Copy link
Contributor Author

l-bat commented Nov 5, 2024

@AlexKoff88 please take a look

optimum/intel/openvino/configuration.py Outdated Show resolved Hide resolved
Comment on lines 465 to 468
if self.weight_format in "nf4" and self.bits != 4:
raise ValueError(
f"When applying weight compression with 'nf4' weight format the `bits` parameters must be set to 4, but found {self.bits}"
)
Copy link
Collaborator

@nikita-savelyevv nikita-savelyevv Nov 5, 2024

Choose a reason for hiding this comment

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

I believe AWQ and SE are not supported for NF4 on NNCF 2.13, so corresponding checks should be added. GPTQ is supported though. Possibly it could be combined with conditions for mxfp4 above to avoid code duplication.

optimum/intel/openvino/configuration.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@nikita-savelyevv nikita-savelyevv left a comment

Choose a reason for hiding this comment

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

Thanks!

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@AlexKoff88
Copy link
Collaborator

@l-bat, can you fix the style, please?

@AlexKoff88 AlexKoff88 merged commit 41637d0 into huggingface:main Nov 13, 2024
21 of 24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants