TylerYep / torchinfo

View model summaries in PyTorch!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

verbose=2 shows weights twice

matthijsvk opened this issue · comments

Describe the bug

I want to see detail until layer.weight and layer.bias, and it seems this is only possible with verbose=2.
I tried setting max_depth=1000, but with verbose=1 the 'weight'/'bias' parameters are never shown in the summary.

With verbose=2, the weighs show up twice for some reason. Once at the top-level, and once under their actual layer (see below)

To Reproduce

import torch
import torch.nn as nn
from torchinfo import summary

model = nn.Sequential(
        nn.Linear(10,10),
        nn.Sequential(
            nn.Linear(10,10),
            nn.Linear(10,10)
        )
)

model_stats = summary(
    model,
    input_data=torch.randn(size=(1, 10)),
    verbose=2,
    col_names=["output_size", "kernel_size", "num_params", "mult_adds"], 
)

Output:

============================================================================================================================================
Layer (type:depth-idx)                   Output Shape              Kernel Shape              Param #                   Mult-Adds
============================================================================================================================================
Sequential                               [1, 10]                   --                        --                        --
├─Linear: 1-1                            [1, 10]                   --                        110                       110
│    └─weight                                                      [10, 10]                  ├─100
│    └─bias                                                        [10]                      └─10
├─Sequential: 1-2                        [1, 10]                   --                        --                        --
│    └─0.weight                                                    [10, 10]                  ├─100
│    └─0.bias                                                      [10]                      ├─10
│    └─1.weight                                                    [10, 10]                  ├─100
│    └─1.bias                                                      [10]                      └─10
│    └─Linear: 2-1                       [1, 10]                   --                        110                       110
│    │    └─weight                                                 [10, 10]                  ├─100
│    │    └─bias                                                   [10]                      └─10
│    └─Linear: 2-2                       [1, 10]                   --                        110                       110
│    │    └─weight                                                 [10, 10]                  ├─100
│    │    └─bias                                                   [10]                      └─10
============================================================================================================================================

Expected behavior

============================================================================================================================================
Layer (type:depth-idx)                   Output Shape              Kernel Shape              Param #                   Mult-Adds
============================================================================================================================================
Sequential                               [1, 10]                   --                        --                        --
├─Linear: 1-1                            [1, 10]                   --                        110                       110
│    └─weight                                                      [10, 10]                  ├─100
│    └─bias                                                        [10]                      └─10
├─Sequential: 1-2                        [1, 10]                   --                        --                        --
│    └─Linear: 2-1                       [1, 10]                   --                        110                       110
│    │    └─weight                                                 [10, 10]                  ├─100
│    │    └─bias                                                   [10]                      └─10
│    └─Linear: 2-2                       [1, 10]                   --                        110                       110
│    │    └─weight                                                 [10, 10]                  ├─100
│    │    └─bias                                                   [10]                      └─10
============================================================================================================================================

For a temporary solution in Vim, you can eliminate duplicates using the following command: :%s/.*└.*\..*\n//g