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

Fp8 implementation #1100

Merged
merged 11 commits into from
Jan 16, 2025
Merged

Fp8 implementation #1100

merged 11 commits into from
Jan 16, 2025

Conversation

KodiaqQ
Copy link
Contributor

@KodiaqQ KodiaqQ commented Jan 7, 2025

What does this PR do?

  • Introduce new options for the --quant-mode parameter: f8e4m3, f8e5m2.

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?

@KodiaqQ KodiaqQ marked this pull request as ready for review January 8, 2025 12:35
@KodiaqQ
Copy link
Contributor Author

KodiaqQ commented Jan 8, 2025

@nikita-savelyevv, @AlexKoff88, could you please review it?

@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 AlexKoff88 self-assigned this Jan 9, 2025
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!

Comment on lines 710 to 714
if self.quantization_config is not None:
if isinstance(self.quantization_config, OVWeightQuantizationConfig):
self.dtype = self.quantization_config.weight_format
else:
self.dtype = "int8"
else:
self.dtype = dtype
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe this should be changed to:

if self.quantization_config is not None:
    self.dtype = self.quantization_config.weight_format
else:
    self.dtype = dtype

self.assertEqual(len(expected_num_fq_nodes_per_model), len(models))
for i, model in enumerate(models):
actual_num_f_nodes, actual_num_weight_nodes = get_num_quantized_nodes(model)
self.assertEqual(expected_num_fq_nodes_per_model[i], actual_num_f_nodes)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
self.assertEqual(expected_num_fq_nodes_per_model[i], actual_num_f_nodes)
self.assertEqual(expected_num_f_nodes_per_model[i], actual_num_f_nodes)

Comment on lines 677 to 685
if not self.sym:
if self.activation_format != "int8":
raise ValueError(
f"Asymmetric quantization can not be performed in {self.activation_format} activation format."
)
if self.weight_format != "int8":
raise ValueError(
f"Asymmetric quantization can not be performed in {self.weight_format} weight format."
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would suggest to initialize sym as True inside OVQuantizatioConfig constructor if fp8 mode is selected. This option is intended to be used with int data types and does not quite make sense with fp8 data types. Also, this way --sym won't be needed to be specified every time fp8 modes are used.

cc @AlexKoff88

Comment on lines +124 to +125
"llama",
"f8e4m3",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do I understand correctly that applying quantization to language models is the intended use case for fp8 quantization?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know what the purpose of the fp8 usage is. The ticket says about LLM & diffusers at least.

Comment on lines +206 to +207
types_map = {
"i8": "int8",
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

@AlexKoff88
Copy link
Collaborator

@IlyasMoutawwakil, @echarlaix, this PR is ready for your review.

Copy link
Member

@IlyasMoutawwakil IlyasMoutawwakil left a comment

Choose a reason for hiding this comment

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

LGTM

@AlexKoff88
Copy link
Collaborator

@KodiaqQ, can you please resolve conflicts to merge this PR?

@KodiaqQ
Copy link
Contributor Author

KodiaqQ commented Jan 15, 2025

@KodiaqQ, can you please resolve conflicts to merge this PR?

Done.

@IlyasMoutawwakil IlyasMoutawwakil merged commit 878b474 into huggingface:main Jan 16, 2025
22 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.

5 participants