Repository: pytorch/torchdynamo

Issue:
isinstance test on dtype causes graph break
```
diff --git a/tests/test_repros.py b/tests/test_repros.py
index 4d590f7..3ede478 100755
--- a/tests/test_repros.py
+++ b/tests/test_repros.py
@@ -1246,3 +1246,11 @@ class ReproTests(torchdynamo.testing.TestCase):
 
         self.assertTrue(same(ref0, res0))
         self.assertTrue(same(ref1, res1))
+
+    def test_isinstance_dtype(self):
+        @torchdynamo.optimize("eager", nopython=True)
+        def fn(x):
+            isinstance(torch.bfloat16, torch.dtype)
+            return x
+
+        fn(torch.randn(3))
```

you get

```
Traceback (most recent call last):                                                                                               
  File "/raid/ezyang/torchdynamo/torchdynamo/convert_frame.py", line 278, in _convert_frame_assert                               
    code = transform_code_object(frame.f_code, transform)                                                                        
  File "/raid/ezyang/torchdynamo/torchdynamo/bytecode_transformation.py", line 338, in transform_code_object                     
    transformations(instructions, code_options)                                                                                  
  File "/raid/ezyang/torchdynamo/torchdynamo/convert_frame.py", line 254, in transform                                           
    tracer.run()                                                                                                                 
  File "/raid/ezyang/torchdynamo/torchdynamo/symbolic_convert.py", line 306, in run                                              
    and self.step()                                                                                                              
  File "/raid/ezyang/torchdynamo/torchdynamo/symbolic_convert.py", line 284, in step                                             
    getattr(self, inst.opname)(inst)                                                                                             
  File "/raid/ezyang/torchdynamo/torchdynamo/symbolic_convert.py", line 145, in wrapper                                          
    return inner_fn(self, inst)                                                                                                  
  File "/raid/ezyang/torchdynamo/torchdynamo/symbolic_convert.py", line 619, in CALL_FUNCTION                                    
    self.call_function(fn, args, {})                                                                                             
  File "/raid/ezyang/torchdynamo/torchdynamo/symbolic_convert.py", line 220, in call_function                                    
    self.push(fn.call_function(self, args, kwargs))                                                                              
  File "/raid/ezyang/torchdynamo/torchdynamo/variables/builtin.py", line 220, in call_function                                   
    result = handler(tx, *args, **kwargs)                                                                                        
  File "/raid/ezyang/torchdynamo/torchdynamo/variables/builtin.py", line 354, in call_isinstance                                 
    arg_type = arg.python_type()                                                                                                 
  File "/raid/ezyang/torchdynamo/torchdynamo/variables/torch.py", line 67, in python_type                                        
    return super().python_type()                                                                                                 
  File "/raid/ezyang/torchdynamo/torchdynamo/variables/base.py", line 137, in python_type                                        
    raise NotImplementedError(f"{self} has no type")                                                                             
NotImplementedError: TorchVariable() has no type 
```


Discussion:
cc @mlazos 
I think this is a good starter task.

Resolving patch:
diff --git a/torchdynamo/allowed_functions.py b/torchdynamo/allowed_functions.py
--- a/torchdynamo/allowed_functions.py
+++ b/torchdynamo/allowed_functions.py
@@ -91,6 +91,11 @@ def _disallowed_function_ids():
         torch.autograd.profiler.profile,
         warnings.warn,
     ]
+    # extract all dtypes from torch
+    dtypes = [
+        obj for obj in torch.__dict__.values() if isinstance(obj, type(torch.float32))
+    ]
+    remove += dtypes
     return {id(x) for x in remove}
 
 


Test patch:
diff --git a/tests/test_repros.py b/tests/test_repros.py
--- a/tests/test_repros.py
+++ b/tests/test_repros.py
@@ -1313,3 +1313,11 @@ def fn():
             return True
 
         fn()
+
+    def test_isinstance_dtype(self):
+        @torchdynamo.optimize("eager", nopython=True)
+        def fn(x):
+            isinstance(torch.bfloat16, torch.dtype)
+            return x
+
+        fn(torch.randn(3))