Fire crews from five stations across Sandwell and Birmingham were called to reports of the blaze in the flat and roof space above Lazio Pizza, on Rood End Road, Oldbury, around 6.30am on Friday.
The fire had caused the first floor of the building, which is in a terraced row, to collapse into the ground floor.
Twenty-five fire fighters from Oldbury, Smethwick, West Bromwich, Handsworth and Highgate fire stations worked to get the fire under control, with four fire engines and an aerial platform pressed into action.
The fire was taken under control 20 minutes after the first crew arrived at 6.34am, while two people were escorted from a neighbouring property and two more advised to leave a separate building as a precaution.
They were allowed to return to their homes later as firefighters worked to dampen down, with crews still at the scene hours later.
Investigators at the scene said the fire is believed to be related to the growing of cannabis.
A spokesman for West Midlands Fire Service said: "At 6.32am on Friday 14 January we responded to a severe fire above a row of shops on Rood End Road, Oldbury.
"Four fire engines and an aerial platform attended, with around 25 personnel.
"Our first crew arrived within four minutes of being mobilised and the fire was under control 20 minutes later.
"This was a severe fire in a flat and roof space above a pizza shop, in a terraced row.
"The first floor collapsed into the ground floor.
"The fire is believed to be related to the growing of cannabis.
"Two people were escorted by firefighters from a neighbouring property, and two more advised to leave a separate building as a precaution. They were later allowed to return to their homes."
A spokeswoman for West Midlands Police said: "We were alerted to a cannabis factory being discovered following a fire in Vernon Road, Oldbury, this morning (14 January).
"It was found during a fire in a flat above a takeaway shop. The blaze is believed to have been caused through the cultivation of cannabis and no-one was injured.
"Further enquiries will be carried out as Rood End Road at the junction of Shirley Road remains closed. Anyone with information can contact us via Live Chat on our website, or by calling 101, and quote log 595 of 14/1/2022."