Attribute error occurs in a function about normalizing flow

I wanted to use torch.compile to acclerate my training then I got an attribute error. Here’s the code and the traceback:

model = torch.compile(model)

def fun(model, data):
    fparam = model.flow.sample(data.shape[0])

opt_fun = torch.compile(fun)

where model.flow is a distribution

Traceback (most recent call last):
  File "/root/miniconda3/envs/myconda/lib/python3.10/site-packages/torch/_dynamo/", line 324, in _compile
    out_code = transform_code_object(code, transform)
  File "/root/miniconda3/envs/myconda/lib/python3.10/site-packages/torch/_dynamo/", line 445, in transform_code_object
    transformations(instructions, code_options)
  File "/root/miniconda3/envs/myconda/lib/python3.10/site-packages/torch/_dynamo/", line 311, in transform
  File "/root/miniconda3/envs/myconda/lib/python3.10/site-packages/torch/_dynamo/", line 1726, in run
  File "/root/miniconda3/envs/myconda/lib/python3.10/site-packages/torch/_dynamo/", line 576, in run
    and self.step()
  File "/root/miniconda3/envs/myconda/lib/python3.10/site-packages/torch/_dynamo/", line 540, in step
    getattr(self, inst.opname)(inst)
  File "/root/miniconda3/envs/myconda/lib/python3.10/site-packages/torch/_dynamo/", line 1030, in LOAD_ATTR
    result = BuiltinVariable(getattr).call_function(
  File "/root/miniconda3/envs/myconda/lib/python3.10/site-packages/torch/_dynamo/variables/", line 566, in call_function
    result = handler(tx, *args, **kwargs)
  File "/root/miniconda3/envs/myconda/lib/python3.10/site-packages/torch/_dynamo/variables/", line 930, in call_getattr
    return obj.var_getattr(tx, name).add_options(options)
  File "/root/miniconda3/envs/myconda/lib/python3.10/site-packages/torch/_dynamo/variables/", line 124, in var_getattr
    subobj = inspect.getattr_static(base, name)
  File "/root/miniconda3/envs/myconda/lib/python3.10/", line 1769, in getattr_static
    raise AttributeError(attr)
AttributeError: flow

from user code:
   File "/mnt/VADA/", line 152, in fun
     fparam = model.flow.sample(data.shape[0])

You can suppress this exception and fall back to eager by setting:
    torch._dynamo.config.suppress_errors = True

Wasn’t I misunderstand what is a compiled model? I used to think torch.compile gives a faster model that is almost the same as before. But now it seems that model has attribute flow doen’t mean the compiled model also has it.