GPS has an arrow on it. That arrow must point forward. You probably already did that. Also, if you are using I2C aux mag (separate cable, usually 2 wire that goes to FlexiPort) then you must set Aux Mag Orientation (in Attitude->Magnetometer) to either 0,180,0 or 180,0,180 (they are the same rotation). This will get it close. It is OK if it is a few units off. Rotating fast will make it show farther off than it is. Rotate slowly and stop to check at a few rotations.
If you are using an OP GPSv9 or a DJI GPS, leave the Aux Mag Orientation at 0,0,0
This article has everything about setup, test, debug of aux mag.
https://librepilot.atlassian.net/wiki/spaces/LPDOC/pages/18382863/Aux+Mag+Setup+and+CalibrationAlso be aware that the Flight Controller must be oriented correctly too. The arrow must point forward, or if not, Attitude -> Settings -> RotateVirtual.. must be set correctly. First get it flying without the GPS/mag to prove that the FC orientation, etc. is configured correctly.