Am I better off paying my master’s in cash or taking out a loan and investing the cash?

Financial picture: I live with parents and after tax, take-home pay is $6K/mo. I max out my 401K and Roth IRA, have a 6-month emergency fund built up and currently stash away about 18% into investments.

I’m also currently in a master’s program. One semester down, three more left. I saved up a bunch of money in the last two years with the intention of paying off my master’s in cash. But I’m wondering if I’m better off taking loans out on the remaining balance, paying a smaller amount monthly, investing the excess cash now and dialing up my investments.

I’d be borrowing $30K in unsubsidized federal loans at an interest rate of 6.54% to put toward the remaining balance.

I know nobody has a crystal ball but I’m curious how folks here would approach the situation and what aspects to consider before making a final decision. Thanks in advance.

**Edit**: specified loan type (unsubsidized)