China will succeed in building a powerful technology industry that will rival the United States, even if President Trump starts a trade war to stop it. The reason can be found on the fourth floor of a nondescript factory in a city once famous for cheap manufacturing and prostitution.

This factory floor, in the southern Chinese city of Dongguan, once employed what one employee called a “magnificent sea of people.” Rising labor costs and a new generation with little interest in toiling in factories forced a new tack. Now the sea of people is being replaced by a whirring array of boxy machines, each performing work it used to take 15 people 26 steps to finish.

The factory suggests that Beijing's vision of Made in China 2025 — the ambitious state-driven plan to retool China’s industries to compete in areas like automation, microchips and self-driving cars — is not being pushed just by the Communist Party’s top leaders. Instead, the drive is also coming from the bottom up: from the businesses and cities across China that know they must modernize or perish.

The Trump administration is not wrong to confront Beijing over Made in China 2025. China’s top-down approach gives its companies unfair advantages and could continue to roil global trade relations long after Mr. Trump retires to Mar-a-Lago.

But Made in China 2025 is also being propelled by businesses like Dongguan Mentech Optical & Magnetic Company, the owner of the factory, which are worried about labor costs and their own futures. It comes from local governments looking for ways to stay relevant. It comes from a growing network of private-sector entrepreneurs, academics and local politicians who are increasingly working together to overhaul China’s factories and its future. Other cities — Suzhou, Wenzhou, Xuzhou and the industrial areas around Shanghai are just a few examples — have also drummed up their own automation plans.

The modernization may not happen in 2025. In fact, it may be long after that. But China will get there, mostly because it has to.

“If Made in China 2025 were a car, the engine has started and it’s definitely moving along,” said Zhang Guojun, director of Guangdong Intelligent Robotics Institute in Dongguan, one of several city-supported local research centers helping the factories upgrade. The city was automating well before Made in China 2025 came out in 2015, he said, “but the policy provided us a clear direction.”

A city of eight million people in the Pearl River Delta, Dongguan long relied on making and exporting shoes, toys and electronic parts to the United States and Europe. In many ways, it looks like the factory-dominated China of popular imagination, with whole parts of the city pervaded by rows of rectangular factory buildings, one after another.

Then the 2008 financial crisis hit. Orders dried up. Dongguan became known as China’s capital of prostitution until a government crackdown cleaned it up.

Read more from The New York Times:

As trade fight looms, China turns censors on its own policies

U.S. and China expand trade war as Beijing matches Trump’s tariffs

ZTE’s near-collapse may be China’s Sputnik moment

Beyond the financial crisis, China’s very prosperity threatened Dongguan’s future. The average worker’s income rose fourfold over the past decade. Fewer young people wanted to work on dull and stressful assembly lines, preferring service jobs — like waiting tables and delivering e-commerce packages — that let them interact with people or move around. Some factories moved to lower-cost countries or shut down for good.

Dongguan’s companies and government had to do something. They committed to modernizing.

Before Made in China 2025 became policy, Dongguan kicked off a “replacing humans with machines initiative” and funded it with about $30 million a year. It later channeled more money into other automation initiatives. Companies that could prove they had a worthy research project or were willing to invest in industrial robots, software or advanced machinery could win subsidies and tax breaks. The government picked up 10 percent to 20 percent of the tab. Smartphone, furniture, machinery and even cake companies won support, official documents show.

Mentech, the telecom equipment supplier, once had hundreds of workers winding, packaging and testing magnetic wires that were thinner than hair, all by hand. Even today, the company is desperate for workers. On the side of one factory building it lists the on-the-job benefits it offers: monthly wages with overtime of up to about $1,100, air-conditioned dormitories, free Wi-Fi and even a birthday present.

“Love your employees,” reads a banner, “and they will love you back 100 times.”

But labor costs and a lack of hands were holding it back. During the Lunar New Year holiday, when most of China shuts down and goes home, some 500 Mentech executives, engineers and administrative staff had to work three-hour shifts after their normal workday to keep the factory running, said Zhang Xiaodong, a research and development manager.

Mentech asked Mr. Zhang and others to figure out how to automate the factory. They spent two years working late into the night. Machines needed tweaking. Components needed to be redesigned so that machines could make them. Several projects failed.

“Not every problem has a solution,” Mr. Zhang said. “We know that smart manufacturing is the future. But getting there isn’t easy.”

Today, a factory floor that once needed over 300 workers now needs 100. More than half of the factory has been automated. The workers clustered around the machines will probably be replaced by machines themselves in a year or two.

To help, the Dongguan government provided $1.5 million in subsidies. It is also luring start-ups and helping scientists open research centers to provide more know-how.

One start-up aiding Mentech is Dongguan Precision Intelligent Technology, which will provide a good chunk of the machinery the company needs to automate fully. Because the equipment will be Chinese-made, it will be cheaper than purchases of automation systems from Japan or the United States.

“The biggest trend in manufacturing is that automation is irreversible,” said Forest Tian, a former venture capitalist who founded Precision Intelligent Technology. “There will be huge demand for these machines.”

The Dongguan government has taken other steps to ensure these centers of innovation help local manufacturers. For example, it formed about 30 research institutes in partnership with major Chinese universities. Once the initial money was given, Dongguan officials told the institutes they had to figure out how to make money on their own.

The institutes teamed up with companies like Guangdong Janus Intelligent Group Corporation, a once-dowdy cellphone parts maker facing the familiar problem of high labor costs. Experts in the field became recurring visitors to its factory.

“We call it 18 Buddhas coming to Dongguan,” said Huang He, the head of Janus’s smart-factory business, alluding to the followers of the original Buddha.

At a Janus factory, rows of automated machine tools work with robotic arms and green conveyor belts in a space nearly the size of a football field. The robotic arms feed metal blocks to the machines, which then punch, grind and wash them. The housings for phones and tablets come out.

The factory requires 16 workers on a shift, instead of 103 before it was automated. The robotic arms are made in China.

No doubt many Chinese companies will fail in their effort to upgrade. Made in China 2025’s other goals, such as building up world-class microchip industries or self-driving cars, remain out of sight for now.

Yet when it comes to manufacturing, Dongguan suggests Made in China 2025 will succeed partly because the effort is bigger than Beijing. Chinese companies and local government officials are determined to climb the value chain so they will not fall into obsolescence. The best Washington can do is to make sure its policies help American companies stay ahead of the game.