I would probably try to use a Variable instead of a Parameter, that should make things ignore it completely, which seems to be what you want.
Or you could do layer.f.requires_grad = False after initializing the optimizer. Then the gradient will not be computed, the optimizer to see 0 all the time. (But the optimizer would still do “computation”.)
Best regards
Thomas