Fixed quantization error in modules that use register_buffer
Author: DonggeunYu
Pull request: yes

# 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).
- [x] Did you read the [contributor guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#create-a-pull-request),
      Pull Request section?
- [x] Was this discussed/approved via a Github issue or the [forum](https://discuss.huggingface.co/)? 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](https://github.com/huggingface/transformers/tree/main/docs), and
      [here are tips on formatting docstrings](https://github.com/huggingface/transformers/tree/main/docs#writing-source-documentation).
- [ ] Did you write any new necessary tests?


## Who can review?

- quantization (bitsandbytes, autogpt): @SunMarc and @younesbelkada

Comments:
@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) ==============
~~~

The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_29203). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

> 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...

🥲
https://github.com/huggingface/transformers/pull/29329

@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 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 😊