Skip to content

Fixed quantization error in modules that use register_buffer#29203

Closed
DonggeunYu wants to merge 14 commits intohuggingface:mainfrom
DonggeunYu:main
Closed

Fixed quantization error in modules that use register_buffer#29203
DonggeunYu wants to merge 14 commits intohuggingface:mainfrom
DonggeunYu:main

Conversation

@DonggeunYu
Copy link
Copy Markdown
Contributor

What does this PR do?

Fixed quantization error in modules that use register_buffer.
When using self.register_buffer, it is included in state_dict, but not in _parameters, which is why first validate that tensor_name exists in _parameters before searching for it by tensor_name in _parameters.

Fixes #29201

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

Who can review?

Copy link
Copy Markdown
Contributor

@younesbelkada younesbelkada left a comment

Choose a reason for hiding this comment

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

Great catch ! can you confirm the 4bit tests pass for you ?

RUN_SLOW=1 pytest tests/quantization/bnb/test_4bit.py

If they pass I think we can safely merge the PR, depending on your hardware you might get some failure with respect to generated texts, for that you can simply check if you get the same failures between main branch and yours

@DonggeunYu
Copy link
Copy Markdown
Contributor Author

DonggeunYu commented Feb 22, 2024

@younesbelkada

RUN_SLOW=1 pytest tests/quantization/bnb/test_4bit.py on my branch output:

=================================== short test summary info ===================================
FAILED tests/quantization/bnb/test_4bit.py::BaseSerializationTest::test_serialization - ValueError: Supplied state dict for model.decoder.layers.0.fc1.weight does not contain `bi...
FAILED tests/quantization/bnb/test_4bit.py::ExtendedSerializationTest::test_fp4_double_safe - ValueError: Supplied state dict for model.decoder.layers.0.fc1.weight does not contain `bi...
FAILED tests/quantization/bnb/test_4bit.py::ExtendedSerializationTest::test_fp4_double_unsafe - ValueError: Supplied state dict for model.decoder.layers.0.self_attn.k_proj.weight does no...
FAILED tests/quantization/bnb/test_4bit.py::ExtendedSerializationTest::test_fp4_single_safe - ValueError: Supplied state dict for model.decoder.layers.0.fc1.weight does not contain `bi...
FAILED tests/quantization/bnb/test_4bit.py::ExtendedSerializationTest::test_fp4_single_unsafe - ValueError: Supplied state dict for model.decoder.layers.0.self_attn.k_proj.weight does no...
FAILED tests/quantization/bnb/test_4bit.py::ExtendedSerializationTest::test_nf4_double_unsafe - ValueError: Supplied state dict for model.decoder.layers.0.self_attn.k_proj.weight does no...
FAILED tests/quantization/bnb/test_4bit.py::ExtendedSerializationTest::test_nf4_single_safe - ValueError: Supplied state dict for model.decoder.layers.0.fc1.weight does not contain `bi...
FAILED tests/quantization/bnb/test_4bit.py::ExtendedSerializationTest::test_nf4_single_unsafe - ValueError: Supplied state dict for model.decoder.layers.0.self_attn.k_proj.weight does no...
FAILED tests/quantization/bnb/test_4bit.py::ExtendedSerializationTest::test_serialization - ValueError: Supplied state dict for model.decoder.layers.0.fc1.weight does not contain `bi...
FAILED tests/quantization/bnb/test_4bit.py::BloomSerializationTest::test_serialization - ValueError: Supplied state dict for transformer.h.0.mlp.dense_4h_to_h.weight does not cont...
FAILED tests/quantization/bnb/test_4bit.py::GPTSerializationTest::test_serialization - ValueError: Supplied state dict for transformer.h.0.attn.c_attn.weight does not contain `b...
============= 11 failed, 27 passed, 1 skipped, 29 warnings in 1628.99s (0:27:08) ==============

Main branch output:

=================================== short test summary info ===================================
FAILED tests/quantization/bnb/test_4bit.py::BaseSerializationTest::test_serialization - ValueError: Supplied state dict for model.decoder.layers.0.fc1.weight does not contain `bi...
FAILED tests/quantization/bnb/test_4bit.py::ExtendedSerializationTest::test_fp4_double_safe - ValueError: Supplied state dict for model.decoder.layers.0.fc1.weight does not contain `bi...
FAILED tests/quantization/bnb/test_4bit.py::ExtendedSerializationTest::test_fp4_double_unsafe - ValueError: Supplied state dict for model.decoder.layers.0.self_attn.k_proj.weight does no...
FAILED tests/quantization/bnb/test_4bit.py::ExtendedSerializationTest::test_fp4_single_safe - ValueError: Supplied state dict for model.decoder.layers.0.fc1.weight does not contain `bi...
FAILED tests/quantization/bnb/test_4bit.py::ExtendedSerializationTest::test_fp4_single_unsafe - ValueError: Supplied state dict for model.decoder.layers.0.self_attn.k_proj.weight does no...
FAILED tests/quantization/bnb/test_4bit.py::ExtendedSerializationTest::test_nf4_double_unsafe - ValueError: Supplied state dict for model.decoder.layers.0.self_attn.k_proj.weight does no...
FAILED tests/quantization/bnb/test_4bit.py::ExtendedSerializationTest::test_nf4_single_safe - ValueError: Supplied state dict for model.decoder.layers.0.fc1.weight does not contain `bi...
FAILED tests/quantization/bnb/test_4bit.py::ExtendedSerializationTest::test_nf4_single_unsafe - ValueError: Supplied state dict for model.decoder.layers.0.self_attn.k_proj.weight does no...
FAILED tests/quantization/bnb/test_4bit.py::ExtendedSerializationTest::test_serialization - ValueError: Supplied state dict for model.decoder.layers.0.fc1.weight does not contain `bi...
FAILED tests/quantization/bnb/test_4bit.py::BloomSerializationTest::test_serialization - ValueError: Supplied state dict for transformer.h.0.mlp.dense_4h_to_h.weight does not cont...
FAILED tests/quantization/bnb/test_4bit.py::GPTSerializationTest::test_serialization - ValueError: Supplied state dict for transformer.h.0.attn.c_attn.weight does not contain `b...
============= 11 failed, 27 passed, 1 skipped, 29 warnings in 1102.77s (0:18:22) ==============

@SunMarc SunMarc self-requested a review February 22, 2024 16:53
Copy link
Copy Markdown
Member

@SunMarc SunMarc left a comment

Choose a reason for hiding this comment

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

LGTM !

Copy link
Copy Markdown
Contributor

@younesbelkada younesbelkada left a comment

Choose a reason for hiding this comment

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

Thanks again @DonggeunYu !
Just to confirm one last point, could your re-run the bnb tests with bitsandbytes==0.42.0 ?

@HuggingFaceDocBuilderDev
Copy link
Copy Markdown

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.

@DonggeunYu
Copy link
Copy Markdown
Contributor Author

DonggeunYu commented Feb 23, 2024

Thanks again @DonggeunYu ! Just to confirm one last point, could your re-run the bnb tests with bitsandbytes==0.42.0 ?

@younesbelkada
But, the same 11 failed...

@DonggeunYu
Copy link
Copy Markdown
Contributor Author

🥲
#29329

@amyeroberts
Copy link
Copy Markdown
Contributor

@DonggeunYu Am I correct in understanding this PR was superceded by #29329? If so, apologies for the delay in reviewing this, and we should close this PR. Please don't hesitate to ping me on a PR if there's a delay in response - thee's a lot of notifications and sometimes they slip through the cracks.

@DonggeunYu
Copy link
Copy Markdown
Contributor Author

@DonggeunYu Am I correct in understanding this PR was superceded by #29329? If so, apologies for the delay in reviewing this, and we should close this PR. Please don't hesitate to ping me on a PR if there's a delay in response - thee's a lot of notifications and sometimes they slip through the cracks.

Yes, that's right. I understand. Thank you 😊

@DonggeunYu DonggeunYu closed this Mar 8, 2024
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.

Quantization Error: register_buffer is not in module_parameters.

5 participants