Riding the wave of an artificial intelligence explosion in the tech world, Nvidia saw its stock rally to record heights Wednesday, topping a $3 trillion valuation and surpassing Apple as the second most valuable company.

Nvidia, which now narrowly trails Microsoft ($3.15 trillion) for the highest market capitalization, has been leading the way in an AI-inspired rally on Wall Street.

On Wednesday, Nvidia shares climbed 5.2% to reach $1,224.40 at the closing bell, valuing the company at $3.012 trillion. Apple's market capitalization closed at $3.003 trillion.

Nvidia announced last month a 10-for-1 stock split, set to take place Friday. Many investors are viewing the stock split as an opportunity to buy into the emerging technology stored on Nvidia's microchips.

"Nvidia is making money on AI right now, and companies like Apple and Meta are spending on AI," said Jake Dollarhide, chief executive officer at Longbow Asset Management, told Reuters.

The leapfrog ahead of Apple reflects a shift at the top in Silicon Valley, where Apple has reigned for years. Investors are closely watching the stock price before Friday's split.