Most simple networks are just a straight chain: input goes through layer 1, that output goes through layer 2, and so on, until the final layer produces the network's output. Writing this chain out by hand every time, x = layer1.forward(x); x = layer2.forward(x); x = layer3.forward(x), works, but it means the network's ARCHITECTURE (how many layers, in what order) is hardcoded into a specific block of code rather than being data you can construct, inspect, and reuse. Sequential turns "a chain of layers" into an actual object: something you build once from a list of layers, that then knows how to run the full chain itself.
[05-module-base-class]'s Module already solved half the problem: how to collect parameters from nested layers automatically. Sequential is where that machinery gets put to real use for the first time: it IS a Module, and each layer it holds is registered as one of ITS child modules, so sequential_model.parameters() transparently returns every layer's parameters, without Sequential itself needing to know anything about what kind of layers it's holding.
Implement Sequential, a subclass of Module (already provided, reused from [05-module-base-class] via load_solution). __init__(self, *layers) accepts any number of layer objects (each with its own .forward(x) method), stores them in order, and registers each one as a child module using the inherited register_module method (so self.parameters(), inherited from Module, picks them all up automatically). forward(self, x) runs x through every layer in order, feeding each layer's output as the next layer's input, and returns the final result.
__init__.self.register_module), using a distinct name for each (its index, as a string, works well).forward must work for any number of layers, including zero (in which case it should return x unchanged) and one.Store self.layers = list(layers) in __init__, then loop over enumerate(self.layers) and call self.register_module(str(i), layer) for each one, str(i) gives each layer a distinct registration name.
forward is a simple loop: for layer in self.layers: x = layer.forward(x), then return x. Each iteration REPLACES x with that layer's output, which is exactly what feeds it into the next layer.
Click "Run Tests" to test your implementation