torch.fx.proxy.TraceError: Proxy object cannot be iterated

Dear All.

Is there have a function or method to deal : Proxy object cannot be iterated ?

import torch
import torch.nn as nn

class M(nn.Module):
    def __init__(self):
        super().__init__()

    def forward(self, x):
        """
        x.size() -> (batch, seq, feature)
        """
        _, seq, _ = x.size()
        for i in range(seq):
            ...

m = M()
import torch.fx 
tracer = torch.fx.Tracer().trace(m)

and then,

type(range(seq)) -> Proxy

So, the seq type is Proxy, is there have a function change Proxy into int ?

Or not to trace the seq variable, which not to change it’s type.

Thx All.

1 Like