benchmark icon indicating copy to clipboard operation
benchmark copied to clipboard

AttributeError: 'tuple' object has no attribute 'shape'

Open Dominic-ZZ opened this issue 2 years ago • 1 comments

Command: python run.py yolov3 -d cpu -t train --bs 1 Error:

Running train method from yolov3 on cpu in eager mode.
Traceback (most recent call last):
  File "run.py", line 230, in <module>
    m = Model(device=args.device, test=args.test, jit=(args.mode == args.mode), batch_size=args.bs, extra_args=extra_args)
  File "/workspace/pytorch_benchmark/benchmark/torchbenchmark/util/model.py", line 14, in __call__
    obj.__post__init__()
  File "/workspace/pytorch_benchmark/benchmark/torchbenchmark/util/model.py", line 103, in __post__init__
    apply_opt_args(self, self.opt_args)
  File "/workspace/pytorch_benchmark/benchmark/torchbenchmark/util/extra_args.py", line 133, in apply_opt_args
    model.set_module(enable_jit(model=module, example_inputs=exmaple_inputs, test=model.test))
  File "/workspace/pytorch_benchmark/benchmark/torchbenchmark/util/backends/jit.py", line 8, in enable_jit
    model = torch.jit.script(model, example_inputs=[example_inputs, ])
  File "/opt/conda/lib/python3.8/site-packages/torch/jit/_script.py", line 1275, in script
    obj(*examples)
  File "/opt/conda/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1186, in _call_impl
    return forward_call(*input, **kwargs)
  File "/workspace/pytorch_benchmark/benchmark/torchbenchmark/models/yolov3/yolo_models.py", line 240, in forward
    img_size = x.shape[-2:]  # height, width
AttributeError: 'tuple' object has no attribute 'shape'

and than, I print the x:

(tensor([[[[ 70,  59,  66,  ...,  95,  95,  95],
          [ 62,  55,  57,  ...,  95,  95,  95],
          [ 77,  56,  71,  ...,  95,  95,  95],
          ...,
          [212, 213, 207,  ...,  89,  79,  85],
          [210, 210, 206,  ...,  82,  77,  79],
          [211, 210, 212,  ...,  95,  95,  94]],

         [[ 73,  63,  70,  ...,  95,  95,  95],
          [ 64,  57,  62,  ...,  95,  95,  95],
          [ 77,  60,  75,  ...,  95,  95,  95],
          ...,
          [210, 212, 198,  ...,  88,  78,  86],
          [211, 211, 204,  ...,  81,  78,  80],
          [210, 209, 211,  ...,  93,  94,  92]],

         [[ 77,  65,  73,  ...,  95,  95,  95],
          [ 68,  63,  66,  ...,  95,  95,  95],
          [ 78,  61,  78,  ...,  95,  95,  95],
          ...,
          [203, 201, 182,  ...,  86,  76,  83],
          [208, 206, 196,  ...,  80,  75,  77],
          [203, 205, 209,  ...,  91,  90,  88]]]], dtype=torch.uint8), tensor([[0.00000e+00, 1.60000e+01, 4.76596e-01, 3.57515e-01, 3.57970e-02, 2.86920e-02],
        [0.00000e+00, 0.00000e+00, 4.33369e-01, 3.31210e-01, 3.31870e-02, 5.10650e-02],
        [0.00000e+00, 0.00000e+00, 5.45033e-01, 3.18690e-01, 2.84220e-02, 3.56037e-02],
        [0.00000e+00, 1.30000e+01, 2.30744e-01, 3.08712e-01, 5.38440e-02, 3.70543e-02],
        [0.00000e+00, 1.30000e+01, 3.47440e-01, 3.39916e-01, 6.29530e-02, 3.61806e-02],
        [0.00000e+00, 0.00000e+00, 5.66721e-01, 3.14540e-01, 1.43590e-02, 1.76298e-02],
        [0.00000e+00, 2.00000e+01, 9.61122e-01, 4.03924e-01, 7.77564e-02, 7.39392e-02],
        [0.00000e+00, 2.00000e+01, 8.71885e-01, 4.12452e-01, 9.30309e-02, 5.39799e-02],
        [0.00000e+00, 2.00000e+01, 7.82502e-01, 4.17735e-01, 5.44530e-02, 4.07930e-02],
        [0.00000e+00, 2.00000e+01, 6.61096e-01, 4.12101e-01, 8.62030e-02, 5.21853e-02],
        [0.00000e+00, 1.50000e+01, 8.74655e-02, 7.96599e-01, 1.74931e-01, 4.06803e-01],
        [0.00000e+00, 0.00000e+00, 8.45760e-01, 8.54039e-01, 7.06250e-02, 2.38797e-01],
        [0.00000e+00, 3.80000e+01, 8.65151e-01, 7.29906e-01, 5.95310e-02, 2.56559e-02],
        [0.00000e+00, 3.20000e+01, 8.14604e-01, 6.79664e-01, 1.02190e-02, 1.12343e-02]]), ['/workspace/pytorch_benchmark/benchmark/torchbenchmark/models/yolov3/../../data/.data/coco128/images/train2017/000000000109.jpg'], [None])

need to changeimg_size = x.shape[-2:] to img_size = x[0].shape[-2:]. And another error came up:

Traceback (most recent call last):
  File "run.py", line 230, in <module>
    m = Model(device=args.device, test=args.test, jit=(args.mode == args.mode), batch_size=args.bs, extra_args=extra_args)
  File "/workspace/pytorch_benchmark/benchmark/torchbenchmark/util/model.py", line 14, in __call__
    obj.__post__init__()
  File "/workspace/pytorch_benchmark/benchmark/torchbenchmark/util/model.py", line 103, in __post__init__
    apply_opt_args(self, self.opt_args)
  File "/workspace/pytorch_benchmark/benchmark/torchbenchmark/util/extra_args.py", line 133, in apply_opt_args
    model.set_module(enable_jit(model=module, example_inputs=exmaple_inputs, test=model.test))
  File "/workspace/pytorch_benchmark/benchmark/torchbenchmark/util/backends/jit.py", line 8, in enable_jit
    model = torch.jit.script(model, example_inputs=[example_inputs, ])
  File "/opt/conda/lib/python3.8/site-packages/torch/jit/_script.py", line 1275, in script
    obj(*examples)
  File "/opt/conda/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1186, in _call_impl
    return forward_call(*input, **kwargs)
  File "/workspace/pytorch_benchmark/benchmark/torchbenchmark/models/yolov3/yolo_models.py", line 244, in forward
    torch_utils.scale_img(x.flip(3), s[0], same_shape=False),  # flip-lr and scale
AttributeError: 'tuple' object has no attribute 'flip'

Is there some bug about the data structure here?

Dominic-ZZ avatar Aug 01 '22 07:08 Dominic-ZZ

Sorry but I can't reproduce your result:

$ python run.py yolov3 -d cpu -t train --bs 1
Running train method from yolov3 on cpu in eager mode with input batch size 1.
CPU Total Wall Time: 1059.863 milliseconds

Looks like the difference is you are trying to torchscript the model (File "/workspace/pytorch_benchmark/benchmark/torchbenchmark/util/backends/jit.py", line 8, in enable_jit), while yolov3 is known to not supporting torchscript.

Taking a closer look, the line 230 of run.py is empty (https://github.com/pytorch/benchmark/blob/main/run.py#L230), not m = Model(device=args.device, test=args.test, jit=(args.mode == args.mode), batch_size=args.bs, extra_args=extra_args), which always sets jit=True. Are you working on the latest main branch?

xuzhao9 avatar Aug 09 '22 00:08 xuzhao9

Closed as can't reproduce.

xuzhao9 avatar Aug 19 '22 00:08 xuzhao9