You should use nn.ModuleList and add the linear layers to it instead of using a Python list, as the latter won’t properly register the modules (as seen in the print statement).
Besides that, your code should be working fine.