def test_save_hyperparameters_ignore_under_composition(base_class):
    """Test that in a composed system, hyperparameter saving skips ignored fields from nested modules."""

    class ChildModule(base_class):
        def __init__(self, dropout, activation, init_method):
            super().__init__()
            self.save_hyperparameters(ignore=["dropout", "activation"])

    class ParentModule(base_class):
        def __init__(self, batch_size, optimizer):
            super().__init__()
            self.child = ChildModule(dropout=0.1, activation="relu", init_method="xavier")

    class PipelineWrapper:  # not a Lightning subclass on purpose
        def __init__(self, run_id="abc123", seed=42):
            self.parent_module = ParentModule(batch_size=64, optimizer="adam")

    pipeline = PipelineWrapper()
    assert pipeline.parent_module.child.hparams == {"init_method": "xavier", "batch_size": 64, "optimizer": "adam"}
Test that in a composed system, hyperparameter saving skips ignored fields from nested modules.
tests/tests_pytorch/models/test_hparams.py