- 
                Notifications
    
You must be signed in to change notification settings  - Fork 693
 
Added Converters for Basic Casting Operations #607
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
          
     Open
      
      
            JWLee89
  wants to merge
  10
  commits into
  NVIDIA-AI-IOT:master
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
JWLee89:cast-converter
  
      
      
   
  
    
  
  
  
 
  
      
    base: master
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
  
     Open
                    Changes from 9 commits
      Commits
    
    
            Show all changes
          
          
            10 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      f7ea780
              
                Added converters for .float(), .bool(), .int() casting operations
              
              
                JWLee89 3bb6486
              
                Added tests for each casting case
              
              
                JWLee89 65a193b
              
                Updated tests
              
              
                JWLee89 4e12e92
              
                Added import to __init__.py and added test cases for .cast operations
              
              
                JWLee89 23e1b89
              
                Removed redundant tests and converters.
              
              
                JWLee89 59f308d
              
                Added back the proper tests and class operations for testing.
              
              
                JWLee89 43c77ae
              
                Updated methods and converter function names, as wel as tensorrt_conv…
              
              
                JWLee89 24b344c
              
                renamed test_torch_bool_casting to test_torch_bool_cast for consistency
              
              
                JWLee89 d087035
              
                Removed redundant comments
              
              
                JWLee89 d158944
              
                Update layer precision based on torch2trt preicion modes
              
              
                JWLee89 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
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -67,3 +67,4 @@ | |
| from .transpose import * | ||
| from .unary import * | ||
| from .view import * | ||
| from .cast import * | ||
  
    
      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,72 @@ | ||
| from torch2trt.torch2trt import * | ||
| from torch2trt.module_test import add_module_test | ||
| 
     | 
||
| 
     | 
||
| def convert_cast(ctx): | ||
| """ | ||
| A simple converter for supporting casting operations. | ||
| 
     | 
||
| IMPORTANT: Note that because TensorRT does not support | ||
| 64 bit data types, .long() will not be supported | ||
| """ | ||
| input_tensor = ctx.method_args[0] | ||
| layer = ctx.network.add_identity(input_tensor._trt) | ||
| output = ctx.method_return | ||
| output._trt = layer.get_output(0) | ||
| 
     | 
||
| 
     | 
||
| @tensorrt_converter("torch.Tensor.float") | ||
| def convert_float(ctx): | ||
| convert_cast(ctx) | ||
| 
     | 
||
| 
     | 
||
| @tensorrt_converter("torch.Tensor.int") | ||
| def convert_int(ctx): | ||
| convert_cast(ctx) | ||
| 
     | 
||
| 
     | 
||
| @tensorrt_converter("torch.Tensor.bool") | ||
| def convert_bool(ctx): | ||
| convert_cast(ctx) | ||
| 
     | 
||
| 
     | 
||
| class DotFloat(torch.nn.Module): | ||
| def __init__(self): | ||
| super(DotFloat, self).__init__() | ||
| 
     | 
||
| def forward(self, x): | ||
| return x.float() | ||
| 
     | 
||
| 
     | 
||
| class DotInt(torch.nn.Module): | ||
| def __init__(self): | ||
| super(DotInt, self).__init__() | ||
| 
     | 
||
| def forward(self, x): | ||
| return x.int() | ||
| 
     | 
||
| 
     | 
||
| class DotBool(torch.nn.Module): | ||
| def __init__(self): | ||
| super(DotBool, self).__init__() | ||
| 
     | 
||
| def forward(self, x): | ||
| return x.bool() | ||
| 
     | 
||
| 
     | 
||
| @add_module_test(torch.bool, torch.device('cuda'), [(1, 3, 3)]) | ||
| @add_module_test(torch.int32, torch.device('cuda'), [(1, 3, 3)]) | ||
| def test_torch_float_cast(): | ||
| return DotFloat() | ||
| 
     | 
||
| 
     | 
||
| @add_module_test(torch.float32, torch.device('cuda'), [(1, 3, 3)]) | ||
| @add_module_test(torch.int32, torch.device('cuda'), [(1, 3, 3)]) | ||
| def test_torch_int_cast(): | ||
| return DotInt() | ||
| 
     | 
||
| 
     | 
||
| @add_module_test(torch.float32, torch.device('cuda'), [(1, 3, 3)]) | ||
| @add_module_test(torch.int32, torch.device('cuda'), [(1, 3, 3)]) | ||
| def test_torch_bool_cast(): | ||
| return DotBool() | ||
  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.