layer4 is an nn.Sequential module, which doesn’t have the reset_parameters method, so your conditions won’t be met.
You could iterate all modules of layer4 and check for this attribute:
def reset_weights(m):
    for name, layer in m.named_children():
        if name=='layer4':
            print(name)
            for n, l in layer.named_modules():
                print(n)
                if hasattr(l, 'reset_parameters'):
                    print(f'Reset trainable parameters of layer = {l}')
                    l.reset_parameters()


model = models.resnet18()
model.apply(reset_weights)