Skip to content

Conversation

Borda
Copy link
Member

@Borda Borda commented Jun 16, 2025

What does this PR do?

path for new release - update bitsandbytes requirement from <0.43,>=0.42 to >=0.42,<0.47

    @staticmethod
    def quantize(
        int8params: bnb.nn.Int8Params, weight: torch.Tensor, device: Optional[torch.device]
    ) -> bnb.nn.Int8Params:
        device = device or torch.device("cuda")
        if device.type != "cuda":
            raise RuntimeError(f"Unexpected device type: {device.type}")
        # https://github.com/TimDettmers/bitsandbytes/blob/0.41.0/bitsandbytes/nn/modules.py#L291-L302
        B = weight.contiguous().to(device=device, dtype=torch.float16)
        if int8params.has_fp16_weights:
            int8params.data = B
        else:
>           CB, CBt, SCB, SCBt, _ = bnb.functional.double_quant(B)
E           AttributeError: module 'bitsandbytes.functional' has no attribute 'double_quant'. Did you mean: 'int8_double_quant'?

/usr/local/lib/python3.10/dist-packages/lightning/fabric/plugins/precision/bitsandbytes.py:259: AttributeError

ref: https://dev.azure.com/Lightning-AI/lit%20Models/_build/results?buildId=235048&view=logs&jobId=80e425e9-2286-5482-2748-077465d0eec2&j=80e425e9-2286-5482-2748-077465d0eec2&t=c5f621af-a304-5088-cbea-3c82554e8451

Before submitting
  • Was this discussed/agreed via a GitHub issue? (not for typos and docs)
  • Did you read the contributor guideline, Pull Request section?
  • Did you make sure your PR does only one thing, instead of bundling different changes together?
  • Did you make sure to update the documentation with your changes? (if necessary)
  • Did you write any new necessary tests? (not for typos and docs)
  • Did you verify new and existing tests pass locally with your changes?
  • Did you list all the breaking changes introduced by this pull request?
  • Did you update the CHANGELOG? (not for typos, docs, test updates, or minor internal changes/refactors)

PR review

Anyone in the community is welcome to review the PR.
Before you start reviewing, make sure you have read the review guidelines. In short, see the following bullet-list:

Reviewer checklist
  • Is this pull request ready for review? (if not, please submit in draft mode)
  • Check that all items from Before submitting are resolved
  • Make sure the title is self-explanatory and the description concisely explains the PR
  • Add labels and milestones (and optionally projects) to the PR so it can be classified

📚 Documentation preview 📚: https://pytorch-lightning--20911.org.readthedocs.build/en/20911/

cc @justusschock @lantiga

@Borda Borda requested a review from Copilot June 16, 2025 17:17
@github-actions github-actions bot added the fabric lightning.fabric.Fabric label Jun 16, 2025
Copy link
Contributor

github-actions bot commented Jun 16, 2025

⚡ Required checks status: All passing 🟢

Groups summary

🟢 pytorch_lightning: Tests workflow
Check ID Status
pl-cpu-guardian success

These checks are required after the changes to requirements/fabric/strategies.txt, src/lightning/fabric/plugins/precision/bitsandbytes.py, requirements/pytorch/extra.txt.

🟢 pytorch_lightning: Azure GPU
Check ID Status
pytorch-lightning (GPUs) (testing Lightning | latest) success
pytorch-lightning (GPUs) (testing PyTorch | latest) success

These checks are required after the changes to requirements/pytorch/extra.txt, requirements/fabric/strategies.txt, src/lightning/fabric/plugins/precision/bitsandbytes.py.

🟢 pytorch_lightning: Benchmarks
Check ID Status
lightning.Benchmarks success

These checks are required after the changes to requirements/fabric/strategies.txt, requirements/pytorch/extra.txt, src/lightning/fabric/plugins/precision/bitsandbytes.py.

🟢 fabric: Docs
Check ID Status
docs-make (fabric, doctest) success
docs-make (fabric, html) success

These checks are required after the changes to src/lightning/fabric/plugins/precision/bitsandbytes.py, requirements/fabric/strategies.txt.

🟢 pytorch_lightning: Docs
Check ID Status
docs-make (pytorch, doctest) success
docs-make (pytorch, html) success

These checks are required after the changes to requirements/pytorch/extra.txt.

🟢 pytorch_lightning: Docker
Check ID Status
build-cuda (3.10, 2.1.2, 12.1.1) success
build-cuda (3.11, 2.2.2, 12.1.1) success
build-cuda (3.11, 2.3.1, 12.1.1) success
build-cuda (3.11, 2.4.1, 12.1.1) success
build-cuda (3.12, 2.5.1, 12.1.1) success
build-cuda (3.12, 2.6.0, 12.4.1) success
build-pl (3.10, 2.1, 12.1.1) success
build-pl (3.11, 2.2, 12.1.1) success
build-pl (3.11, 2.3, 12.1.1) success
build-pl (3.11, 2.4, 12.1.1) success
build-pl (3.12, 2.5, 12.1.1) success
build-pl (3.12, 2.6, 12.4.1) success
build-pl (3.12, 2.7, 12.6.3, true) success

These checks are required after the changes to requirements/pytorch/extra.txt, requirements/fabric/strategies.txt.

🟢 lightning_fabric: CPU workflow
Check ID Status
fabric-cpu-guardian success

These checks are required after the changes to requirements/fabric/strategies.txt, src/lightning/fabric/plugins/precision/bitsandbytes.py.

🟢 lightning_fabric: Azure GPU
Check ID Status
lightning-fabric (GPUs) (testing Fabric | latest) success
lightning-fabric (GPUs) (testing Lightning | latest) success

These checks are required after the changes to requirements/fabric/strategies.txt, src/lightning/fabric/plugins/precision/bitsandbytes.py.

🟢 mypy
Check ID Status
mypy success

These checks are required after the changes to requirements/fabric/strategies.txt, requirements/pytorch/extra.txt, src/lightning/fabric/plugins/precision/bitsandbytes.py.

🟢 install
Check ID Status
install-pkg-guardian success

These checks are required after the changes to src/lightning/fabric/plugins/precision/bitsandbytes.py, requirements/fabric/strategies.txt, requirements/pytorch/extra.txt.


Thank you for your contribution! 💜

Note
This comment is automatically generated and updates for 60 minutes every 180 seconds. If you have any other questions, contact carmocca for help.

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR ensures compatibility with newer bitsandbytes releases by falling back to the new int8_double_quant API when double_quant is unavailable.

  • Adds a feature check to call double_quant for older versions and int8_double_quant for bitsandbytes ≥0.46
  • Adjusts unpacking of returned values accordingly
Comments suppressed due to low confidence (1)

src/lightning/fabric/plugins/precision/bitsandbytes.py:262

  • Add a unit test to cover the int8_double_quant path (bitsandbytes ≥0.46) to ensure this fallback remains functional across releases.
CB, SCB = bnb.functional.int8_double_quant(B)

Co-authored-by: Copilot <[email protected]>
@Borda Borda added the 3rd party Related to a 3rd-party label Jun 16, 2025
Copy link

codecov bot commented Jun 16, 2025

Codecov Report

❌ Patch coverage is 0% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 87%. Comparing base (87e3974) to head (7d5d1b0).
⚠️ Report is 199 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #20911   +/-   ##
=======================================
  Coverage      87%      87%           
=======================================
  Files         268      268           
  Lines       23442    23442           
=======================================
  Hits        20391    20391           
  Misses       3051     3051           

@github-actions github-actions bot added pl Generic label for PyTorch Lightning package dependencies Pull requests that update a dependency file labels Jun 16, 2025
Copy link
Collaborator

@lantiga lantiga left a comment

Choose a reason for hiding this comment

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

thank you @Borda

@Borda Borda changed the title compatibility patch for bnb.functional.int8_double_quant bump: bitsandbytes >=0.45.2,<0.47.0 & compatibility patch for bnb.functional.int8_double_quant Jun 16, 2025
@Borda Borda merged commit c03660a into master Jun 16, 2025
169 of 174 checks passed
@Borda Borda deleted the fix/bnb.functional.int8_double_quant branch June 16, 2025 20:24
Borda added a commit that referenced this pull request Jun 19, 2025
…functional.int8_double_quant` (#20911)

* compatibility patch for `bnb.functional.int8_double_quant`
* bitsandbytes >=0.45.2,<0.47.0

---------

Co-authored-by: Copilot <[email protected]>
(cherry picked from commit c03660a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3rd party Related to a 3rd-party dependencies Pull requests that update a dependency file fabric lightning.fabric.Fabric pl Generic label for PyTorch Lightning package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants