- 
                Notifications
    
You must be signed in to change notification settings  - Fork 926
 
          Blog post on bitsandbytes integration on Hugging Face
          #463
        
          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
          
     Merged
      
      
    
  
     Merged
                    Changes from 58 commits
      Commits
    
    
            Show all changes
          
          
            60 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      e13bf39
              
                first commit
              
              
                younesbelkada fc8fb59
              
                add new thumbnails
              
              
                younesbelkada 7cd183c
              
                add more content
              
              
                younesbelkada 7f3e653
              
                add new gif
              
              
                younesbelkada 7471a28
              
                Update _blog.yml
              
              
                younesbelkada 9cab34a
              
                Merge branch 'main' into add_bnb_inference
              
              
                younesbelkada b4ba73b
              
                Merge branch 'main' into add_bnb_inference
              
              
                younesbelkada 4cc7cbf
              
                rename files
              
              
                younesbelkada df2fcb6
              
                Merge branch 'add_bnb_inference' of https://github.com/younesbelkada/…
              
              
                younesbelkada 9ed399b
              
                Apply suggestions from code review
              
              
                younesbelkada e598e7b
              
                Apply suggestions from code review
              
              
                younesbelkada a4f548e
              
                change content a bit
              
              
                younesbelkada e4e9b2a
              
                re-write text: part 1
              
              
                stas00 d36520a
              
                few modifs
              
              
                younesbelkada c37de76
              
                modify a bit
              
              
                younesbelkada 2d7f6ef
              
                add more content
              
              
                younesbelkada 62a1c96
              
                add image
              
              
                younesbelkada 768fdd7
              
                paraphrase a bit
              
              
                younesbelkada 94e88ee
              
                add more content
              
              
                younesbelkada 907b496
              
                add more content
              
              
                younesbelkada 4b2f33d
              
                some improvements
              
              
                younesbelkada 7850a1a
              
                add thumbnail
              
              
                younesbelkada b093193
              
                add more text + fix table
              
              
                younesbelkada 7f66c85
              
                fix table
              
              
                younesbelkada c3b3c16
              
                fix tables
              
              
                younesbelkada e9c5ecc
              
                add stas as author
              
              
                younesbelkada 7042366
              
                add a last sentence
              
              
                younesbelkada a18447d
              
                edit some more
              
              
                stas00 c713148
              
                few modifs
              
              
                younesbelkada 0815b10
              
                modify thumbail
              
              
                younesbelkada f8ea5ed
              
                add thumbnail
              
              
                younesbelkada a51c607
              
                add removed comment
              
              
                younesbelkada d509d06
              
                add photos
              
              
                younesbelkada 884b7a4
              
                add more infos
              
              
                younesbelkada 20f0179
              
                Apply suggestions from code review
              
              
                younesbelkada 93301b8
              
                Apply suggestions from code review
              
              
                younesbelkada 1895282
              
                Add files via upload
              
              
                younesbelkada ccea0ef
              
                add steven to the credits!
              
              
                younesbelkada a606303
              
                edits
              
              
                stas00 362363f
              
                edits
              
              
                stas00 e6adfa7
              
                edits
              
              
                stas00 84fe2cb
              
                edits
              
              
                younesbelkada a5826d5
              
                add script
              
              
                younesbelkada c71e04f
              
                change to std err
              
              
                younesbelkada c9b1071
              
                refactor a bit the tables
              
              
                younesbelkada 6542f67
              
                add Tim's comments
              
              
                younesbelkada 96898cf
              
                remove separators
              
              
                younesbelkada c749578
              
                explain why it is slow
              
              
                younesbelkada 35c31c1
              
                Update hf-bitsandbytes-integration.md
              
              
                younesbelkada c6a39d7
              
                Add links to paper
              
              
                younesbelkada 92517be
              
                delete dummy file
              
              
                younesbelkada f8fa134
              
                add correct link to paper
              
              
                younesbelkada 728ffa8
              
                add more explanation on speed
              
              
                younesbelkada d2ff94a
              
                update figure
              
              
                younesbelkada e83dee8
              
                replace authors by we
              
              
                younesbelkada 3789ca0
              
                add freezed image
              
              
                younesbelkada 88075aa
              
                remove old table
              
              
                younesbelkada 060313f
              
                Update hf-bitsandbytes-integration.md
              
              
                TimDettmers 4ff602f
              
                Apply suggestions from code review
              
              
                younesbelkada 487c428
              
                Apply suggestions from code review
              
              
                younesbelkada File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
              
      
      Loading
      
  Sorry, something went wrong. Reload?
      Sorry, we cannot display this file.
      Sorry, this file is invalid so it cannot be displayed.
      
    
      
      Loading
      
  Sorry, something went wrong. Reload?
      Sorry, we cannot display this file.
      Sorry, this file is invalid so it cannot be displayed.
      
    
      
      Loading
      
  Sorry, something went wrong. Reload?
      Sorry, we cannot display this file.
      Sorry, this file is invalid so it cannot be displayed.
      
    
      
      Loading
      
  Sorry, something went wrong. Reload?
      Sorry, we cannot display this file.
      Sorry, this file is invalid so it cannot be displayed.
      
    
      
      Loading
      
  Sorry, something went wrong. Reload?
      Sorry, we cannot display this file.
      Sorry, this file is invalid so it cannot be displayed.
      
    
      
      Loading
      
  Sorry, something went wrong. Reload?
      Sorry, we cannot display this file.
      Sorry, this file is invalid so it cannot be displayed.
      
    
      
      Loading
      
  Sorry, something went wrong. Reload?
      Sorry, we cannot display this file.
      Sorry, this file is invalid so it cannot be displayed.
      
    
      
      Loading
      
  Sorry, something went wrong. Reload?
      Sorry, we cannot display this file.
      Sorry, this file is invalid so it cannot be displayed.
      
    
      
      Loading
      
  Sorry, something went wrong. Reload?
      Sorry, we cannot display this file.
      Sorry, this file is invalid so it cannot be displayed.
      
    
      
      Loading
      
  Sorry, something went wrong. Reload?
      Sorry, we cannot display this file.
      Sorry, this file is invalid so it cannot be displayed.
      
    
      
      Loading
      
  Sorry, something went wrong. Reload?
      Sorry, we cannot display this file.
      Sorry, this file is invalid so it cannot be displayed.
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import torch | ||
| import torch.nn as nn | ||
| 
     | 
||
| from bitsandbytes.nn import Linear8bitLt | ||
| 
     | 
||
| # Utility function | ||
| 
     | 
||
| def get_model_memory_footprint(model): | ||
| r""" | ||
| Partially copied and inspired from: https://discuss.pytorch.org/t/gpu-memory-that-model-uses/56822/2 | ||
| """ | ||
| return sum([param.nelement() * param.element_size() for param in model.parameters()]) | ||
| 
     | 
||
| # Main script | ||
| 
     | 
||
| fp16_model = nn.Sequential( | ||
| nn.Linear(64, 64), | ||
| nn.Linear(64, 64) | ||
| ).to(torch.float16) | ||
| 
     | 
||
| # Train and save your model! | ||
| 
     | 
||
| torch.save(fp16_model.state_dict(), "model.pt") | ||
| 
     | 
||
| # Define your int8 model! | ||
| 
     | 
||
| int8_model = nn.Sequential( | ||
| Linear8bitLt(64, 64, has_fp16_weights=False), | ||
| Linear8bitLt(64, 64, has_fp16_weights=False) | ||
| ) | ||
| 
     | 
||
| int8_model.load_state_dict(torch.load("model.pt")) | ||
| int8_model = int8_model.to(0) # Quantization happens here | ||
| 
     | 
||
| input_ = torch.randn(8, 64, dtype=torch.float16) | ||
| hidden_states = int8_model(input_.to(0)) | ||
| 
     | 
||
| mem_int8 = get_model_memory_footprint(int8_model) | ||
| mem_fp16 = get_model_memory_footprint(fp16_model) | ||
| 
     | 
||
| print(f"Relative difference: {mem_fp16/mem_int8}") | 
      
      Loading
      
  Sorry, something went wrong. Reload?
      Sorry, we cannot display this file.
      Sorry, this file is invalid so it cannot be displayed.
      
    
      
      Loading
      
  Sorry, something went wrong. Reload?
      Sorry, we cannot display this file.
      Sorry, this file is invalid so it cannot be displayed.
      
    
      
      Loading
      
  Sorry, something went wrong. Reload?
      Sorry, we cannot display this file.
      Sorry, this file is invalid so it cannot be displayed.
      
    
      
      Loading
      
  Sorry, something went wrong. Reload?
      Sorry, we cannot display this file.
      Sorry, this file is invalid so it cannot be displayed.
      
    
        
          
          Binary file added
          
            BIN
              
                +17.4 KB
              
          
        
  assets/96_hf_bitsandbytes_integration/tf32-Mantissa-chart-hi-res-FINAL.png
  
  
      
      
   
        
      
      
    
      
      Loading
      
  Sorry, something went wrong. Reload?
      Sorry, we cannot display this file.
      Sorry, this file is invalid so it cannot be displayed.
      
    
      
      Loading
      
  Sorry, something went wrong. Reload?
      Sorry, we cannot display this file.
      Sorry, this file is invalid so it cannot be displayed.
      
    
      
      Loading
      
  Sorry, something went wrong. Reload?
      Sorry, we cannot display this file.
      Sorry, this file is invalid so it cannot be displayed.
      
    
      
      Loading
      
  Sorry, something went wrong. Reload?
      Sorry, we cannot display this file.
      Sorry, this file is invalid so it cannot be displayed.
      
    
      
      Loading
      
  Sorry, something went wrong. Reload?
      Sorry, we cannot display this file.
      Sorry, this file is invalid so it cannot be displayed.
      
    Large diffs are not rendered by default.
      
      Oops, something went wrong.
      
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.