- 
                Notifications
    
You must be signed in to change notification settings  - Fork 36
 
[Transform] Serialize with tied weights #370
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 all commits
      Commits
    
    
            Show all changes
          
          
            96 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      d8a10ec
              
                add utilities
              
              
                kylesayrs d2af054
              
                add tests
              
              
                kylesayrs e32d5b5
              
                add additional tests
              
              
                kylesayrs 9d0518b
              
                add utils and tests
              
              
                kylesayrs 8c5a2d9
              
                Implement transform factories
              
              
                kylesayrs 809e367
              
                Merge branch 'kylesayrs/transform_utils' into kylesayrs/transform_fac…
              
              
                kylesayrs 8d613b3
              
                add permutations
              
              
                kylesayrs 57d171a
              
                add delete_offload_module
              
              
                kylesayrs d77bcef
              
                Merge branch 'kylesayrs/transform-accelerate-utilities' into kylesayr…
              
              
                kylesayrs ab73b43
              
                Merge branch 'kylesayrs/transform-accelerate-utilities' into kylesayr…
              
              
                kylesayrs 4b55733
              
                Merge branch 'kylesayrs/transform_factory' into kylesayrs/transform_p…
              
              
                kylesayrs aa7d21b
              
                key inverses by weight
              
              
                kylesayrs 6901e02
              
                fix tests
              
              
                kylesayrs 47ae9fe
              
                standardize random hadamard
              
              
                kylesayrs 34f1343
              
                Merge branch 'kylesayrs/transform_utils' into kylesayrs/transform_fac…
              
              
                kylesayrs 1039100
              
                prepend input hooks
              
              
                kylesayrs 5677553
              
                Merge remote-tracking branch 'origin' into kylesayrs/transform_utils
              
              
                kylesayrs 68ec14e
              
                apply sqrt division first
              
              
                kylesayrs a62418a
              
                Merge branch 'kylesayrs/transform_utils' into kylesayrs/transform_fac…
              
              
                kylesayrs b117523
              
                use divided hadamards
              
              
                kylesayrs a46f754
              
                fix typo
              
              
                kylesayrs cb1cb52
              
                add random option
              
              
                kylesayrs 7c02bb2
              
                Merge branch 'kylesayrs/transform_utils' into kylesayrs/transform_fac…
              
              
                kylesayrs 02af1e9
              
                use random seeds, rename matrix multiply
              
              
                kylesayrs f45f3e9
              
                add deterministic generation to random matrix
              
              
                kylesayrs 7a7abdf
              
                fix perm math
              
              
                kylesayrs 6e52894
              
                update docstrings
              
              
                kylesayrs 7230933
              
                update docstrings
              
              
                kylesayrs f74fe3e
              
                Merge branch 'kylesayrs/transform_factory' into kylesayrs/transform_p…
              
              
                kylesayrs 92ddea9
              
                cleanup
              
              
                kylesayrs 779956f
              
                cleanup 2
              
              
                kylesayrs fbd2939
              
                Merge branch 'kylesayrs/transform_utils' into kylesayrs/transform_fac…
              
              
                kylesayrs dd72b6a
              
                make seed optional
              
              
                kylesayrs 4ae491d
              
                Merge branch 'kylesayrs/transform_factory' into kylesayrs/transform_p…
              
              
                kylesayrs da19b0f
              
                remove iterable check and missing return value
              
              
                kylesayrs 7ab17ce
              
                Merge branch 'main' into kylesayrs/transform_permutations
              
              
                kylesayrs 33df50f
              
                Merge remote-tracking branch 'origin' into kylesayrs/transform_permut…
              
              
                kylesayrs 6e1ec39
              
                Remove unrelated changes
              
              
                kylesayrs 938e702
              
                simplify code
              
              
                kylesayrs 27bc0b3
              
                implement apply, use in tests
              
              
                kylesayrs a27db62
              
                use hadamards database file
              
              
                kylesayrs ce63955
              
                try manifest
              
              
                kylesayrs 7ae5863
              
                try setup, update hadamards list
              
              
                kylesayrs 67675c3
              
                fix setup
              
              
                kylesayrs f061db9
              
                add docstrings, cleanup
              
              
                kylesayrs 4a84ce1
              
                fix setup, thank you @dbarbuzzi
              
              
                kylesayrs cde1066
              
                remove numpy, add tests
              
              
                kylesayrs 1ba6195
              
                solidify dtype, add gpu tests
              
              
                kylesayrs c373345
              
                fix docstring
              
              
                kylesayrs fbaf47a
              
                add device option
              
              
                kylesayrs 5a887f4
              
                construct on execution device, cache on offload device
              
              
                kylesayrs 310fe6d
              
                save construction device changes for later
              
              
                kylesayrs b715329
              
                construct on execution device, cache on offload device
              
              
                kylesayrs 249323c
              
                cite nja sloane
              
              
                kylesayrs 1823af4
              
                Merge branch 'kylesayrs/extend-hadamard', remote-tracking branch 'ori…
              
              
                kylesayrs 94a0bf5
              
                Merge remote-tracking branch 'origin' into kylesayrs/extend-hadamard
              
              
                kylesayrs cf066e0
              
                Merge branch 'kylesayrs/extend-hadamard' into kylesayrs/transform_con…
              
              
                kylesayrs c1a4a34
              
                remove dreg
              
              
                kylesayrs 5807ee1
              
                put on device via safe_open
              
              
                kylesayrs ccb88ed
              
                nits and docstrings
              
              
                kylesayrs feba695
              
                update docstring
              
              
                kylesayrs c8f6b53
              
                Merge branch 'kylesayrs/extend-hadamard' into kylesayrs/transform_con…
              
              
                kylesayrs e7f08e1
              
                Merge branch 'kylesayrs/transform_construct_cache_device' into kylesa…
              
              
                kylesayrs 75b9307
              
                Merge remote-tracking branch 'origin' into kylesayrs/transform_permut…
              
              
                kylesayrs b6a0dd4
              
                Merge remote-tracking branch 'origin' into kylesayrs/transform_constr…
              
              
                kylesayrs 955f2f5
              
                Merge
              
              
                kylesayrs 226f367
              
                merge with construct: construct in float32
              
              
                kylesayrs 9745acb
              
                Merge remote-tracking branch 'origin' into kylesayrs/transform_apply
              
              
                kylesayrs fd3390a
              
                construct with same dtype, constructing on fp32 found no difference
              
              
                kylesayrs 3c55003
              
                Merge branch 'kylesayrs/transform_construct_cache_device' into kylesa…
              
              
                kylesayrs ad29c15
              
                remove unnecessary imports
              
              
                kylesayrs 85f40b5
              
                bugfixes (#375)
              
              
                brian-dellabetta 500af9b
              
                use factory_kwargs
              
              
                kylesayrs 8e36540
              
                add frozen dict to deps
              
              
                kylesayrs 48653ec
              
                Merge remote-tracking branch 'origin' into kylesayrs/transform_permut…
              
              
                kylesayrs 56df0f7
              
                fix style
              
              
                kylesayrs a251569
              
                merge
              
              
                kylesayrs cb5a32b
              
                Merge remote-tracking branch 'origin' into kylesayrs/transform_apply
              
              
                kylesayrs 06e0346
              
                Merge branch 'kylesayrs/transform_permutations' into kylesayrs/transf…
              
              
                kylesayrs 0a4fea5
              
                Merge branch 'kylesayrs/transform_construct_cache_device' into kylesa…
              
              
                kylesayrs 49740c6
              
                use delete_offload_module
              
              
                kylesayrs 7dc182b
              
                Merge remote-tracking branch 'origin' into kylesayrs/transform_constr…
              
              
                kylesayrs 80db2ce
              
                Merge branch 'kylesayrs/transform_construct_cache_device' into kylesa…
              
              
                kylesayrs e06bbad
              
                add docstrign
              
              
                kylesayrs 438bc13
              
                Merge remote-tracking branch 'origin' into kylesayrs/transform_apply
              
              
                kylesayrs fd77ecc
              
                use parametrize
              
              
                kylesayrs 5a95fd2
              
                populate _dynamic_tied_weights_keys
              
              
                kylesayrs b009f47
              
                ensure serializable
              
              
                kylesayrs 2e362d2
              
                remove extra space
              
              
                kylesayrs c6abb96
              
                apply style
              
              
                kylesayrs 3da59a0
              
                Merge remote-tracking branch 'origin' into kylesayrs/transform_save
              
              
                kylesayrs 97345b0
              
                merge dregs
              
              
                kylesayrs 4085613
              
                skip offloading tests until transformers changes land
              
              
                kylesayrs 85419e2
              
                Merge remote-tracking branch 'origin' into kylesayrs/transform_save
              
              
                kylesayrs c45352e
              
                Merge remote-tracking branch 'origin' into kylesayrs/transform_save
              
              
                kylesayrs 85ae8ba
              
                use set
              
              
                kylesayrs 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
    
  
  
    
              
  
    
      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
    
  
  
    
              
  
    
      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
    
  
  
    
              
  
    
      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
    
  
  
    
              
  
    
      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
    
  
  
    
              
  
    
      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,54 @@ | ||
| # Copyright (c) 2021 - present / Neuralmagic, Inc. All Rights Reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| 
     | 
||
| import pytest | ||
| import torch | ||
| from compressed_tensors.transform import ( | ||
| TransformConfig, | ||
| TransformScheme, | ||
| apply_transform_config, | ||
| ) | ||
| from compressed_tensors.utils import offloaded_dispatch | ||
| from tests.testing_utils import requires_accelerate, requires_gpu | ||
| 
     | 
||
| 
     | 
||
| @pytest.mark.parametrize("type", ("hadamard", "random-hadamard")) | ||
| @pytest.mark.parametrize("randomize", (True, False)) | ||
| def test_serialization(type, randomize, model_apply, tmp_path, offload=False): | ||
| # get model, maybe offload | ||
| model, apply = model_apply | ||
| if offload: | ||
| offloaded_dispatch(model, torch.device("cuda")) | ||
| 
     | 
||
| # apply transforms to model | ||
| config = TransformConfig( | ||
| config_groups={"": TransformScheme(type=type, randomize=randomize, apply=apply)} | ||
| ) | ||
| apply_transform_config(model, config) | ||
| 
     | 
||
| # save model | ||
| model.save_pretrained(tmp_path) | ||
| 
     | 
||
| # TODO: reload model | ||
| 
     | 
||
| 
     | 
||
| @pytest.mark.skip(reason="Requires changes in upstream transformers") | ||
| # https://github.com/huggingface/transformers/pull/39280 | ||
| # https://github.com/huggingface/transformers/pull/39263 | ||
| @requires_gpu | ||
| @requires_accelerate() | ||
| @pytest.mark.parametrize("type", ("hadamard", "random-hadamard")) | ||
| @pytest.mark.parametrize("randomize", (True, False)) | ||
| def test_serialization_offload(type, randomize, model_apply, tmp_path): | ||
| test_serialization(type, randomize, model_apply, tmp_path, offload=True) | 
  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.