-   Notifications  You must be signed in to change notification settings 
- Fork 559
[LoweringContext] Support an optimized parameter mapping for SPMD #8453
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
   Closed  
     Closed  
 Changes from all commits
 Commits 
  Show all changes 
  5 commits   Select commit Hold shift + click to select a range 
 f898629  [LoweringContext] Support an optimized parameter mapping for SPMD 
  rpsilva-aws d0a345a  [LoweringContext] Support an optimized parameter mapping for SPMD 
  rpsilva-aws 7f55eca  Merge branch 'rpsilva_lc_mapping' of github.com:rpsilva-aws/xla into … 
  rpsilva-aws 6b61128  Merge branch 'rpsilva_lc_mapping' of github.com:rpsilva-aws/xla into … 
  rpsilva-aws d29b39b  Merge branch 'rpsilva_lc_mapping' of github.com:rpsilva-aws/xla into … 
  rpsilva-aws 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   
     | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| import sys | ||
|  | ||
| import unittest | ||
|  | ||
| import test_xla_sharding_base | ||
|  | ||
| import torch | ||
| import torch_xla | ||
| import torch_xla.debug.metrics as met | ||
| import torch_xla.distributed.spmd as xs | ||
| import torch_xla.core.xla_model as xm | ||
| import contextlib | ||
|  | ||
|  | ||
| class TestSPMDLoweringContext(test_xla_sharding_base.XlaShardingTest): | ||
|  | ||
| @classmethod | ||
| def setUpClass(cls): | ||
| super().setUpClass() | ||
|  | ||
| def test_device_parameter_id_tensor_mapping(self): | ||
| met.clear_all() | ||
|  | ||
| model_axis = min(8, self.n_devices) | ||
| data_axis = self.n_devices // model_axis | ||
| mesh_shape = (data_axis, model_axis) | ||
| spmd_mesh = self._get_mesh(mesh_shape, axis_names=('x', 'y')) | ||
|  | ||
| device = xm.xla_device() | ||
| a = torch.randn([32, 2048]).to(device) | ||
| xs.mark_sharding(a, spmd_mesh, ('x', 'y')) | ||
| b = torch.ones(2048).to(device) | ||
| xs.mark_sharding(b, spmd_mesh, ('x',)) | ||
|  | ||
| def fn(a, b): | ||
| return a + b | ||
|  | ||
| result = fn(a, b) | ||
| ctx = torch_xla._XLAC.lowering.LoweringContext("MyCustomName") | ||
| ctx.build([result]) | ||
| torch_xla.sync() | ||
|  | ||
| mapping = ctx.device_parameter_id_tensor_mapping() | ||
| num_params = len(mapping) | ||
| self.assertEqual(num_params, 2) | ||
| self.assertNotEqual(ctx.tensor_parameter_id(a), -1) | ||
| self.assertNotEqual(ctx.tensor_parameter_id(b), -1) | ||
| self.assertEqual(met.counter_value("VirtualDeviceUsage"), num_params) | ||
|  | ||
| # Ensure that the parameter mapping does not require transferring data | ||
| # from the device to the host when sharded. | ||
| self.assertFalse(met.metric_data("TransferFromDeviceTime")) | ||
| self.assertFalse(met.counter_value("ReplicateShardedData")) | ||
|  | ||
|  | ||
| if __name__ == '__main__': | ||
| test = unittest.main() | ||
| sys.exit(0 if test.result.wasSuccessful() else 1) | 
   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   
       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.