You could either use the nn.Flatten 5 module directly or use the functional API via torch.flatten or tensor.view in the forward method.
The approach depends on your use case (e.g. nn.Flatten should be used in an nn.Sequential container) and your coding style.