question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unkown type name 'torch.device'

See original GitHub issue

🐛 Bug

I ran the one-liner to see if the library works python -c "import kornia; print(kornia.__version__)"

But I got an error

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/sandro/anaconda3/envs/supermariopy/lib/python3.7/site-packages/kornia/__init__.py", line 18, in <module>
    from kornia import jit
  File "/home/sandro/anaconda3/envs/supermariopy/lib/python3.7/site-packages/kornia/jit/__init__.py", line 8, in <module>
    spatial_soft_argmax2d = torch.jit.script(K.geometry.spatial_soft_argmax2d)
  File "/home/sandro/anaconda3/envs/supermariopy/lib/python3.7/site-packages/torch/jit/__init__.py", line 1281, in script
    fn = torch._C._jit_script_compile(qualified_name, ast, _rcb, get_default_args(obj))
  File "/home/sandro/anaconda3/envs/supermariopy/lib/python3.7/site-packages/torch/jit/_recursive.py", line 555, in try_compile_fn
    return torch.jit.script(fn, _rcb=rcb)
  File "/home/sandro/anaconda3/envs/supermariopy/lib/python3.7/site-packages/torch/jit/__init__.py", line 1281, in script
    fn = torch._C._jit_script_compile(qualified_name, ast, _rcb, get_default_args(obj))
  File "/home/sandro/anaconda3/envs/supermariopy/lib/python3.7/site-packages/torch/jit/_recursive.py", line 555, in try_compile_fn
    return torch.jit.script(fn, _rcb=rcb)
  File "/home/sandro/anaconda3/envs/supermariopy/lib/python3.7/site-packages/torch/jit/__init__.py", line 1281, in script
    fn = torch._C._jit_script_compile(qualified_name, ast, _rcb, get_default_args(obj))
RuntimeError: 
Unknown type name 'torch.device':
  File "/home/sandro/anaconda3/envs/supermariopy/lib/python3.7/site-packages/kornia/utils/grid.py", line 10
        width: int,
        normalized_coordinates: bool = True,
        device: Optional[torch.device] = torch.device('cpu')) -> torch.Tensor:
                         ~~~~~~~~~~~~ <--- HERE
    """Generates a coordinate grid for an image.
'create_meshgrid' is being compiled since it was called from 'spatial_expectation2d'
  File "/home/sandro/anaconda3/envs/supermariopy/lib/python3.7/site-packages/kornia/geometry/dsnt.py", line 89

    # Create coordinates grid.
    grid: torch.Tensor = create_meshgrid(height, width, normalized_coordinates, input.device)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ <--- HERE
    grid = grid.to(input.dtype)
'spatial_expectation2d' is being compiled since it was called from 'spatial_soft_argmax2d'
  File "/home/sandro/anaconda3/envs/supermariopy/lib/python3.7/site-packages/kornia/geometry/spatial_soft_argmax.py", line 515
    """
    input_soft: torch.Tensor = dsnt.spatial_softmax2d(input, temperature)
    output: torch.Tensor = dsnt.spatial_expectation2d(input_soft, normalized_coordinates)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ <--- HERE
    return output

Environment

  • PyTorch Version: torch==1.5.0 torchvision==0.5.0 torchviz==0.0.1
  • OS: Linux
  • How you installed PyTorch: pip
  • Python version: python 3.7
  • CUDA/cuDNN version: none (CPU)

I guess I am missing something trivial. It would be great if someone could help me figure out my problem. Thanks

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
edgarribacommented, May 14, 2020

@theRealSuperMario I will add it somewhere to the readme. This is actually a problem since pip doesn’t solve well dependencies. The package was explicitly built with torch 1.5.0 as install dependency but apparently pip doesn’t throw any error in case you have a different version during installation. It only uses version in case you don’t have any torch in your system, then will download by default minimum required version.

1reaction
theRealSuperMariocommented, May 14, 2020

I guess it would be greate to note this somewhere on the readme, or did I just not find this piece of information because I was unable to search properly?

Read more comments on GitHub >

github_iconTop Results From Across the Web

[jit] torch.device type annotation not supported in methods
RuntimeError: Unknown type name 'torch.device': File "a.py", ... [JIT] Resolve torch.device in recursive compilation of classes
Read more >
Torch::jit::load fails with Unknown Type Name Error - Mobile
I am trying to implement Fast Neural Style Transfer on iOS application. To do that, I started with an implemented version of Fast...
Read more >
Why can't I use classes for type annotation of the arguments to ...
Module s have some special handling in TorchScript to make them work, but they aren't currently supported as arguments.
Read more >
Torchscripted Pytorch Lightning Module Fails to Load
The torchscripted module runs without issue outside of triton. ... failed to load model 'model': Unknown type name 'NoneType': Serialized ...
Read more >
torch.jit - Enchanter documentation
This means that all submodules must be subclasses of :class:`ScriptModule` as well. .. DANGER:: All modules, no matter their device, are always loaded...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found