What if I only want to trace one of layer’s weight during training?

The optimizer change the parameters inplace. So if you just hold on to param, it will be updated as training goes 
Your original code fails as attribute names cannot start with numbers. So foo.1 is invalid in python and raises a Syntax error.