Please see if this helps:
#Variables
level = 0
strParent = ‘’
lstModules = list( model.named_modules())[1:]
#Initial Print Statements
print(’{0:<20}’.format(‘Module Name’), ‘|’, ‘{0:<10}’.format(‘Parent’) , ‘|’,  ‘{0:<10}’.format(‘Module’, ’ ‘*10))
print(’{0:<20}’.format(’===========’), ‘|’,  ‘{0:<10}’.format(’======’), ‘|’,  ‘{0:<10}’.format(’======’))
#Loop through the module
for i in range(len(lstModules)):
if level==0:
strParent=‘None’
module_name = lstModules[i][0]
parent_name = strParent
module      = str(lstModules[i][1])
print(’{0:<20}’.format(module_name), ‘|’ ,  ‘{0:<10}’.format(parent_name), ‘|’,  ‘{0:<100}’.format(module))
strParent = lstModules[i][0]
level=1