Why is subclass of Model.__init__ never executed?

I am running the fastai TabularModel and placed some print statements in the init() method. The print statements in the forward method starting dumping out text, but the ones in init never showed up. I tried setting some self.xxx variables, and even put in a assert statement, none fired while forward kept on getting called.

There is something strange about how this works. Can someone throw some lights into this?

Could you post a code snippet to reproduce this issue?

class TabularModel(Module):
    "Basic model for tabular data."
    def __init__(self, emb_szs:ListSizes, n_cont:int, out_sz:int, layers:Collection[int], ps:Collection[float]=None,
                 emb_drop:float=0., y_range:OptRange=None, use_bn:bool=True, bn_final:bool=False):
        super().__init__()
              
        self.emb_szs = emb_szs
        b = 0
        assert b != 0, "force an assertion to see who passed data_collate"  
        ps = ifnone(ps, [0]*len(layers))
        ps = listify(ps, layers)
        print('emb_szs={}'.format(emb_szs))
        for ni,nf in emb_szs:
            print('ni, nf={},{}'.format(ni, nf))
        self.embeds = nn.ModuleList([embedding(ni, nf) for ni,nf in emb_szs])
        print('self.embeds={}'.format(self.embeds))
        self.emb_drop = nn.Dropout(emb_drop)
        self.bn_cont = nn.BatchNorm1d(n_cont)
        n_emb = sum(e.embedding_dim for e in self.embeds)
        print('n_emb={}'.format(n_emb))
        self.n_emb,self.n_cont,self.y_range = n_emb,n_cont,y_range
        sizes = self.get_sizes(layers, out_sz)
        actns = [nn.ReLU(inplace=True) for _ in range(len(sizes)-2)] + [None]
        layers = []
        for i,(n_in,n_out,dp,act) in enumerate(zip(sizes[:-1],sizes[1:],[0.]+ps,actns)):
            layers += bn_drop_lin(n_in, n_out, bn=use_bn and i!=0, p=dp, actn=act)
        if bn_final: layers.append(nn.BatchNorm1d(sizes[-1]))
        self.layers = nn.Sequential(*layers)

All the assert and print statements have no effect, yet the init must have executed, otherwise the self. variables would not have been set, and the forward() call would have bombed out.

Could you post a link to the implementation?
I’m currently not sure, if Module refers to nn.Module or a custom implementation in FastAI.

Of course removing all undefined variables, works fine:

class TabularModel(nn.Module):
    "Basic model for tabular data."
    def __init__(self):
        super().__init__()
        b = 0
        assert b != 0, 'test'      

To debug this issue, we would need an executable code snippet.