If you have a student visa you can only stay in the UK if your visa is still valid on the date of your graduation ceremony.
It‘s not possible to extend your student visa for the purpose of attending your graduation ceremony. If your student visa expires you’ll have to return home and apply for a visitor visa; applications for this must be made online here.
If you have transferred into another immigration category you may remain in the UK and attend your graduation ceremony as long as your visa is valid. For more information about what you need to do before returning for graduation, please visit our Graduation pages.