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

[Core] Change 8-bit serialization weight format format #1164

Merged
merged 10 commits into from
Apr 10, 2024

Conversation

younesbelkada
Copy link
Collaborator

@younesbelkada younesbelkada commented Apr 4, 2024

Currently for 8-bit layers the weight format are saved in pure str in the state dict, which is no longer supported in transformers

This PR should be totally backward compatible with previous 8-bit weights pushed on the Hub

cc @Titus-von-Koeller @TimDettmers @SunMarc

Copy link

github-actions bot commented Apr 4, 2024

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.

@Titus-von-Koeller
Copy link
Collaborator

@younesbelkada Thanks a lot for your work on this ❤️

I'm waiting with my final review and merge until you ping me, as you I remember you saying this is potentially still in flux.

@younesbelkada
Copy link
Collaborator Author

Thanks @Titus-von-Koeller ! yes let me run few other tests and ping you here

bitsandbytes/nn/modules.py Outdated Show resolved Hide resolved
bitsandbytes/utils.py Show resolved Hide resolved
bitsandbytes/nn/modules.py Outdated Show resolved Hide resolved
Comment on lines 622 to 633
if isinstance(weight_format, torch.Tensor):
weight_format = weight_format.item()

# For new weights format storage type we expclicitly check
# if weights_format is on the mapping
if isinstance(weight_format, int) and weight_format not in LINEAR_8BIT_WEIGHTS_FORMAT_MAPPING.values():
raise ValueError(f"Expected supported weight format - got {weight_format}")
elif isinstance(weight_format, int) and weight_format in LINEAR_8BIT_WEIGHTS_FORMAT_MAPPING.values():
weight_format = dict(
zip(LINEAR_8BIT_WEIGHTS_FORMAT_MAPPING.values(), LINEAR_8BIT_WEIGHTS_FORMAT_MAPPING.keys())
)[weight_format]

Copy link
Contributor

Choose a reason for hiding this comment

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

622..633 looks like it should be a free function (determine_weight_format() or similar).

@akx
Copy link
Contributor

akx commented Apr 9, 2024

There should probably be at least some tests for this in this repo too.

@Titus-von-Koeller
Copy link
Collaborator

Thanks @akx for the review! Good catches. I agree that these changes would make sense.

@younesbelkada In case you're too busy tmr, I can wrap this up for you and come up with some simple tests. Anyways, we can release this by Thursday, no problem, so that we're aligned with the Transformers release.

For now, instead of this, I'll focus on some multi-backend related topics as these are critical to be well prepared for the meeting on that topic tmr evening.

younesbelkada and others added 6 commits April 10, 2024 10:36
Co-authored-by: Aarni Koskela <akx@iki.fi>
Co-authored-by: Aarni Koskela <akx@iki.fi>
Co-authored-by: Aarni Koskela <akx@iki.fi>
@Titus-von-Koeller Titus-von-Koeller merged commit 7449d71 into main Apr 10, 2024
35 checks passed
@Titus-von-Koeller Titus-von-Koeller deleted the fix-8bit-serialization branch April 10, 2024 08:50
Comment on lines +629 to +634
# For new weights format storage type, we explicitly check
# if weights_format is on the mapping
if isinstance(weight_format, int) and weight_format not in INVERSE_LINEAR_8BIT_WEIGHTS_FORMAT_MAPPING:
raise ValueError(f"Expected supported weight format - got {weight_format}")
elif isinstance(weight_format, int) and weight_format in INVERSE_LINEAR_8BIT_WEIGHTS_FORMAT_MAPPING:
weight_format = INVERSE_LINEAR_8BIT_WEIGHTS_FORMAT_MAPPING[weight_format]
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't seem to make much sense? Why is the isinstance() check repeated?

Comment on lines +626 to +635
if isinstance(weight_format, torch.Tensor):
weight_format = weight_format.item()

# For new weights format storage type, we explicitly check
# if weights_format is on the mapping
if isinstance(weight_format, int) and weight_format not in INVERSE_LINEAR_8BIT_WEIGHTS_FORMAT_MAPPING:
raise ValueError(f"Expected supported weight format - got {weight_format}")
elif isinstance(weight_format, int) and weight_format in INVERSE_LINEAR_8BIT_WEIGHTS_FORMAT_MAPPING:
weight_format = INVERSE_LINEAR_8BIT_WEIGHTS_FORMAT_MAPPING[weight_format]

Copy link
Contributor

Choose a reason for hiding this comment

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

As said before, this should probably be a free-standing helper function.

naqi pushed a commit to naqi/bitsandbytes that referenced this pull request Apr 16, 2024
…s-foundation#1164)

* change 8-bit serialization weight format format

* precimmit

* pre-commit

* fix

* Update bitsandbytes/nn/modules.py

Co-authored-by: Aarni Koskela <akx@iki.fi>

* Update bitsandbytes/nn/modules.py

Co-authored-by: Aarni Koskela <akx@iki.fi>

* Update bitsandbytes/utils.py

Co-authored-by: Aarni Koskela <akx@iki.fi>

* address feedback

* lint

---------

Co-authored-by: Aarni Koskela <akx@iki.fi>
matthewdouglas pushed a commit to matthewdouglas/bitsandbytes that referenced this pull request Oct 28, 2024
…s-foundation#1164)

* change 8-bit serialization weight format format

* precimmit

* pre-commit

* fix

* Update bitsandbytes/nn/modules.py

Co-authored-by: Aarni Koskela <akx@iki.fi>

* Update bitsandbytes/nn/modules.py

Co-authored-by: Aarni Koskela <akx@iki.fi>

* Update bitsandbytes/utils.py

Co-authored-by: Aarni Koskela <akx@iki.fi>

* address feedback

* lint

---------

Co-authored-by: Aarni Koskela <akx@iki.fi>
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.

3 participants