TylerYep / torchinfo

View model summaries in PyTorch!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error occurred while passing Empty-Vectors as parameters

Liuqh12 opened this issue · comments

Version
torchinfo==1.8.0

Above all
Empty-Vectors mean:

ev = torch.rand([])

which:

ev.shape=torch.Size([])
type(ev)=torch.Tensor

To Reproduce

from diffusers import StableDiffusionPipeline
import torch
from torchinfo import summary

pipe =  StableDiffusionPipeline.from_pretrained('runwayml/stable-diffusion-v1-5', torch_dtype=torch.float16)
unet = pipe.unet
# way 1:
summary(model=unet, input_size= [ [2, 4, 64, 64], [], [2, 77, 768] ], dtypes=[torch.FloatTensor, torch.Tensor, torch.Tensor])

#way 2:
s = torch.rand([2, 4, 64, 64])
t = torch.rand([])
e = torch.rand([2, 77, 768])

summary(model=unet, input_data={'sample':s, 'timestep':t, 'encoder_hidden_states':e}, depth=5)

Outputs:

For way 1:

Traceback (most recent call last):
  File "c:\liuqh12\ss\standard_pipe.py", line 23, in <module>
    summary(model=model, input_size= [ [2, 4, 64, 64], [], [2, 77, 768] ], dtypes=[torch.FloatTensor, torch.Tensor, torch.Tensor])
  File "C:\Users\miniconda3\envs\ss\lib\site-packages\torchinfo\torchinfo.py", line 220, in summary
    x, correct_input_size = process_input(
  File "C:\Users\miniconda3\envs\ss\lib\site-packages\torchinfo\torchinfo.py", line 256, in process_input
    x = get_input_tensor(correct_input_size, batch_dim, dtypes, device)
  File "C:\Users\miniconda3\envs\ss\lib\site-packages\torchinfo\torchinfo.py", line 529, in get_input_tensor
    input_tensor = torch.rand(*size)
TypeError: rand() received an invalid combination of arguments - got (), but expected one of:
 * (tuple of ints size, *, torch.Generator generator, tuple of names names, torch.dtype dtype, torch.layout layout, torch.device device, bool pin_memory, bool requires_grad)
 * (tuple of ints size, *, torch.Generator generator, Tensor out, torch.dtype dtype, torch.layout layout, torch.device device, bool pin_memory, bool requires_grad)
 * (tuple of ints size, *, Tensor out, torch.dtype dtype, torch.layout layout, torch.device device, bool pin_memory, bool requires_grad)
 * (tuple of ints size, *, tuple of names names, torch.dtype dtype, torch.layout layout, torch.device device, bool pin_memory, bool requires_grad)

For way2:

Traceback (most recent call last):
  File "c:\liuqh12\ss\standard_pipe.py", line 24, in <module>
    summary(model=model, input_data={'sample':s, 'timestep':t, 'encoder_hidden_states':e}, depth=5)
  File "C:\Users\miniconda3\envs\ss\lib\site-packages\torchinfo\torchinfo.py", line 223, in summary
    summary_list = forward_pass(
  File "C:\Users\miniconda3\envs\ss\lib\site-packages\torchinfo\torchinfo.py", line 304, in forward_pass
    raise RuntimeError(
RuntimeError: Failed to run torchinfo. See above stack traces for more details. Executed layers up to: [Timesteps: 1]

May I skip some usage detail?
thanks