‘len’ is not supported in symbolic tracing by default

yang_wang: <p>Hello, I now have a requirement to parse the yolov3 network constructed by mmdetion. In mmdetion, the yolov3 network is divided into backbone, neck, bbox, and 3 parts. But when I use torch.fx to parse this model, I have the following problem. I tried to use the torch.fx.wrap(‘len’) tutorial given by the official website to solve this problem. It is very strange that the example on the official website runs successfully, but it does not take effect in the code I wrote. How to solve the problem that ‘len’ cannot be resolved?<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/8/1/81d9afab0879c30c90a93c8a42f1b1292d4b1a93.png" data-download-href="https://discuss.pytorch.org/uploads/default/81d9afab0879c30c90a93c8a42f1b1292d4b1a93" title="1"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/8/1/81d9afab0879c30c90a93c8a42f1b1292d4b1a93_2_690x436.png" alt="1" data-base62-sha1="iwHZ1n5f2iyQv9ZoM4zkHsA764X" width="690" height="436" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/8/1/81d9afab0879c30c90a93c8a42f1b1292d4b1a93_2_690x436.png, https://discuss.pytorch.org/uploads/default/optimized/3X/8/1/81d9afab0879c30c90a93c8a42f1b1292d4b1a93_2_1035x654.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/8/1/81d9afab0879c30c90a93c8a42f1b1292d4b1a93.png 2x" data-dominant-color="472020"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">1</span><span class="informations">1317×834 119 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div><br>
code:<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/f/a/fae90964265ce399f87b5a0dd64bc37ca09bbcd1.png" data-download-href="https://discuss.pytorch.org/uploads/default/fae90964265ce399f87b5a0dd64bc37ca09bbcd1" title="2"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/f/a/fae90964265ce399f87b5a0dd64bc37ca09bbcd1_2_690x337.png" alt="2" data-base62-sha1="zNEE4MDRUzYzeKnhlb9LKTLVi9j" width="690" height="337" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/f/a/fae90964265ce399f87b5a0dd64bc37ca09bbcd1_2_690x337.png, https://discuss.pytorch.org/uploads/default/optimized/3X/f/a/fae90964265ce399f87b5a0dd64bc37ca09bbcd1_2_1035x505.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/f/a/fae90964265ce399f87b5a0dd64bc37ca09bbcd1.png 2x" data-dominant-color="252726"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">2</span><span class="informations">1107×542 57.2 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>

ptrblck: <p>I’m not exactly sure what “module scope” means here, but would defining it at the “global” score help (i.e. move if right after the <code>imports</code> and rerun your code.</p>

yang_wang: <p>I tried putting <code>torch.fx.wrap('len')</code> anywhere, including the <code>global</code>, but it didn’t solve the problem</p>

yang_wang: <p>i have sovled this problem，please delete it.</p>

zxl: <p>I have encountered the same problem. How did you solve it？</p>

Seul-Ki_Yeom: <p><a class="mention" href="/u/yang_wang">@yang_wang</a> I have a same issue. Could you please let me know how to figure out?</p>

rick1: <p>Hello bro, I also meet a trace problem can you share your solution?</p>

Changjiang_Gou: <p>I solved the problem in a similar situation. Just add <code>torch.fx.wrap('len')</code> at the top of the same file where you use len(variable).</p>