You can upgrade directly from 4.12.4 to 5.1.
It is possible to push upgrade of modules to your agents in Settings->Upgrade Agents.
If your environment contains agents currently running a version less than 4.12.0, you must first manually upgrade your agents to the latest version.
I hope this helped.
In addition, you will need a new license key that you can get from your portal. Please make sure you have a license key before you upgrade.