mirror of
				https://github.com/pytorch/pytorch.git
				synced 2025-11-04 08:00:58 +08:00 
			
		
		
		
	[Reland] Clean Up MobileOptimizerType Rewrite Flags Public API and Documentation (#92081)
Summary:
X-link: https://github.com/facebookresearch/d2go/pull/459
Reland of D41690203 (370df963e0)
Remove MobileOptimizerType and all rewrite flags from torch.X and torch._C.X to clean up torch.X and torch._C.X namespaces
The affected rewrite flags are
- CONV_BN_FUSION
- FUSE_ADD_RELU
- HOIST_CONV_PACKED_PARAMS
- INSERT_FOLD_PREPACK_OPS
- REMOVE_DROPOUT
- VULKAN_AUTOMATIC_GPU_TRANSFER
Bc-Breaking Change:
Before this change, the rewrite flags were accessible through all of
1. torch.utils.mobile_optimizer.MobileOptimizerType.X
2. torch._C.MobileOptimizerType.X
3. torch.X
4. torch.MobileOptimizerType.X
5. torch._C.X
But after this change, only torch.utils.mobile_optimizer.MobileOptimizerType.X  (option 1 above) and the newly added torch._C._MobileOptimizerType.X remain
Corresponding updates to PyTorch Tutorial Docs are in https://github.com/pytorch/tutorials/pull/2163
Test Plan:
```buck test caffe2/test:test_mobile_optimizer```
```
Summary
  Pass: 6
  Skip: 1
    ↻ caffe2/test:test_mobile_optimizer - test_mobilenet_optimize_for_mobile (test_mobile_optimizer.TestOptimizer)
  ListingSuccess: 1
Finished test run: https://www.internalfb.com/intern/testinfra/testrun/4222124793514412
```
___
```buck test caffe2/torch/fb/mobile/tests:model_exporter_tests```
Tests pass
___
With temporary testing changes in D41690204:
```buck run caffe2:test_rewrite_flags_api```
Before:
```
torch.utils.mobile_optimizer.MobileOptimizerType.VULKAN_AUTOMATIC_GPU_TRANSFER
        Expected: ✅ | Result: ✅
torch._C._MobileOptimizerType.VULKAN_AUTOMATIC_GPU_TRANSFER
        Expected: ✅ | Result: ❌ (module 'torch._C' has no attribute '_MobileOptimizerType')
torch._C.MobileOptimizerType.VULKAN_AUTOMATIC_GPU_TRANSFER
        Expected: ❌ | Result: ✅
torch.VULKAN_AUTOMATIC_GPU_TRANSFER
        Expected: ❌ | Result: ✅
torch.MobileOptimizerType.VULKAN_AUTOMATIC_GPU_TRANSFER
        Expected: ❌ | Result: ✅
torch._C.VULKAN_AUTOMATIC_GPU_TRANSFER
        Expected: ❌ | Result: ✅
```
After:
```
torch.utils.mobile_optimizer.MobileOptimizerType.VULKAN_AUTOMATIC_GPU_TRANSFER
        Expected: ✅ | Result: ✅
torch._C._MobileOptimizerType.VULKAN_AUTOMATIC_GPU_TRANSFER
        Expected: ✅ | Result: ✅
torch._C.MobileOptimizerType.VULKAN_AUTOMATIC_GPU_TRANSFER
        Expected: ❌ | Result: ❌ (module 'torch._C' has no attribute 'MobileOptimizerType')
torch.VULKAN_AUTOMATIC_GPU_TRANSFER
        Expected: ❌ | Result: ❌ (module 'torch' has no attribute 'VULKAN_AUTOMATIC_GPU_TRANSFER')
torch.MobileOptimizerType.VULKAN_AUTOMATIC_GPU_TRANSFER
        Expected: ❌ | Result: ❌ (module 'torch' has no attribute 'MobileOptimizerType')
torch._C.VULKAN_AUTOMATIC_GPU_TRANSFER
        Expected: ❌ | Result: ❌ (module 'torch._C' has no attribute 'VULKAN_AUTOMATIC_GPU_TRANSFER')
```
```buck test caffe2/test:public_bindings -- test_no_new_bindings```
```
Summary
  Pass: 1
  ListingSuccess: 1
Finished test run: https://www.internalfb.com/intern/testinfra/testrun/7881299473114294
```
Reviewed By: SS-JIA
Differential Revision: D42442395
Pull Request resolved: https://github.com/pytorch/pytorch/pull/92081
Approved by: https://github.com/albanD
			
			
This commit is contained in:
		
				
					committed by
					
						
						PyTorch MergeBot
					
				
			
			
				
	
			
			
			
						parent
						
							55f0ed6dcd
						
					
				
				
					commit
					da43584bef
				
			@ -1315,7 +1315,7 @@ void initJITBindings(PyObject* module) {
 | 
			
		||||
          "get_all_written_records",
 | 
			
		||||
          &PyTorchStreamWriter::getAllWrittenRecords);
 | 
			
		||||
 | 
			
		||||
  py::enum_<MobileOptimizerType>(m, "MobileOptimizerType")
 | 
			
		||||
  py::enum_<MobileOptimizerType>(m, "_MobileOptimizerType")
 | 
			
		||||
      .value("CONV_BN_FUSION", MobileOptimizerType::CONV_BN_FUSION)
 | 
			
		||||
      .value(
 | 
			
		||||
          "INSERT_FOLD_PREPACK_OPS",
 | 
			
		||||
@ -1327,8 +1327,7 @@ void initJITBindings(PyObject* module) {
 | 
			
		||||
          MobileOptimizerType::HOIST_CONV_PACKED_PARAMS)
 | 
			
		||||
      .value(
 | 
			
		||||
          "VULKAN_AUTOMATIC_GPU_TRANSFER",
 | 
			
		||||
          MobileOptimizerType::VULKAN_AUTOMATIC_GPU_TRANSFER)
 | 
			
		||||
      .export_values();
 | 
			
		||||
          MobileOptimizerType::VULKAN_AUTOMATIC_GPU_TRANSFER);
 | 
			
		||||
 | 
			
		||||
  // This allows PyTorchStreamReader to read from a Python buffer. It requires
 | 
			
		||||
  // that the buffer implement `seek()`, `tell()`, and `read()`.
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user