Gripping with knees is a pretty common fault that a lot of people have. The problem is that if you pinch in with your knees your knee acts like a fulcrum and your lower leg swings back and forth instead of being your foundation that keeps you strong and balanced. First make sure that your saddle fits well and doesn't encourage your leg to do it. A lot of it is going to be repetition repetition repetition of the correct way to do it! Unfortunately gripping with my knee is a problem I have and it's not an easy one to fix! A few pointers that I think has helped me..
1) Lots and lots of 2 point and make the conscious effort to have an even distribution of pressure between your thigh, knee, and calf. If anything, think about gripping with the middle of your calf and the middle of your thigh.
2) I don't know about you but riding stirrupless actually made it worse for me. I know this won't be the case for everyone, but this is the ONE instance that stirrups was a better idea!
3) Push your heels down. Yes, in most cases I wouldn't say PUSH your heels down because it forces your ankle to brace instead of being a shock absorber and it can cause you to shoot your lower leg forward, but interestingly doing lots of exercises like gymnastics where I consciously told myself to PUSH my leg down made me let go with my knee and made me use my whole leg.
4) make sure you aren't in a chair seat. That can make knee gripping worse. Again, lots of 2 point. ;)
So these are all pointers that aren't necessarily helpful for other bad habits, but has helped my knee gripping quite a bit. Good luck!