I bumped to that issue while trying to find memory leakage in a custom architecture. To get the number of the children that are not parents to any other module, thus the real number of modules inside the provided one, I am using this recursive function:
def dim(module):
    total_num = 0
    f = False
    for child in module.children():
        f = True
        total_num += dim(child)
    if not f:
        return 1
    return total_num

I hope it helps