Hi,
The main reason is that pytorch needs to create the weights at the initialization of the layer (and thus know the input size).
This is to make sure that calls like model.cuda() or your_opt = optim.SGD(model.parameters(), ...) works as expected even before your model has seen a single sample.
Note that changing this is under discussion (but tricky to make sure it works fine with the other constructs in pytorch) and you can find the details in this issue: https://github.com/pytorch/pytorch/issues/23352 5