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.

ValueError: __len__() should return >= 0

See original GitHub issue

when use torch2trt convert the torch.eq, error occurs. mm = torch.eq(mm, 0.) mm is tensor and mm.shape = [3136, 1, 3, 3]

File “/media/cfs/torch2trt-master/examples/inpainting/model.py”, line 329, in forward mm = torch.eq(mm, nn) File “./torch2trt/torch2trt.py”, line 285, in wrapper converter"converter" File “./torch2trt/converters/compare.py”, line 26, in convert_gt return convert_elementwise(ctx, trt.ElementWiseOperation.EQUAL) File “./torch2trt/converters/compare.py”, line 9, in convert_elementwise input_a_trt, input_b_trt = broadcast_trt_tensors(ctx.network, [input_a_trt, input_b_trt], len(output.shape) - 1) File “./torch2trt/torch2trt.py”, line 170, in broadcast_trt_tensors if len(t.shape) < broadcast_ndim: ValueError: len() should return >= 0

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:13 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
pepinucommented, Mar 22, 2021

@jaybdub @whcjb

I found out the problem is the trt not being able to process slice() operator in the same fashion torch does.

The network I was trying to port crashed on torch.add() operation between two tensors, while converting minimal torch.add op worked like a charm.

My model was cutting spatial dimensions using python slice() operation, instead of torch.narrow recommended for tensors.

To check this is the culprit I wrote and tested 2 versions of a network that narrows dims and adds them together: Screenshot 2021-03-22 at 13 23 23 Screenshot 2021-03-22 at 13 23 27 Screenshot 2021-03-22 at 13 23 32 Screenshot 2021-03-22 at 13 23 50

I think the screen is self-explanatory, here’s a gist to reproduce this.

I’m not sure where to go from here, there should be some type check for slice within the lib, hope it helps.

Best Regards

EDIT:

I looked at the last screen and see that tensors are not matching between TRT and normal model, which is weird? I was sure that they were while writing this…

0reactions
Tegalacommented, Jul 25, 2022

I meet same problem too, wish for some solution @jaybdub 0.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

[BUG] ValueError: __len__() should return >= 0 #496 - GitHub
When I run this code I get error "ValueError: len() should return >= 0" Now my question is what should be length of...
Read more >
fastai: ValueError: __len__() should return >= 0 - Stack Overflow
Looks like your data is in 1 .txt file, and LanguageModelData.from_text_files() expects to deal with folders containing many files.
Read more >
Avoid raising OverflowError in len() when __len__() returns ...
msg289779 ‑ (view) Author: Serhiy Storchaka (serhiy.storchaka) * Date: 2017‑03‑17 19:52 msg289782 ‑ (view) Author: Barry A. Warsaw (barry) * Date: 2017‑03‑17 20:28 msg290109 ‑...
Read more >
ERROR: __len__() should return >= 0 on liveFeed
Hello everyone. I need help I am working on implementing a new data feed / live broker. I have taken Oanda as a...
Read more >
Python's sum(): The Pythonic Way to Sum Values
Python's built-in function sum() is an efficient and Pythonic way to sum a list of ... def sum_numbers(numbers): ... if len(numbers) == 0:...
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